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
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–4why, one step back1import isPlainObject from 'is-plain-obj';2import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';34// Deep merge specific options like `env`. Shallow merge the other ones.Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84
line 5why, one step back5// Use spread (which only copies own properties) to safely read from boundOptions without prototype pollution100% test coverage (#1018)ehmickybefore adoption9f65b86
line 6why, one step back6export const mergeOptions = (boundOptions, options) => {Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84
line 7why, one step back7 const safeBoundOptions = {__proto__: null, ...boundOptions};Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
lines 8–11why, one step back8 const mergedOptions = Object.fromEntries(Object.entries(options).map(([optionName, optionValue]) => [9 optionName,10 mergeOption(optionName, safeBoundOptions[optionName], optionValue),11 ]));Harden some thingsSindre Sorhusbefore adoption4a0a121
line 12why, one step back12 return {__proto__: null, ...safeBoundOptions, ...mergedOptions};100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 13–14why, one step back13};14TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15const mergeOption = (optionName, boundOptionValue, optionValue) => DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue) ? {...boundOptionValue, ...optionValue} : optionValue;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 16–17why, one step back1617const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);