-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
322fa95
commit bbc3121
Showing
7 changed files
with
61 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '12' | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
'use strict'; | ||
const lenient = require('./lenient'); | ||
const lenientFunction = require('./lenient'); | ||
|
||
const yn = (input, options) => { | ||
input = String(input).trim(); | ||
const yn = (value, { | ||
lenient = false, | ||
default: default_ = null | ||
} = {}) => { | ||
value = String(value).trim(); | ||
|
||
options = Object.assign({ | ||
lenient: false, | ||
default: null | ||
}, options); | ||
|
||
if (options.default !== null && typeof options.default !== 'boolean') { | ||
throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof options.default}\``); | ||
if (default_ !== null && typeof default_ !== 'boolean') { | ||
throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof default_}\``); | ||
} | ||
|
||
if (/^(?:y|yes|true|1)$/i.test(input)) { | ||
if (/^(?:y|yes|true|1)$/i.test(value)) { | ||
return true; | ||
} | ||
|
||
if (/^(?:n|no|false|0)$/i.test(input)) { | ||
if (/^(?:n|no|false|0)$/i.test(value)) { | ||
return false; | ||
} | ||
|
||
if (options.lenient === true) { | ||
return lenient(input, options); | ||
if (lenient === true) { | ||
return lenientFunction(value, default_); | ||
} | ||
|
||
return options.default; | ||
return default_; | ||
}; | ||
|
||
module.exports = yn; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = yn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters