Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 20, 2018
1 parent c716329 commit 41930d4
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: false
language: node_js
node_js:
- '10'
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const os = require('os');
const macosRelease = require('macos-release');
const winRelease = require('windows-release');

module.exports = function (platform, release) {
module.exports = (platform, release) => {
if (!platform && release) {
throw new Error('You can\'t specify a `release` without specifying `platform`');
}
Expand All @@ -16,6 +16,7 @@ module.exports = function (platform, release) {
if (!release && os.platform() === 'darwin') {
release = os.release();
}

const prefix = release ? (Number(release.split('.')[0]) > 15 ? 'macOS' : 'OS X') : 'macOS';
id = release ? macosRelease(release).name : '';
return prefix + (id ? ' ' + id : '');
Expand All @@ -25,6 +26,7 @@ module.exports = function (platform, release) {
if (!release && os.platform() === 'linux') {
release = os.release();
}

id = release ? release.replace(/^(\d+\.\d+).*/, '$1') : '';
return 'Linux' + (id ? ' ' + id : '');
}
Expand All @@ -33,6 +35,7 @@ module.exports = function (platform, release) {
if (!release && os.platform() === 'win32') {
release = os.release();
}

id = release ? winRelease(release) : '';
return 'Windows' + (id ? ' ' + id : '');
}
Expand Down
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

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:
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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
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.
81 changes: 40 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
{
"name": "os-name",
"version": "2.0.1",
"description": "Get the name of the current operating system. Example: macOS Sierra",
"license": "MIT",
"repository": "sindresorhus/os-name",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"os",
"operating",
"system",
"platform",
"name",
"title",
"release",
"version",
"macos",
"osx",
"windows",
"linux"
],
"dependencies": {
"macos-release": "^2.0.0",
"windows-release": "^3.1.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "os-name",
"version": "2.0.1",
"description": "Get the name of the current operating system. Example: macOS Sierra",
"license": "MIT",
"repository": "sindresorhus/os-name",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"os",
"operating",
"system",
"platform",
"name",
"title",
"release",
"version",
"macos",
"windows",
"linux"
],
"dependencies": {
"macos-release": "^2.0.0",
"windows-release": "^3.1.0"
},
"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.23.0"
}
}
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Useful for analytics and debugging.
## Install

```
$ npm install --save os-name
$ npm install os-name
```


Expand All @@ -19,7 +19,7 @@ $ npm install --save os-name
const os = require('os');
const osName = require('os-name');

// on a macOS Sierra system
// On a macOS Sierra system

osName();
//=> 'macOS Sierra'
Expand All @@ -42,11 +42,11 @@ osName('win32', '6.3.9600');

### osName([platform, release])

By default the name of the current operating system is returned.
By default, the name of the current operating system is returned.

You can optionally supply a custom [`os.platform()`](http://nodejs.org/api/os.html#os_os_platform) and [`os.release()`](http://nodejs.org/api/os.html#os_os_release).
You can optionally supply a custom [`os.platform()`](https://nodejs.org/api/os.html#os_os_platform) and [`os.release()`](https://nodejs.org/api/os.html#os_os_release).

Check out [getos](https://github.com/wblankenship/getos) if you need the Linux distribution name.
Check out [`getos`](https://github.com/wblankenship/getos) if you need the Linux distribution name.


## Contributing
Expand Down
38 changes: 19 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import os from 'os';
import test from 'ava';
import m from '.';
import osName from '.';

test(t => {
t.true(m().length > 0);
t.is(m('darwin', '18.0.0'), 'macOS Mojave');
t.is(m('darwin', '17.0.0'), 'macOS High Sierra');
t.is(m('darwin', '16.0.0'), 'macOS Sierra');
t.is(m('darwin', '14.0.0'), 'OS X Yosemite');
t.is(m('darwin', '99.0.0'), 'macOS');
t.is(m('linux', '3.13.0-24-generic'), 'Linux 3.13');
t.is(m('win32', '5.1.2600'), 'Windows XP');
t.is(m('win32', '4.90'), 'Windows ME');
t.is(m('win32', '6.2'), 'Windows 8');
t.is(m('win32', '10.0'), 'Windows 10');
test('main', t => {
t.true(osName().length > 0);
t.is(osName('darwin', '18.0.0'), 'macOS Mojave');
t.is(osName('darwin', '17.0.0'), 'macOS High Sierra');
t.is(osName('darwin', '16.0.0'), 'macOS Sierra');
t.is(osName('darwin', '14.0.0'), 'OS X Yosemite');
t.is(osName('darwin', '99.0.0'), 'macOS');
t.is(osName('linux', '3.13.0-24-generic'), 'Linux 3.13');
t.is(osName('win32', '5.1.2600'), 'Windows XP');
t.is(osName('win32', '4.90'), 'Windows ME');
t.is(osName('win32', '6.2'), 'Windows 8');
t.is(osName('win32', '10.0'), 'Windows 10');

os.platform = () => 'darwin';
t.is(m('win32'), 'Windows');
t.is(m('linux'), 'Linux');
t.is(osName('win32'), 'Windows');
t.is(osName('linux'), 'Linux');

os.platform = () => 'linux';
t.is(m('darwin'), 'macOS');
t.is(m('win32'), 'Windows');
t.is(osName('darwin'), 'macOS');
t.is(osName('win32'), 'Windows');

os.platform = () => 'win32';
t.is(m('darwin'), 'macOS');
t.is(m('linux'), 'Linux');
t.is(osName('darwin'), 'macOS');
t.is(osName('linux'), 'Linux');
});

0 comments on commit 41930d4

Please sign in to comment.