or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/npm-is-windows

Returns true if the platform is windows, works with node.js, commonjs, browser, AMD, electron, etc.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/is-windows@1.0.x

To install, run

npx @tessl/cli install tessl/npm-is-windows@1.0.0

0

# is-windows

1

2

Returns 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.

3

4

## Package Information

5

6

- **Package Name**: is-windows

7

- **Package Type**: npm

8

- **Language**: JavaScript

9

- **Installation**: `npm install is-windows`

10

11

## Core Imports

12

13

```javascript

14

var isWindows = require('is-windows');

15

```

16

17

For ES6 imports (if transpiled):

18

19

```javascript

20

import isWindows from 'is-windows';

21

```

22

23

## Basic Usage

24

25

```javascript

26

var isWindows = require('is-windows');

27

28

console.log(isWindows());

29

// => true on Windows platforms, false otherwise

30

31

// Works in all environments

32

if (isWindows()) {

33

// Windows-specific code

34

console.log('Running on Windows');

35

} else {

36

// Non-Windows code

37

console.log('Running on non-Windows platform');

38

}

39

```

40

41

## Capabilities

42

43

### Platform Detection

44

45

Detects if the current platform is Windows by checking both standard Windows detection and Windows-like environments.

46

47

```javascript { .api }

48

/**

49

* Detects if the current platform is Windows

50

* @returns {boolean} true if running on Windows platform, false otherwise

51

*/

52

function isWindows() {}

53

```

54

55

**Detection Logic:**

56

- Returns `true` if `process.platform === 'win32'` (native Windows)

57

- Returns `true` if `process.env.OSTYPE` matches `msys` or `cygwin` (Windows-like environments)

58

- Returns `false` for all other platforms

59

60

**Supported Environments:**

61

- **Node.js**: CommonJS module export

62

- **Browser**: Available as `window.isWindows()`

63

- **Web Workers**: Available as `self.isWindows()`

64

- **AMD**: Compatible with RequireJS and other AMD loaders

65

- **Electron**: Works in both main and renderer processes

66

- **Universal**: Falls back to global scope attachment

67

68

## Environment-Specific Usage

69

70

### Node.js / CommonJS

71

72

```javascript

73

const isWindows = require('is-windows');

74

75

if (isWindows()) {

76

require('child_process').spawn('cmd', ['/c', 'dir']);

77

} else {

78

require('child_process').spawn('ls', ['-la']);

79

}

80

```

81

82

### Browser

83

84

```html

85

<script src="node_modules/is-windows/index.js"></script>

86

<script>

87

if (window.isWindows()) {

88

console.log('Browser is running on Windows');

89

}

90

</script>

91

```

92

93

### AMD (RequireJS)

94

95

```javascript

96

define(['is-windows'], function(isWindows) {

97

return function() {

98

if (isWindows()) {

99

// Windows-specific logic

100

}

101

};

102

});

103

```

104

105

### ES6 Modules (with transpilation)

106

107

```javascript

108

import isWindows from 'is-windows';

109

110

const platform = isWindows() ? 'windows' : 'other';

111

console.log(`Running on: ${platform}`);

112

```

113

114

## Platform Coverage

115

116

The function detects the following Windows environments:

117

118

- **Windows 10/11**: Standard `win32` platform detection

119

- **Windows Server**: All versions detected via `win32`

120

- **Git Bash**: Detected via `OSTYPE=msys`

121

- **MSYS2**: Detected via `OSTYPE=msys`

122

- **Cygwin**: Detected via `OSTYPE=cygwin`

123

- **WSL**: Not detected (reports as Linux, which is technically correct)

124

125

## Zero Dependencies

126

127

This 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.