Skip to content
Myr

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 file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–9why, one step back
1// 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.
2// Like destructuring them, `null` throws.3export const copyOptions = (options = {}) => {4 if (options === null) {5 throw new TypeError('The options must be an object, not `null`.');6 }78 return {__proto__: null, ...options};9};

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 10–15why, one step back
10
11export const checkBooleanOption = (value, optionName) => {12 if (value !== undefined && typeof value !== 'boolean') {13 throw new TypeError(`The \`${optionName}\` option must use a boolean.`);14 }15};