Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

defaulty

fabioricali43.9kMIT2.1.0

Copies missing properties to the target object.

copy, clone, object, deep, defaults, config, extend, set, array, values, missing, properties

readme

defaulty

Copies deep missing properties to the target object.

Installation

Node.js

npm install defaulty --save

Example

const defaulty = require('defaulty');

const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
let targetObj = {a: 4, b: 5, d: {a: 1}};

defaulty(targetObj, defaultObj);

console.log(targetObj); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};

Exclude default properties

const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}, x: 1, y: 2};
let targetObj = {a: 4, b: 5, d: {a: 1}};

defaulty(targetObj, defaultObj, ['x', 'y']);

console.log(targetObj); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};

Copy target object

const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
const targetObj = {a: 4, b: 5, d: {a: 1}};

const newTargetObject = defaulty.copy(targetObj, defaultObj);

console.log(newTargetObject); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
console.log(targetObj); //=> {a: 4, b: 5, d: {a: 1}};

Changelog

You can view the changelog here

License

Defaulty is open-sourced software licensed under the MIT license

Author

Fabio Ricali

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[2.1.0] - 2018-01-07

  • Now copy method copies deep objects

[2.0.0] - 2017-12-09

  • Now undefined value will be overwrite by the default

[1.2.2] - 2017-11-04

  • Added support to ES5

[1.2.1] - 2017-08-26

  • Added new API copy, now you can set default properties into new target object

[1.1.0] - 2017-08-20

  • Added exclude param, now you can exclude any default parameters

[1.0.3] - 2017-08-20

  • Removed unnecessary files for deployment on NPM

[1.0.2] - 2017-08-11

  • Added repository url

[1.0.1] - 2017-08-11

  • First release