You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

extendify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extendify

Deep extend with customizable behavior for Node.js

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
5.1K
3.51%
Maintainers
1
Weekly downloads
 
Created
Source

Logo

Deep extend with customizable behavior for Node.js.

"Extedify" is a lightweight wrapper over lodash's _.merge (like a deep _.extend) with customizable handling of arrays, booleans, numbers and strings.

(By default, extedify will behave exactly like lodash's _.merge.)

Installation

npm install extendify

Usage

var extendify = require('extendify');
myExtend = extendify({
    // options
});

Options

  • inPlace – Override the 'source' with the result?
    • true (default)
    • false
  • isDeep – Use deep extend?
    • true (default)
    • false
  • arrays – How to handle arrays?
    • replace (recommended)
    • concat
    • merge (default)
    • or
    • and
  • booleans – How to handle booleans?
    • replace (default)
    • concat
    • or
    • and
  • numbers – How to handle numbers?
    • replace (default)
    • concat
    • or
    • and
  • strings – How to handle strings?
    • replace (default)
    • concat
    • or
    • and

Example

Let's get an _.extend function that

  • returns a copy/clone,
  • replaces arrays,
  • supports nested objects (also known as deep extends).
_.extend = extendify({
    inPlace: false,
    isDeep: true,
    arrays : 'replace'
});

object1 = {
    a:{
        list: [1, 2]
    },
    b: 4
};

object2 = {
    a:{
        list: [3]
    }
};

var result = myExtend(object1, object2);
/*
{
    a: {
        list: [3]
    },
    b: 4
}
*/

More examples are available in the 'examples.js' file.

Contributions

Your feedback is welcome, email me at reshef.shai@gmail.com.

Keywords

extend

FAQs

Package last updated on 13 Dec 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