@nodeutils/defaults-deep
Like lodash's _.defaultsDeep, but with array preservation
Last updated 8 years ago by drewdotpro .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @nodeutils/defaults-deep 
SYNC missed versions from official npm registry.

defaults-deep

An individual component of the [nodeutils package]

Similar to lodash's defaultsDeep, but without mutating the source object, and no merging of arrays.

Installation

Install the package via npm:

$ npm install @nodeutils/defaults-deep --save

Usage

Arguments

  1. [sources] (...Object): The source objects. Provide 2 or more, in descending order of importance

Returns

(Object): Returns the merged objects

Example

var defaultsDeep = require('@nodeutils/defaults-deep');

var objectA = { bar: { biz: { net: 'txi', qox: 'fuc' } }, qux: ['baz'] };
var objectB = { bar: { biz: { net: 'qux'} }, qux: ['biz', 'ban'] };
var objectC = { bar: { biz: { net: 'qux', lee: 'sox' } }, qux: ['biz', 'rep'], foo: 'bar' };

defaultsDeep(objectA, objectB, objectC);
// => { bar: { biz: { net: 'qux', qox: 'fuc', lee: 'sox' } }, qux: ['baz'], foo: 'bar' }

###How Incredibly simple:

"use strict";
const _ = require("lodash");
module.exports = function () {
    let output = {};
    _.toArray(arguments).reverse().forEach(item=> {
        _.mergeWith(output, item, (objectValue, sourceValue) => {
            return _.isArray(sourceValue) ? sourceValue : undefined;
        });
    });
    return output;
};

Current Tags

  • 1.1.0                                ...           latest (8 years ago)

5 Versions

  • 1.1.0                                ...           8 years ago
  • 1.0.3                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (6)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE