
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
object-lib
Advanced tools
$ npm install --save-dev object-lib
For more extensive examples, please refer to the tests.
Align the ordering of one object recursively to a reference object.
Example:
import { align } from 'object-lib';
const obj = { k1: 1, k2: 2 };
const ref = { k2: null, k1: null };
align(obj, ref);
// obj => { k2: 1, k1: 2 }
Deep clone object.
Fields targeted by passed needles are created as a reference and not cloned.
Fields targeted by excluded needles are removed entirely from the result.
Needles are declared using the object-scan syntax.
Example:
import { clone } from 'object-lib';
const data = { a: {}, b: {}, c: {} };
const cloned = clone(data, ['b', '!c']);
console.log(cloned);
// => { a: {}, b: {} }
console.log(cloned.a !== data.a);
// => true
console.log(cloned.b === data.b);
// => true
Check if subtree
is contained in tree
recursively.
Different types are never considered contained.
Arrays are contained iff they are the same length and every element is contained in the corresponding element.
Objects are contained if the keys are a subset, and the respective values are contained.
All other types are contained if they match exactly (===
).
Example:
import { contains } from 'object-lib';
contains({ a: [1, 2], b: 'c' }, { a: [1, 2] });
// => true
contains({ a: [1, 2], b: 'c' }, { a: [1] });
// => false
Deals with parsing invalid json outputs that are commonly generated by llms
Allows merging of objects. The logic defines paths that map to a field, or a function, to merge by.
If a function is passed, it is invoked with the value, and the result is used as the merge identifier.
The paths are defined using object-scan syntax.
Example:
import { Merge } from 'object-lib';
Merge()(
{ children: [{ id: 1 }, { id: 2 }] },
{ children: [{ id: 2 }, { id: 3 }] }
);
// => { children: [ { id: 1 }, { id: 2 }, { id: 2 }, { id: 3 } ] }
Merge({ '**[*]': 'id' })(
{ children: [{ id: 1 }, { id: 2 }] },
{ children: [{ id: 2 }, { id: 3 }] }
);
// => { children: [ { id: 1 }, { id: 2 }, { id: 3 } ] }
Creates a "wrapper" proxy object that errors when a (nested) property is accessed that does not exist. Normally this would just return "undefined".
Takes input "template" obj. This is expected to be a (deeply nested) object. Rendering works very similar to mustache templates, some features are not supported yet.
For details see tests.
Returns all unique variables in template
Renders variables into deep copy of obj
FAQs
Various object utility functions
The npm package object-lib receives a total of 13,145 weekly downloads. As such, object-lib popularity was classified as popular.
We found that object-lib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.