3.0.0 • Published 2 years ago

defaults v3.0.0

Weekly downloads
6,920,127
License
MIT
Repository
github
Last release
2 years ago

defaults

Easily handle defaults for your options

Install

npm install defaults

Usage

import defaults from 'defaults';

const calculate = options => {
	options = defaults(options, {
		timeout: {
			before: 100,
			after: 100
		}
	});

	console.log(options);
	//=> {timeout: {before: 200, after: 100}}

	// …
}

// …

calculate({timeout: {before: 200}});

API

defaults(options, defaultOptions?)

Deeply merges the given options with the specified defaults and returns a new object.

The given parameters are deep-cloned and never mutated.

options

Type: object

The user-provided options.

If the value is not a plain object, a new plain object will be used instead.

defaultOptions

Type: object | undefined

The default options to use when a value is not provided in the options object.

FAQ

Why use this over object-spread?

  • Does not overwrite options if they are not defined in the options object
  • Supports deep merging of objects
  • Provides protection against prototype pollution attacks
wcwidtheasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagetext-cleaner2cad-cli@cashremit/cr-streamline-iconshoserver-frameworkreact-native-template-rfbaseairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxfdeneme323112@texttree/demo-bsa-reference-rcl@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjameskoa-slow-downreact-native-covid-sdkgql_din_modauto-extractmongoose-timestamps-unixpanqibaoreact-native-printer-brothersrn-pdf-reader-offlineexpress-block-ieexpress-enforce-httpsreact-native-shekhar-bridge-testcogoportutilsdyx-react@rpii/nightwatch-html-reportertalent-to-vite-cliwilscanner@oiti/documentoscopy-react-native@mink-opn/build-tokensquoc-testreact-native-slider-kfunblock-block-save-variables@prodam/prodam-typesimp-gulp-utilsimp-utils@ayr/lambda-proxy-utilsplginshamsi-date-nowexpand-react-bridgeluminos-ui-core@everything-registry/sub-chunk-1461iqra-calculatorjawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplecode-msi-simple_calculator123zs89cli-number-guessingkny63-atm-machinekshahmeer10_atmatm_process@uf3sindh/simple_cli_calculatorhmmmmd12-cli-number-guessinghmd12-cli-number-guessingja--simple--calculatorlapture-ui-complaptureuicode-with-zafar-number-gusseing-gamecode-with-zafar-student-managment-systemgriffin-ui-librarynadia-simple-calculatoratm-code-from-inquirer-code-with-hasnainatm-code-with-hasnainatm-code-with-hasnain-using-inquirercode-with-abbasi-riffattalha12-todo-listtdl1-to-do-listsyncbackbasessyz432cli-number-guessingsynopsis-backendsynopsis-clienttaha-atm-machinesvg2icontest-library-123test-haptik-libtest-npm-jjmessiwinx-form-winxwinston-loggerwiki2pdfword-counter-h-a-aword-counter-husainaword-counter-in-typescriptword-my-counterword_counter_hk123word_counter-by-safawordddd-counterwaleed_atmwajhi-to-do-list
2.0.2

2 years ago

3.0.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.4

3 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

12 years ago