├── .editorconfig ├── .gitattributes ├── .github ├── security.md └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── package.json ├── readme.md └── test.js /.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 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | - 20 14 | - 18 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | Get the name of a Windows version from the release number: `5.1.2600` → `XP`. 3 | 4 | @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). 5 | 6 | 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()`. 7 | 8 | @example 9 | ``` 10 | import os from 'node:os'; 11 | import windowsRelease from 'windows-release'; 12 | 13 | // On a Windows XP system 14 | 15 | windowsRelease(); 16 | //=> 'XP' 17 | 18 | os.release(); 19 | //=> '5.1.2600' 20 | 21 | windowsRelease(os.release()); 22 | //=> 'XP' 23 | 24 | windowsRelease('4.9.3000'); 25 | //=> 'ME' 26 | ``` 27 | */ 28 | export default function windowsRelease(release?: string): string; 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import os from 'node:os'; 2 | import {execaSync} from 'execa'; 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 version = /(\d+\.\d+)(?:\.(\d+))?/.exec(release || os.release()); 24 | 25 | if (release && !version) { 26 | throw new Error('`release` argument doesn\'t match `n.n`'); 27 | } 28 | 29 | let ver = version[1] || ''; 30 | const build = version[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 | // If the resulting caption contains the year 2008, 2012, 2016, 2019 or 2022, it is a server version, so return a server OS name. 37 | if ((!release || release === os.release()) && ['6.1', '6.2', '6.3', '10.0'].includes(ver)) { 38 | let stdout; 39 | try { 40 | stdout = execaSync('wmic', ['os', 'get', 'Caption']).stdout || ''; 41 | } catch { 42 | stdout = execaSync('powershell', ['(Get-CimInstance -ClassName Win32_OperatingSystem).caption']).stdout || ''; 43 | } 44 | 45 | const year = (stdout.match(/2008|2012|2016|2019|2022|2025/) || [])[0]; 46 | 47 | if (year) { 48 | return `Server ${year}`; 49 | } 50 | } 51 | 52 | // Windows 11 53 | if (ver === '10.0' && build.startsWith('2')) { 54 | ver = '10.0.2'; 55 | } 56 | 57 | return names.get(ver); 58 | } 59 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType} from 'tsd'; 2 | import windowsRelease from './index.js'; 3 | 4 | expectType(windowsRelease()); 5 | expectType(windowsRelease('5.1.2600')); 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "windows-release", 3 | "version": "6.1.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": ">=18" 21 | }, 22 | "scripts": { 23 | "test": "xo && ava && tsd" 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 | "dependencies": { 43 | "execa": "^8.0.1" 44 | }, 45 | "devDependencies": { 46 | "ava": "^5.3.1", 47 | "tsd": "^0.29.0", 48 | "xo": "^0.56.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /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 | #### release 37 | 38 | Type: `string` 39 | 40 | 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). 41 | 42 | 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()`. 43 | 44 | ## Related 45 | 46 | - [os-name](https://github.com/sindresorhus/os-name) - Get the name of the current operating system 47 | - [macos-release](https://github.com/sindresorhus/macos-release) - Get the name and version of a macOS release from the Darwin version 48 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------