Socket
Socket
Sign inDemoInstall

just-extend

Package Overview
Dependencies
0
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-extend

extend an object


Version published
Maintainers
1
Weekly downloads
4,385,319
decreased by-15.01%

Weekly downloads

Package description

What is just-extend?

The just-extend npm package is a utility library for deep or shallow copying and extending of objects. It allows users to merge properties from source objects into a target object, with the option to perform deep (recursive) merges.

What are just-extend's main functionalities?

Shallow extend

This feature allows the user to merge properties from one or more source objects into a target object. If the same property exists in both objects, the value from the last object will be used.

{"var extend = require('just-extend');
var obj1 = {a: 3, b: 4};
var obj2 = {b: 5, c: 6};
var result = extend(obj1, obj2);
// result is {a: 3, b: 5, c: 6}"}

Deep extend

This feature allows the user to perform a deep merge, where nested objects are also merged together. This is useful when you want to combine objects with nested structures.

{"var extend = require('just-extend');
var obj1 = {a: {b: 3}};
var obj2 = {a: {c: 4}};
var result = extend(true, obj1, obj2);
// result is {a: {b: 3, c: 4}}"}

Extend with customizer function

This feature allows the user to provide a customizer function that determines how values are merged. The customizer function can be used to specify custom merging behavior for specific properties or types of values.

{"var extend = require('just-extend');
var customizer = function(objValue, srcValue) {
  if (Array.isArray(objValue)) {
    return objValue.concat(srcValue);
  }
};
var obj1 = {a: [1, 2], b: 3};
var obj2 = {a: [3, 4], b: 4};
var result = extend(customizer, obj1, obj2);
// result is {a: [1, 2, 3, 4], b: 4}"}

Other packages similar to just-extend

Readme

Source

just-extend

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-extend
yarn add just-extend

Extend an object

import extend from 'just-extend';

var obj = {a: 3, b: 5};
extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 4, b: 5, c: 8}

var obj = {a: 3, b: 5};
extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
obj; // {a: 3, b: 5}

var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}

var arr = [1, 2, 3];
var obj = {a: 3, b: 5};
extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
arr.push(4);
obj; // {a: 3, b: 5, c: [1, 2, 3]}

extend({a: 4, b: 5}); // {a: 4, b: 5}
extend({a: 4, b: 5}, 3); {a: 4, b: 5}
extend({a: 4, b: 5}, true); {a: 4, b: 5}
extend('hello', {a: 4, b: 5}); // throws
extend(3, {a: 4, b: 5}); // throws

Keywords

FAQs

Last updated on 17 Dec 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc