Skip to content

Commit 7c38da9

Browse files
committed
Require Node.js 6
1 parent f790df7 commit 7c38da9

File tree

10 files changed

+94
-110
lines changed

10 files changed

+94
-110
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
sudo: false
21
language: node_js
32
node_js:
3+
- '10'
4+
- '8'
45
- '6'
5-
- '4'

index.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
'use strict';
22
const lenient = require('./lenient');
33

4-
module.exports = (val, opts) => {
5-
val = String(val).trim();
6-
opts = Object.assign({
4+
const yn = (input, options) => {
5+
input = String(input).trim();
6+
7+
options = Object.assign({
78
lenient: false,
89
default: null
9-
}, opts);
10+
}, options);
1011

11-
if (opts.default !== null && typeof opts.default !== 'boolean') {
12-
throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof opts.default}\``);
12+
if (options.default !== null && typeof options.default !== 'boolean') {
13+
throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof options.default}\``);
1314
}
1415

15-
if (/^(?:y|yes|true|1)$/i.test(val)) {
16+
if (/^(?:y|yes|true|1)$/i.test(input)) {
1617
return true;
1718
}
1819

19-
if (/^(?:n|no|false|0)$/i.test(val)) {
20+
if (/^(?:n|no|false|0)$/i.test(input)) {
2021
return false;
2122
}
2223

23-
if (opts.lenient === true) {
24-
return lenient(val, opts);
24+
if (options.lenient === true) {
25+
return lenient(input, options);
2526
}
2627

27-
return opts.default;
28+
return options.default;
2829
};
2930

30-
module.exports.default = module.exports;
31+
module.exports = yn;
32+
module.exports.default = yn;

lenient.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ const oMatch = new Map([
5858
['l', 0.25]
5959
]);
6060

61-
function getYesMatchScore(val) {
61+
function getYesMatchScore(value) {
62+
const [y, e, s] = value;
6263
let score = 0;
63-
const y = val[0];
64-
const e = val[1];
65-
const s = val[2];
6664

6765
if (yMatch.has(y)) {
6866
score += yMatch.get(y);
@@ -79,10 +77,9 @@ function getYesMatchScore(val) {
7977
return score;
8078
}
8179

82-
function getNoMatchScore(val) {
80+
function getNoMatchScore(value) {
81+
const [n, o] = value;
8382
let score = 0;
84-
const n = val[0];
85-
const o = val[1];
8683

8784
if (nMatch.has(n)) {
8885
score += nMatch.get(n);
@@ -95,14 +92,14 @@ function getNoMatchScore(val) {
9592
return score;
9693
}
9794

98-
module.exports = (val, opts) => {
99-
if (getYesMatchScore(val) >= YES_MATCH_SCORE_THRESHOLD) {
95+
module.exports = (input, options) => {
96+
if (getYesMatchScore(input) >= YES_MATCH_SCORE_THRESHOLD) {
10097
return true;
10198
}
10299

103-
if (getNoMatchScore(val) >= NO_MATCH_SCORE_THRESHOLD) {
100+
if (getNoMatchScore(input) >= NO_MATCH_SCORE_THRESHOLD) {
104101
return false;
105102
}
106103

107-
return opts.default;
104+
return options.default;
108105
};

license

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

33
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
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:
116

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
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.

package.json

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
{
2-
"name": "yn",
3-
"version": "2.0.0",
4-
"description": "Parse yes/no like values",
5-
"license": "MIT",
6-
"repository": "sindresorhus/yn",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"contributors": [
13-
"Justin Woo <[email protected]>",
14-
"Mark Stosberg <[email protected]>"
15-
],
16-
"engines": {
17-
"node": ">=4"
18-
},
19-
"scripts": {
20-
"test": "xo && ava && tsd-check"
21-
},
22-
"files": [
23-
"index.js",
24-
"lenient.js",
25-
"index.d.ts"
26-
],
27-
"keywords": [
28-
"yn",
29-
"yes",
30-
"no",
31-
"cli",
32-
"prompt",
33-
"validate",
34-
"input",
35-
"answer",
36-
"true",
37-
"false",
38-
"parse",
39-
"lenient"
40-
],
41-
"devDependencies": {
42-
"ava": "*",
43-
"tsd-check": "*",
44-
"xo": "*"
45-
}
2+
"name": "yn",
3+
"version": "2.0.0",
4+
"description": "Parse yes/no like values",
5+
"license": "MIT",
6+
"repository": "sindresorhus/yn",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=6"
14+
},
15+
"scripts": {
16+
"test": "xo && ava && tsd-check"
17+
},
18+
"files": [
19+
"index.js",
20+
"lenient.js",
21+
"index.d.ts"
22+
],
23+
"keywords": [
24+
"yn",
25+
"yes",
26+
"no",
27+
"cli",
28+
"prompt",
29+
"validate",
30+
"input",
31+
"answer",
32+
"true",
33+
"false",
34+
"parse",
35+
"lenient"
36+
],
37+
"devDependencies": {
38+
"ava": "^0.25.0",
39+
"tsd-check": "^0.2.1",
40+
"xo": "^0.23.0"
41+
}
4642
}

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The following case-insensitive values are recognized:
1818
## Install
1919

2020
```
21-
$ npm install --save yn
21+
$ npm install yn
2222
```
2323

2424

@@ -61,7 +61,7 @@ Value that should be converted.
6161

6262
#### options
6363

64-
Type: `object`
64+
Type: `Object`
6565

6666
##### lenient
6767

@@ -80,4 +80,4 @@ Default value if no match was found.
8080

8181
## License
8282

83-
MIT © [Sindre Sorhus](http://sindresorhus.com)
83+
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import m from '.';
2+
import yn from '.';
33

44
const truthyCases = [
55
'y',
@@ -16,8 +16,8 @@ const truthyCases = [
1616
];
1717
test('truthy cases', t => {
1818
for (const el of truthyCases) {
19-
t.true(m(el));
20-
t.true(m(el, {lenient: true}));
19+
t.true(yn(el));
20+
t.true(yn(el, {lenient: true}));
2121
}
2222
});
2323

@@ -36,8 +36,8 @@ const falseyCases = [
3636
];
3737
test('falsey cases', t => {
3838
for (const el of falseyCases) {
39-
t.false(m(el));
40-
t.false(m(el, {lenient: true}));
39+
t.false(yn(el));
40+
t.false(yn(el, {lenient: true}));
4141
}
4242
});
4343

@@ -68,35 +68,35 @@ const nullCases = [
6868
];
6969
test('null cases', t => {
7070
for (const el of nullCases) {
71-
t.is(m(el), null);
72-
t.is(m(el, {lenient: true}), null);
71+
t.is(yn(el), null);
72+
t.is(yn(el, {lenient: true}), null);
7373
}
7474
});
7575

7676
test('lenient option - truthy value cases', t => {
77-
t.true(m('ues', {lenient: true}));
78-
t.true(m('ywa', {lenient: true}));
79-
t.true(m('tes', {lenient: true}));
80-
t.true(m('twa', {lenient: true}));
81-
t.true(m('urd', {lenient: true}));
77+
t.true(yn('ues', {lenient: true}));
78+
t.true(yn('ywa', {lenient: true}));
79+
t.true(yn('tes', {lenient: true}));
80+
t.true(yn('twa', {lenient: true}));
81+
t.true(yn('urd', {lenient: true}));
8282
});
8383

8484
test('lenient option - falsey value cases', t => {
85-
t.false(m('ni', {lenient: true}));
86-
t.false(m('bi', {lenient: true}));
87-
t.false(m('mo', {lenient: true}));
85+
t.false(yn('ni', {lenient: true}));
86+
t.false(yn('bi', {lenient: true}));
87+
t.false(yn('mo', {lenient: true}));
8888
});
8989

9090
test('default option throws error if not a boolean type', t => {
91-
t.throws(() => m('10', {default: 10}), 'Expected the `default` option to be of type `boolean`, got `number`');
91+
t.throws(() => yn('10', {default: 10}), 'Expected the `default` option to be of type `boolean`, got `number`');
9292
});
9393

9494
test('default option', t => {
95-
t.true(m('10', {default: true}));
96-
t.false(m('10', {default: false}));
95+
t.true(yn('10', {default: true}));
96+
t.false(yn('10', {default: false}));
9797
});
9898

9999
test('default option with lenient option', t => {
100-
t.true(m('10', {default: true, lenient: true}));
101-
t.false(m('10', {default: false, lenient: true}));
100+
t.true(yn('10', {default: true, lenient: true}));
101+
t.false(yn('10', {default: false, lenient: true}));
102102
});

0 commit comments

Comments
 (0)