1 | 'use strict';
|
2 | const lenientFunction = require('./lenient');
|
3 |
|
4 | const yn = (value, {
|
5 | lenient = false,
|
6 | default: default_
|
7 | } = {}) => {
|
8 | value = String(value).trim();
|
9 |
|
10 | if (default_ !== undefined && typeof default_ !== 'boolean') {
|
11 | throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof default_}\``);
|
12 | }
|
13 |
|
14 | if (/^(?:y|yes|true|1|on)$/i.test(value)) {
|
15 | return true;
|
16 | }
|
17 |
|
18 | if (/^(?:n|no|false|0|off)$/i.test(value)) {
|
19 | return false;
|
20 | }
|
21 |
|
22 | if (lenient === true) {
|
23 | return lenientFunction(value, default_);
|
24 | }
|
25 |
|
26 | return default_;
|
27 | };
|
28 |
|
29 | module.exports = yn;
|