Returns true if the platform is windows, works with node.js, commonjs, browser, AMD, electron, etc.
npx @tessl/cli install tessl/npm-is-windows@1.0.0Returns true if the platform is Windows. This is a lightweight UMD module that works across Node.js, CommonJS, browser, AMD, Electron and other JavaScript environments. It detects Windows platform including native Windows (win32), MSYS environments (Git Bash, MSYS2), and Cygwin environments.
npm install is-windowsvar isWindows = require('is-windows');For ES6 imports (if transpiled):
import isWindows from 'is-windows';var isWindows = require('is-windows');
console.log(isWindows());
// => true on Windows platforms, false otherwise
// Works in all environments
if (isWindows()) {
// Windows-specific code
console.log('Running on Windows');
} else {
// Non-Windows code
console.log('Running on non-Windows platform');
}Detects if the current platform is Windows by checking both standard Windows detection and Windows-like environments.
/**
* Detects if the current platform is Windows
* @returns {boolean} true if running on Windows platform, false otherwise
*/
function isWindows() {}Detection Logic:
true if process.platform === 'win32' (native Windows)true if process.env.OSTYPE matches msys or cygwin (Windows-like environments)false for all other platformsSupported Environments:
window.isWindows()self.isWindows()const isWindows = require('is-windows');
if (isWindows()) {
require('child_process').spawn('cmd', ['/c', 'dir']);
} else {
require('child_process').spawn('ls', ['-la']);
}<script src="node_modules/is-windows/index.js"></script>
<script>
if (window.isWindows()) {
console.log('Browser is running on Windows');
}
</script>define(['is-windows'], function(isWindows) {
return function() {
if (isWindows()) {
// Windows-specific logic
}
};
});import isWindows from 'is-windows';
const platform = isWindows() ? 'windows' : 'other';
console.log(`Running on: ${platform}`);The function detects the following Windows environments:
win32 platform detectionwin32OSTYPE=msysOSTYPE=msysOSTYPE=cygwinThis package has no dependencies and adds minimal overhead to your project. The entire module is self-contained in a single file with UMD (Universal Module Definition) wrapper that automatically detects and adapts to the available module system (CommonJS, AMD, or global scope), ensuring maximum compatibility across all JavaScript environments.