├── .npmrc ├── .gitattributes ├── .gitignore ├── .github ├── security.md └── workflows │ └── main.yml ├── .editorconfig ├── package.json ├── index.d.ts ├── license ├── readme.md ├── index.js └── test.js /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 24 14 | - 20 15 | steps: 16 | - uses: actions/checkout@v5 17 | - uses: actions/setup-node@v5 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "windows-release", 3 | "version": "7.0.0", 4 | "description": "Get the name of a Windows version from the release number: `5.1.2600` → `XP`", 5 | "license": "MIT", 6 | "repository": "sindresorhus/windows-release", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": { 15 | "types": "./index.d.ts", 16 | "default": "./index.js" 17 | }, 18 | "sideEffects": false, 19 | "engines": { 20 | "node": ">=20" 21 | }, 22 | "scripts": { 23 | "test": "xo && ava" 24 | }, 25 | "files": [ 26 | "index.js", 27 | "index.d.ts" 28 | ], 29 | "keywords": [ 30 | "os", 31 | "win", 32 | "win32", 33 | "windows", 34 | "operating", 35 | "system", 36 | "platform", 37 | "name", 38 | "title", 39 | "release", 40 | "version" 41 | ], 42 | "devDependencies": { 43 | "ava": "^6.4.1", 44 | "xo": "^1.2.2" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | Get the name of a Windows version from the release number: `5.1.2600` → `XP`. 3 | 4 | Returns the Windows version name, or `undefined` if the version is not recognized or does not exist. 5 | 6 | @param release - By default, the current OS is used, but you can supply a custom release number, which is the output of [`os.release()`](https://nodejs.org/api/os.html#os_os_release). 7 | 8 | Note: Most Windows Server versions cannot be detected based on the release number alone. There is runtime detection in place to work around this, but it will only be used if no argument is supplied, or the supplied argument matches `os.release()`. 9 | 10 | @example 11 | ``` 12 | import os from 'node:os'; 13 | import windowsRelease from 'windows-release'; 14 | 15 | // On a Windows XP system 16 | 17 | windowsRelease(); 18 | //=> 'XP' 19 | 20 | os.release(); 21 | //=> '5.1.2600' 22 | 23 | windowsRelease(os.release()); 24 | //=> 'XP' 25 | 26 | windowsRelease('4.9.3000'); 27 | //=> 'ME' 28 | ``` 29 | */ 30 | export default function windowsRelease(release?: string): string | undefined; 31 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # windows-release 2 | 3 | > Get the name of a Windows version from the release number: `5.1.2600` → `XP` 4 | 5 | ## Install 6 | 7 | ```sh 8 | npm install windows-release 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import os from 'node:os'; 15 | import windowsRelease from 'windows-release'; 16 | 17 | // On a Windows XP system 18 | 19 | windowsRelease(); 20 | //=> 'XP' 21 | 22 | os.release(); 23 | //=> '5.1.2600' 24 | 25 | windowsRelease(os.release()); 26 | //=> 'XP' 27 | 28 | windowsRelease('4.9.3000'); 29 | //=> 'ME' 30 | ``` 31 | 32 | ## API 33 | 34 | ### windowsRelease(release?) 35 | 36 | Returns: `string | undefined` 37 | 38 | Returns the Windows version name, or `undefined` if the version is not recognized or does not exist. 39 | 40 | #### release 41 | 42 | Type: `string` 43 | 44 | By default, the current OS is used, but you can supply a custom release number, which is the output of [`os.release()`](https://nodejs.org/api/os.html#os_os_release). 45 | 46 | Note: Most Windows Server versions cannot be detected based on the release number alone. There is runtime detection in place to work around this, but it will only be used if no argument is supplied, or the supplied argument matches `os.release()`. 47 | 48 | ## Related 49 | 50 | - [os-name](https://github.com/sindresorhus/os-name) - Get the name of the current operating system 51 | - [macos-release](https://github.com/sindresorhus/macos-release) - Get the name and version of a macOS release from the Darwin version 52 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import os from 'node:os'; 2 | import {spawnSync} from 'node:child_process'; 3 | 4 | // Reference: https://www.gaijin.at/en/lstwinver.php 5 | // Windows 11 reference: https://docs.microsoft.com/en-us/windows/release-health/windows11-release-information 6 | const names = new Map([ 7 | ['10.0.2', '11'], // It's unclear whether future Windows 11 versions will use this version scheme: https://github.com/sindresorhus/windows-release/pull/26/files#r744945281 8 | ['10.0', '10'], 9 | ['6.3', '8.1'], 10 | ['6.2', '8'], 11 | ['6.1', '7'], 12 | ['6.0', 'Vista'], 13 | ['5.2', 'Server 2003'], 14 | ['5.1', 'XP'], 15 | ['5.0', '2000'], 16 | ['4.90', 'ME'], 17 | ['4.10', '98'], 18 | ['4.03', '95'], 19 | ['4.00', '95'], 20 | ]); 21 | 22 | export default function windowsRelease(release) { 23 | const versionMatch = /(\d+\.\d+)(?:\.(\d+))?/.exec(release || os.release()); 24 | 25 | if (release && !versionMatch) { 26 | throw new Error('`release` argument doesn\'t match `n.n`'); 27 | } 28 | 29 | let version = versionMatch[1] ?? ''; 30 | const build = versionMatch[2] ?? ''; 31 | 32 | // Server 2008, 2012, 2016, and 2019 versions are ambiguous with desktop versions and must be detected at runtime. 33 | // If `release` is omitted or we're on a Windows system, and the version number is an ambiguous version 34 | // then use `wmic` to get the OS caption: https://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx 35 | // If `wmic` is obsolete (later versions of Windows 10), use PowerShell instead. 36 | // We force English output using /locale:ms_409 for wmic and setting CurrentUICulture for PowerShell 37 | // to ensure year detection works on non-English Windows systems. 38 | // If the resulting caption contains the year 2008, 2012, 2016, 2019, 2022, or 2025, it is a server version, so return a server OS name. 39 | if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(version)) { 40 | let stdout; 41 | try { 42 | stdout = spawnSync('wmic', ['/locale:ms_409', 'os', 'get', 'Caption'], {encoding: 'utf8'}).stdout || ''; 43 | } catch { 44 | const command = '[Threading.Thread]::CurrentThread.CurrentUICulture = \'en-US\'; (Get-CimInstance -ClassName Win32_OperatingSystem).caption'; 45 | stdout = spawnSync('powershell', ['-NoProfile', '-Command', command], {encoding: 'utf8'}).stdout || ''; 46 | } 47 | 48 | const year = (stdout.match(/2008|2012|2016|2019|2022|2025/) || [])[0]; 49 | 50 | if (year) { 51 | return `Server ${year}`; 52 | } 53 | } 54 | 55 | // Windows 11 and Windows 10 build number validation for version 10.0 56 | if (version === '10.0' && build) { 57 | const buildNumber = Number.parseInt(build, 10); 58 | 59 | if (buildNumber >= 22_000 && buildNumber <= 30_000) { 60 | // Windows 11: build 22000 to 30000 (reasonable upper bound for future versions) 61 | version = '10.0.2'; 62 | } else if (buildNumber >= 10_240 && buildNumber <= 19_045) { 63 | // Windows 10: build 10240 to 19045 - keep ver as '10.0' 64 | } else { 65 | // Invalid build number - return undefined 66 | return undefined; 67 | } 68 | } 69 | 70 | return names.get(version); 71 | } 72 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import windowsRelease from './index.js'; 3 | 4 | // Test using versions strings sourced from https://www.gaijin.at/en/lstwinver.php 5 | 6 | test('Windows 95 versions are correctly matched', t => { 7 | const expected = '95'; 8 | const versions = ['4.00.950', '4.00.1111', '4.03.1212', '4.03.1214']; 9 | 10 | for (const version of versions) { 11 | t.is(windowsRelease(version), expected); 12 | } 13 | }); 14 | 15 | test('Windows 98 versions are correctly matched', t => { 16 | const expected = '98'; 17 | const versions = ['4.10.1998', '4.10.2222']; 18 | 19 | for (const version of versions) { 20 | t.is(windowsRelease(version), expected); 21 | } 22 | }); 23 | 24 | test('Windows ME versions are correctly matched', t => { 25 | const expected = 'ME'; 26 | const versions = ['4.90.2476', '4.90.3000']; 27 | 28 | for (const version of versions) { 29 | t.is(windowsRelease(version), expected); 30 | } 31 | }); 32 | 33 | test('Windows 2000 versions are correctly matched', t => { 34 | const expected = '2000'; 35 | const versions = ['5.0.2031', '5.0.2128', '5.0.2183', '5.0.2195']; 36 | 37 | for (const version of versions) { 38 | t.is(windowsRelease(version), expected); 39 | } 40 | }); 41 | 42 | test('Windows XP versions are correctly matched', t => { 43 | const expected = 'XP'; 44 | const versions = ['5.1.2505', '5.1.2600', '5.1.2600.1105', '5.1.2600.2180']; 45 | 46 | for (const version of versions) { 47 | t.is(windowsRelease(version), expected); 48 | } 49 | }); 50 | 51 | test('Windows Server 2003 versions are correctly matched', t => { 52 | const expected = 'Server 2003'; 53 | const versions = ['5.2.3541', '5.2.3590', '5.2.3660', '5.2.3718', '5.2.3763', '5.2.3790', '5.2.3790.1180', '5.2.3790.1218']; 54 | 55 | for (const version of versions) { 56 | t.is(windowsRelease(version), expected); 57 | } 58 | }); 59 | 60 | test('Windows Vista versions are correctly matched', t => { 61 | const expected = 'Vista'; 62 | const versions = [ 63 | '6.0.5270', 64 | '6.0.5308', 65 | '6.0.5342', 66 | '6.0.5365', 67 | '6.0.5381', 68 | '6.0.5384', 69 | '6.0.5456', 70 | '6.0.5472', 71 | '6.0.5536', 72 | '6.0.5600.16384', 73 | '6.0.5700', 74 | '6.0.5728', 75 | '6.0.5744.16384', 76 | '6.0.5808', 77 | '6.0.5824', 78 | '6.0.5840', 79 | '6.0.6000.16386', 80 | '6.0.6000', 81 | '6.0.6002', 82 | ]; 83 | 84 | for (const version of versions) { 85 | t.is(windowsRelease(version), expected); 86 | } 87 | }); 88 | 89 | test('Windows 7 versions are correctly matched', t => { 90 | const expected = '7'; 91 | const versions = ['6.1.7600.16385', '6.1.7600', '6.1.7601']; 92 | 93 | for (const version of versions) { 94 | t.is(windowsRelease(version), expected); 95 | } 96 | }); 97 | 98 | test('Windows 8 versions are correctly matched', t => { 99 | const expected = '8'; 100 | const versions = ['6.2.9200', '6.2.10211']; 101 | 102 | for (const version of versions) { 103 | t.is(windowsRelease(version), expected); 104 | } 105 | }); 106 | 107 | test('Windows 8.1 versions are correctly matched', t => { 108 | const expected = '8.1'; 109 | const versions = ['6.3.9200', '6.3.9600']; 110 | 111 | for (const version of versions) { 112 | t.is(windowsRelease(version), expected); 113 | } 114 | }); 115 | 116 | test('Windows 10 versions are correctly matched', t => { 117 | const expected = '10'; 118 | const versions = ['10.0.10240', '10.0.10586', '10.0.14393']; 119 | 120 | for (const version of versions) { 121 | t.is(windowsRelease(version), expected); 122 | } 123 | }); 124 | 125 | test('Windows 11 versions are correctly matched', t => { 126 | const expected = '11'; 127 | const versions = ['10.0.22000', '10.0.26100']; 128 | 129 | for (const version of versions) { 130 | t.is(windowsRelease(version), expected); 131 | } 132 | }); 133 | 134 | test('returns undefined for non-existent Windows versions', t => { 135 | // Non-existent Windows 10 build numbers (too high) 136 | t.is(windowsRelease('10.0.90000'), undefined); 137 | t.is(windowsRelease('10.0.50000'), undefined); 138 | 139 | // Non-existent Windows 11 build numbers (too low) 140 | t.is(windowsRelease('10.0.21999'), undefined); 141 | t.is(windowsRelease('10.0.20000'), undefined); 142 | 143 | // Gap between Windows 10 and 11 144 | t.is(windowsRelease('10.0.21000'), undefined); 145 | }); 146 | --------------------------------------------------------------------------------