options.js
This file
Path
lib/utils/options.js
15 lines · 629 bytes · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
12345678910111213141516// The options of methods like `subprocess.pipe()`, `subprocess.readable()` or `sendMessage()` are kept on a null-prototype object, otherwise a polluted `Object.prototype` would inject option values.// Like destructuring them, `null` throws.export const copyOptions = (options = {}) => { if (options === null) { throw new TypeError('The options must be an object, not `null`.'); }
return {__proto__: null, ...options};};
export const checkBooleanOption = (value, optionName) => { if (value !== undefined && typeof value !== 'boolean') { throw new TypeError(`The \`${optionName}\` option must use a boolean.`); }};