bind.js
This file
Path
lib/methods/bind.js
17 lines · 950 bytes · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
123456789101112131415161718import isPlainObject from 'is-plain-obj';import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';
// Deep merge specific options like `env`. Shallow merge the other ones.// Use spread (which only copies own properties) to safely read from boundOptions without prototype pollutionexport const mergeOptions = (boundOptions, options) => { const safeBoundOptions = {__proto__: null, ...boundOptions}; const mergedOptions = Object.fromEntries(Object.entries(options).map(([optionName, optionValue]) => [ optionName, mergeOption(optionName, safeBoundOptions[optionName], optionValue), ])); return {__proto__: null, ...safeBoundOptions, ...mergedOptions};};
const mergeOption = (optionName, boundOptionValue, optionValue) => DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue) ? {...boundOptionValue, ...optionValue} : optionValue;
const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);