Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

defaults-shallow

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defaults-shallow

Extend an object with the properties of other objects, but only if they don't already exist.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

defaults-shallow NPM version

Extend an object with the properties of other objects, but only if they don't already exist.

How is this different than extend or assign?

  • [extend][] and assign: "last one wins" - properties are updated or overwritten by new values.
  • defaults: "first one wins" - only new properties are filled in.

Install

Install with npm

$ npm i defaults-shallow --save

Usage

var defaults = require('defaults-shallow');

defaults({a: 'b'}, {c: 'd'});
//=> {a: 'b', c: 'd'}

defaults({a: 'b'}, {a: 'c'});
//=> {a: 'b'}

To shallow clone you can use an empty object as the first argument:

var options = defaults({}, {a: 'b'}, {c: 'd'}, {a: 'f'});
//=> {a: 'b', c: 'd'}
  • defaults-deep: Like extend but recursively copies only the missing properties/values to the target object. | homepage
  • extend-shallow: Extend an object with the properties of additional objects. node.js/javascript util. | homepage
  • merge-deep: Recursively merge values in a javascript object. | homepage
  • mixin-deep: Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.

This file was generated by verb-cli on October 04, 2015.

Keywords

assign

FAQs

Package last updated on 04 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts