Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-lib

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-lib - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0

lib/core/clone.js

14

lib/core/align.js

@@ -5,2 +5,4 @@ "use strict";

const last = require('../util/last');
const align = (target, ref) => {

@@ -23,6 +25,6 @@ const keysTarget = Object.keys(target);

}) => {
const last = context[context.length - 1];
const ref = last(context);
if (last instanceof Object) {
context.push(property === undefined ? last : last[property]);
if (ref instanceof Object) {
context.push(property === undefined ? ref : ref[property]);
return false;

@@ -38,6 +40,6 @@ }

}) => {
const last = context.pop();
const ref = context.pop();
if (last instanceof Object && value instanceof Object) {
align(last, value);
if (ref instanceof Object && value instanceof Object) {
align(ref, value);
}

@@ -44,0 +46,0 @@ }

@@ -5,2 +5,4 @@ "use strict";

const last = require('../util/last');
const scanner = objectScan(['**'], {

@@ -19,5 +21,5 @@ rtn: 'context',

} = context;
const last = stack[stack.length - 1];
const ref = last(stack);
if (isMatch && !(property in last)) {
if (isMatch && !(property in ref)) {
context.result = false;

@@ -27,3 +29,3 @@ return true;

const current = isMatch ? last[property] : last;
const current = isMatch ? ref[property] : ref;

@@ -30,0 +32,0 @@ if (isLeaf) {

@@ -7,12 +7,6 @@ "use strict";

const last = arr => arr[arr.length - 1];
const last = require('../util/last');
const mkChild = ref => {
if (!(ref instanceof Object)) {
return ref;
}
const mkChild = require('../util/mk-child');
return Array.isArray(ref) ? [] : {};
};
const populate = (obj, key, fn) => {

@@ -49,6 +43,6 @@ if (!(key in obj)) {

} = context;
const current = last(stack);
const ref = last(stack);
if (!isMatch) {
if (incompatible(current, value)) {
if (incompatible(ref, value)) {
stack[0] = mkChild(value);

@@ -60,3 +54,3 @@ }

if (!(current instanceof Object)) {
if (!(ref instanceof Object)) {
stack.push(null);

@@ -66,8 +60,8 @@ return true;

if (!Array.isArray(current)) {
if (!(property in current) || incompatible(current[property], value)) {
current[property] = mkChild(value);
if (!Array.isArray(ref)) {
if (!(property in ref) || incompatible(ref[property], value)) {
ref[property] = mkChild(value);
}
stack.push(current[property]);
stack.push(ref[property]);
return false;

@@ -80,3 +74,3 @@ }

if (groupBy === null) {
current.push(value);
ref.push(value);
stack.push(null);

@@ -91,3 +85,3 @@ return true;

if (populate(groups[groupId], groupEntryId, () => mkChild(value))) {
current.push(groups[groupId][groupEntryId]);
ref.push(groups[groupId][groupEntryId]);
}

@@ -94,0 +88,0 @@

@@ -5,2 +5,4 @@ "use strict";

const clone = require('./core/clone');
const contains = require('./core/contains');

@@ -12,4 +14,5 @@

align,
clone,
contains,
Merge
};
{
"name": "object-lib",
"version": "2.0.4",
"version": "2.1.0",
"main": "lib/index.js",

@@ -29,2 +29,3 @@ "repository": {

"lodash.clonedeep": "4.5.0",
"lodash.samplesize": "4.2.0",
"node-tdd": "2.19.1",

@@ -31,0 +32,0 @@ "nyc": "15.1.0",

@@ -36,2 +36,28 @@ # object-lib

### clone(obj: Object[], needles: Array<String> = [])
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](https://github.com/blackflux/object-scan) syntax.
_Example:_
<!-- eslint-disable import/no-unresolved,no-console -->
```js
const { clone } = require('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
```
### contains(tree: Object, subtree: Object)

@@ -38,0 +64,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc