528 B
528 B
title, tags, unlisted
| title | tags | unlisted |
|---|---|---|
| yesNo | string,regexp,intermediate | true |
Returns true if the string is y/yes or false if the string is n/no.
- Use
RegExp.prototype.test()to check if the string evaluates toy/yesorn/no. - Omit the second argument,
defto set the default answer asno.
const yesNo = (val, def = false) =>
/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
yesNo('Y'); // true
yesNo('yes'); // true
yesNo('No'); // false
yesNo('Foo', true); // true