Socket
Socket
Sign inDemoInstall

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 3.0.1 to 4.0.0

42

lib/core/align.js

@@ -1,26 +0,23 @@

"use strict";
import objectScan from 'object-scan';
import last from '../util/last.js';
const objectScan = require('object-scan');
const last = require('../util/last');
const align = (target, ref) => {
const keysTarget = Object.keys(target);
const keysRef = Object.keys(ref);
keysTarget.map(k => [k, keysRef.indexOf(k)]).map(([k, idx]) => idx === -1 ? [k, Number.MAX_VALUE] : [k, idx]).sort((e1, e2) => e1[1] - e2[1]).forEach(([k]) => {
const value = target[k]; // eslint-disable-next-line no-param-reassign
delete target[k]; // eslint-disable-next-line no-param-reassign
target[k] = value;
});
keysTarget
.map((k) => [k, keysRef.indexOf(k)])
.map(([k, idx]) => (idx === -1 ? [k, Number.MAX_VALUE] : [k, idx]))
.sort((e1, e2) => e1[1] - e2[1])
.forEach(([k]) => {
const value = target[k];
// eslint-disable-next-line no-param-reassign
delete target[k];
// eslint-disable-next-line no-param-reassign
target[k] = value;
});
};
const scanner = objectScan(['', '**'], {
breakFn: ({
property,
context
}) => {
breakFn: ({ property, context }) => {
const ref = last(context);
if (ref instanceof Object) {

@@ -30,12 +27,7 @@ context.push(property === undefined ? ref : ref[property]);

}
context.push(null);
return true;
},
filterFn: ({
value,
context
}) => {
filterFn: ({ value, context }) => {
const ref = context.pop();
if (ref instanceof Object && value instanceof Object) {

@@ -47,4 +39,4 @@ align(ref, value);

module.exports = (tree, ref) => {
export default (tree, ref) => {
scanner(ref, [tree]);
};
};

@@ -1,10 +0,6 @@

"use strict";
import objectScan from 'object-scan';
import last from '../util/last.js';
import mkChild from '../util/mk-child.js';
const objectScan = require('object-scan');
const last = require('../util/last');
const mkChild = require('../util/mk-child');
module.exports = (obj, needles = []) => {
export default (obj, needles = []) => {
const hasDoubleStar = needles.includes('**');

@@ -15,7 +11,3 @@ const breakLength = hasDoubleStar ? 0 : 1;

breakFn: ({
isMatch,
property,
value,
context,
getMatchedBy
isMatch, property, value, context, getMatchedBy
}) => {

@@ -25,7 +17,5 @@ if (!isMatch) {

}
const ref = last(context);
const doBreak = getMatchedBy().length > breakLength;
const v = doBreak ? value : mkChild(value);
if (Array.isArray(ref)) {

@@ -38,11 +28,8 @@ ref.push(v);

}
return doBreak;
},
filterFn: ({
context
}) => {
filterFn: ({ context }) => {
context.pop();
}
})(obj, [mkChild(obj)])[0];
};
};

@@ -1,7 +0,4 @@

"use strict";
import objectScan from 'object-scan';
import last from '../util/last.js';
const objectScan = require('object-scan');
const last = require('../util/last');
const scanner = objectScan(['**'], {

@@ -11,13 +8,6 @@ rtn: 'context',

breakFn: ({
isLeaf,
isMatch,
property,
value,
context
isLeaf, isMatch, property, value, context
}) => {
const {
stack
} = context;
const { stack } = context;
const ref = last(stack);
if (isMatch && !(property in ref)) {

@@ -27,5 +17,3 @@ context.result = false;

}
const current = isMatch ? ref[property] : ref;
if (isLeaf) {

@@ -36,13 +24,14 @@ if (value !== current) {

}
} else if (value instanceof Object !== current instanceof Object || Array.isArray(value) !== Array.isArray(current) || Array.isArray(value) && value.length !== current.length) {
} else if (
value instanceof Object !== current instanceof Object
|| Array.isArray(value) !== Array.isArray(current)
|| (Array.isArray(value) && value.length !== current.length)
) {
context.result = false;
return true;
}
stack.push(current);
return false;
},
filterFn: ({
context
}) => {
filterFn: ({ context }) => {
context.stack.pop();

@@ -53,10 +42,5 @@ return context.result !== true;

module.exports = (tree, subtree) => {
const {
result
} = scanner(subtree, {
stack: [tree],
result: true
});
export default (tree, subtree) => {
const { result } = scanner(subtree, { stack: [tree], result: true });
return result;
};
};

@@ -1,11 +0,6 @@

"use strict";
import assert from 'assert';
import objectScan from 'object-scan';
import last from '../util/last.js';
import mkChild from '../util/mk-child.js';
const assert = require('assert');
const objectScan = require('object-scan');
const last = require('../util/last');
const mkChild = require('../util/mk-child');
const populate = (obj, key, fn) => {

@@ -17,27 +12,19 @@ if (!(key in obj)) {

}
return false;
};
const incompatible = (a, b) => (
!(a instanceof Object)
|| !(b instanceof Object)
|| Array.isArray(a) !== Array.isArray(b)
);
const incompatible = (a, b) => !(a instanceof Object) || !(b instanceof Object) || Array.isArray(a) !== Array.isArray(b);
export default (logic_ = {}) => {
const logic = { '**': null, ...logic_ };
module.exports = (logic_ = {}) => {
const logic = {
'**': null,
...logic_
};
const scanner = objectScan(Object.keys(logic), {
reverse: false,
breakFn: ({
isMatch,
property,
value,
matchedBy,
context
isMatch, property, value, matchedBy, context
}) => {
const {
stack,
groups,
path
} = context;
const { stack, groups, path } = context;
const ref = last(stack);

@@ -49,6 +36,4 @@

}
return false;
}
if (!(ref instanceof Object)) {

@@ -58,3 +43,2 @@ stack.push(null);

}
if (!Array.isArray(ref)) {

@@ -64,3 +48,2 @@ if (!(property in ref) || incompatible(ref[property], value)) {

}
stack.push(ref[property]);

@@ -71,3 +54,5 @@ return false;

const bestNeedle = last(matchedBy);
const groupBy = typeof logic[bestNeedle] === 'function' ? logic[bestNeedle](value) : logic[bestNeedle];
const groupBy = typeof logic[bestNeedle] === 'function'
? logic[bestNeedle](value)
: logic[bestNeedle];

@@ -83,7 +68,5 @@ if (groupBy === null) {

const groupEntryId = value instanceof Object ? value[groupBy] : undefined;
if (populate(groups[groupId], groupEntryId, () => mkChild(value))) {
ref.push(groups[groupId][groupEntryId]);
}
path.push(`${groupBy}=${groupEntryId}`);

@@ -93,12 +76,5 @@ stack.push(groups[groupId][groupEntryId]);

},
filterFn: ({
matchedBy,
context
}) => {
const {
stack,
path
} = context;
filterFn: ({ matchedBy, context }) => {
const { stack, path } = context;
stack.pop();
if (logic[last(matchedBy)] !== null) {

@@ -112,10 +88,6 @@ path.pop();

const groups = {};
args.forEach(arg => scanner(arg, {
stack,
groups,
path: []
}));
args.forEach((arg) => scanner(arg, { stack, groups, path: [] }));
assert(stack.length === 1);
return stack[0];
};
};
};

@@ -1,16 +0,4 @@

"use strict";
const align = require('./core/align');
const clone = require('./core/clone');
const contains = require('./core/contains');
const Merge = require('./core/merge');
module.exports = {
align,
clone,
contains,
Merge
};
export { default as align } from './core/align.js';
export { default as clone } from './core/clone.js';
export { default as contains } from './core/contains.js';
export { default as Merge } from './core/merge.js';

@@ -1,3 +0,1 @@

"use strict";
module.exports = arr => arr[arr.length - 1];
export default (arr) => arr[arr.length - 1];

@@ -1,9 +0,6 @@

"use strict";
module.exports = ref => {
export default (ref) => {
if (!(ref instanceof Object)) {
return ref;
}
return Array.isArray(ref) ? [] : {};
};
};
{
"name": "object-lib",
"version": "3.0.1",
"type": "module",
"version": "4.0.0",
"main": "lib/index.js",

@@ -12,23 +13,19 @@ "repository": {

"devDependencies": {
"@babel/cli": "7.14.8",
"@babel/core": "7.15.0",
"@babel/register": "7.15.3",
"@blackflux/eslint-plugin-rules": "2.0.3",
"@blackflux/robo-config-plugin": "5.3.0",
"babel-eslint": "10.1.0",
"babel-preset-latest-node": "5.5.1",
"chai": "4.3.4",
"coveralls": "3.1.1",
"eslint": "7.32.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-plugin-import": "2.24.2",
"@babel/core": "7.22.9",
"@babel/eslint-parser": "7.22.9",
"@babel/register": "7.22.5",
"@blackflux/eslint-plugin-rules": "3.0.0",
"@blackflux/robo-config-plugin": "9.1.9",
"c8": "8.0.1",
"chai": "4.3.7",
"eslint": "8.46.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-json": "3.1.0",
"eslint-plugin-markdown": "2.2.0",
"eslint-plugin-mocha": "9.0.0",
"js-gardener": "3.0.3",
"eslint-plugin-markdown": "3.0.1",
"eslint-plugin-mocha": "10.1.0",
"js-gardener": "5.0.1",
"lodash.clonedeep": "4.5.0",
"lodash.samplesize": "4.2.0",
"node-tdd": "3.0.4",
"nyc": "15.1.0",
"semantic-release": "17.4.7"
"node-tdd": "4.0.0"
},

@@ -56,32 +53,2 @@ "licenses": [

],
"nyc": {
"exclude": [
"gardener.js",
"node_modules/*",
"coverage/*",
"lib/*"
],
"tempDir": "./coverage/.nyc_output",
"report-dir": "./coverage",
"check-coverage": true,
"per-file": false,
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100,
"include": [
"**/*.js"
],
"reporter": [
"lcov",
"text-summary"
],
"require": [
"@babel/register"
],
"extension": [],
"cache": true,
"all": true,
"babel": true
},
"files": [

@@ -92,5 +59,5 @@ "lib"

"clean": "rm -rf lib",
"build": "npx babel src --out-dir lib --copy-files --include-dotfiles --config-file ./.babelrc",
"build": "cp -rf ./src ./lib",
"build-clean": "yarn run clean && yarn run build",
"test-simple": "nyc mocha \"./test/**/*.spec.js\"",
"test-simple": "c8 mocha --experimental-loader=./test/hot.js \"./test/**/*.spec.js\"",
"test": "yarn run clean && yarn run gardener && yarn run test-simple",

@@ -104,5 +71,4 @@ "docker": "docker run --net host -u`id -u`:`id -g` -v $(pwd):/user/project -v ~/.aws:/user/.aws -v ~/.npmrc:/user/.npmrc -w /user/project -it --entrypoint /bin/bash",

"tsv": "yarn run test-simple --verbose",
"coveralls": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
"semantic-release": "yarn run build-clean && npx semantic-release",
"gardener": "node gardener"
"gardener": "node gardener.js"
},

@@ -114,7 +80,7 @@ "homepage": "https://github.com/blackflux/object-lib#readme",

"engines": {
"node": ">= 12"
"node": ">= 16"
},
"dependencies": {
"object-scan": "17.0.0"
"object-scan": "19.0.0"
}
}

@@ -27,3 +27,3 @@ # object-lib

```js
const { align } = require('object-lib');
import { align } from 'object-lib';

@@ -50,3 +50,3 @@ const obj = { k1: 1, k2: 2 };

```js
const { clone } = require('object-lib');
import { clone } from 'object-lib';

@@ -81,3 +81,3 @@ const data = { a: {}, b: {}, c: {} };

```js
const { contains } = require('object-lib');
import { contains } from 'object-lib';

@@ -102,3 +102,3 @@ contains({ a: [1, 2], b: 'c' }, { a: [1, 2] });

```js
const { Merge } = require('object-lib');
import { Merge } from 'object-lib';

@@ -105,0 +105,0 @@ Merge()(

Sorry, the diff of this file is not supported yet

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