Skip to content
Myr

bind.js

This file

Path

lib/methods/bind.js

17 lines · 950 bytes · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take 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 back
1import 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 back
5// Use spread (which only copies own properties) to safely read from boundOptions without prototype pollution

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 6why, one step back
6export const mergeOptions = (boundOptions, options) => {

Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84

line 7why, one step back
7 const safeBoundOptions = {__proto__: null, ...boundOptions};

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

lines 8–11why, one step back
8 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 back
12 return {__proto__: null, ...safeBoundOptions, ...mergedOptions};

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 13–14why, one step back
13};
14

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15const 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 back
16
17const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);