bind.js
This file
Path
lib/methods/bind.js
23 lines · 787 bytes · JavaScript
Last changed by
Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
History of this fileTake it
Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478
lines 1–23why, 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.5export const mergeOptions = (boundOptions, options) => {6 const newOptions = Object.fromEntries(7 Object.entries(options).map(([optionName, optionValue]) => [8 optionName,9 mergeOption(optionName, boundOptions[optionName], optionValue),10 ]),11 );12 return {...boundOptions, ...newOptions};13};1415const mergeOption = (optionName, boundOptionValue, optionValue) => {16 if (DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue)) {17 return {...boundOptionValue, ...optionValue};18 }1920 return optionValue;21};2223const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);