bind.js 787 B

1234567891011121314151617181920212223
  1. import isPlainObject from 'is-plain-obj';
  2. import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';
  3. // Deep merge specific options like `env`. Shallow merge the other ones.
  4. export const mergeOptions = (boundOptions, options) => {
  5. const newOptions = Object.fromEntries(
  6. Object.entries(options).map(([optionName, optionValue]) => [
  7. optionName,
  8. mergeOption(optionName, boundOptions[optionName], optionValue),
  9. ]),
  10. );
  11. return {...boundOptions, ...newOptions};
  12. };
  13. const mergeOption = (optionName, boundOptionValue, optionValue) => {
  14. if (DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue)) {
  15. return {...boundOptionValue, ...optionValue};
  16. }
  17. return optionValue;
  18. };
  19. const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);