3.0.0 • Published 6 months ago

defaults v3.0.0

Weekly downloads
6,920,127
License
MIT
Repository
github
Last release
6 months 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_release@314oner_npm/universal-components-libraryreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplecode-msi-simple_calculator123zs89cli-number-guessingkny63-atm-machinekshahmeer10_atmatm_process@uf3sindh/simple_cli_calculatorexpress-rate-limit-jsonexpress-requests-logglyextract-stylesf9z6a3-simple-calculatorfawaterak-online-paymentfawatrak-online-paymentfaizanscommunit-simple-calculatorfb1newgame-projectfenglin-uploaderff8f8todo_listff8f8todo_list.jsffk-typescript-atm-machineffk-typescript-simple-calculatorfdsssfed-ssiexpress-tokenwarefab-guessing-gamefarazstudentmanagementexprssifilecurd888files-existfinboxio-yarnfio-cisc-show-readmefirestorage-serverfishzerofixed_form_builderflex-sdk-providerfluent.adflow.reactnativesdkfluent.adflow.reactnativesdk-alphafmslfirst-app-lyfuciflowable-bpmn-modelerfrdrk-js-semaphorefzl-number-guess-gameforce-domain
2.0.2

8 months ago

3.0.0

6 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.4

2 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

11 years ago