Socket
Socket
Sign inDemoInstall

object-scan

Package Overview
Dependencies
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-scan - npm Package Compare versions

Comparing version 18.0.1 to 18.0.2

37

lib/core/compiler.js

@@ -15,2 +15,6 @@ /* compile needles to hierarchical map object */

const ROOTS = Symbol('roots');
const setRoots = (input, roots) => defineProperty(input, ROOTS, roots);
export const getRoots = (input) => input[ROOTS];
const HAS_MATCHES = Symbol('has-matches');

@@ -62,7 +66,7 @@ const setHasMatches = (input) => defineProperty(input, HAS_MATCHES, true);

export const matchedBy = (searches) => Array
.from(new Set([].concat(...searches.map((e) => getLeafNeedlesMatch(e)))));
.from(new Set(searches.flatMap((e) => getLeafNeedlesMatch(e))));
export const excludedBy = (searches) => Array
.from(new Set([].concat(...searches.map((e) => getLeafNeedlesExclude(e)))));
.from(new Set(searches.flatMap((e) => getLeafNeedlesExclude(e))));
export const traversedBy = (searches) => Array
.from(new Set([].concat(...searches.map((e) => getNeedles(e)))));
.from(new Set(searches.flatMap((e) => getNeedles(e))));

@@ -111,3 +115,3 @@ export const isLastLeafMatch = (searches) => {

.filter(([cur]) => cur !== tower)
.forEach(([cur, parent]) => onFin(cur, wc[wc.length - 1], parent, excluded));
.forEach(([cur, parent]) => onFin(cur, parent, wc[wc.length - 1], excluded));
}

@@ -145,9 +149,7 @@ });

},
onFin: (cur, wc, parent, excluded) => {
if (ctx.strict) {
if (wc.isSimpleStarRec) {
const unnecessary = Object.keys(parent).filter((k) => !['**', ''].includes(k));
if (unnecessary.length !== 0) {
throw new Error(`Needle Target Invalidated: "${parent[unnecessary[0]][NEEDLES][0]}" by "${needle}"`);
}
onFin: (cur, parent, wc, excluded) => {
if (ctx.strict && wc.isSimpleStarRec) {
const unnecessary = Object.keys(parent).filter((k) => !['**', ''].includes(k));
if (unnecessary.length !== 0) {
throw new Error(`Needle Target Invalidated: "${parent[unnecessary[0]][NEEDLES][0]}" by "${needle}"`);
}

@@ -172,3 +174,3 @@ }

const finalizeTower = (tower) => {
const finalizeTower = (tower, ctx) => {
const matches = [];

@@ -191,2 +193,11 @@ let lastDepth = -1;

});
if (ctx.useArraySelector === false) {
const roots = [];
if ('' in tower) {
roots.push(tower['']);
}
roots.push(...getValues(tower).filter((e) => getWildcard(e).isStarRec));
setRoots(tower, roots);
}
};

@@ -203,4 +214,4 @@

setWildcard(tower, new Wildcard('*', false));
finalizeTower(tower);
finalizeTower(tower, ctx);
return tower;
};

@@ -5,3 +5,3 @@ import assert from 'assert';

hasMatches, matchedBy, isLastLeafMatch,
getValues, getOrder
getValues, getOrder, getRoots
} from './compiler.js';

@@ -169,8 +169,4 @@ import Result from './find-result.js';

searchesOut.push(...searches);
if (path.length === 0) {
if ('' in searches[0]) {
searchesOut.push(searches[0]['']);
}
searchesOut.push(...getValues(searches[0])
.filter((v) => getWildcard(v).isStarRec));
if (depth === 0) {
searchesOut.push(...getRoots(searches[0]));
}

@@ -180,3 +176,3 @@ } else {

const search = searches[sIdx];
if (getWildcard(search).anyMatch(key)) {
if (getWildcard(search).recMatch(key)) {
searchesOut.push(search);

@@ -183,0 +179,0 @@ }

@@ -58,8 +58,10 @@ import assert from 'assert';

},
finishElement: (idx, { err, fins, finReq = false }) => {
finishElement: (idx, err, fins, { finReq = false } = {}) => {
const isFinished = cursor === idx;
if (isFinished && !fins.includes(input[idx - 1] || null)) {
throwError(err, input, { char: idx });
}
if (!isFinished) {
if (isFinished) {
if (!fins.includes(input[idx - 1] || null)) {
throwError(err, input, { char: idx });
}
cursor += 1;
} else {
if (finReq) {

@@ -77,4 +79,4 @@ throwError(err, input, { char: idx });

excludeNext = false;
cursor = idx + 1;
}
cursor = idx + 1;
},

@@ -81,0 +83,0 @@ startExclusion: (idx) => {

@@ -21,39 +21,39 @@ import { Wildcard } from './wildcard.js';

const char = input[idx];
if (escaped === false && bracketDepth === 0) {
switch (char) {
case '.':
result.finishElement(idx, { err: 'Bad Path Separator', fins: [']', '}'] });
break;
case '[':
if (!ctx.useArraySelector) {
throwError('Forbidden Array Selector', input, { char: idx });
}
result.finishElement(idx, { err: 'Bad Array Start', fins: [null, '!', '{', ',', '}', ']'] });
result.setInArray(true, idx);
break;
case ']':
result.finishElement(idx, { err: 'Bad Array Terminator', fins: ['}'] });
result.setInArray(false, idx);
break;
case '{':
result.finishElement(idx, { err: 'Bad Group Start', fins: [null, '!', '.', '[', '{', ','], finReq: true });
result.startGroup();
break;
case ',':
result.finishElement(idx, { err: 'Bad Group Separator', fins: [']', '}'] });
result.newGroupElement();
break;
case '}':
result.finishElement(idx, { err: 'Bad Group Terminator', fins: [']', '}'] });
result.finishGroup(idx);
break;
case '!':
result.finishElement(idx, { err: 'Bad Exclusion', fins: [null, '.', ',', '{', '['], finReq: true });
result.startExclusion(idx);
break;
default:
break;
if (escaped === false) {
if (bracketDepth === 0) {
switch (char) {
case '.':
result.finishElement(idx, 'Bad Path Separator', [']', '}']);
break;
case '[':
if (!ctx.useArraySelector) {
throwError('Forbidden Array Selector', input, { char: idx });
}
result.finishElement(idx, 'Bad Array Start', [null, '!', '{', ',', '}', ']']);
result.setInArray(true, idx);
break;
case ']':
result.finishElement(idx, 'Bad Array Terminator', ['}']);
result.setInArray(false, idx);
break;
case '{':
result.finishElement(idx, 'Bad Group Start', [null, '!', '.', '[', '{', ','], { finReq: true });
result.startGroup();
break;
case ',':
result.finishElement(idx, 'Bad Group Separator', [']', '}']);
result.newGroupElement();
break;
case '}':
result.finishElement(idx, 'Bad Group Terminator', [']', '}']);
result.finishGroup(idx);
break;
case '!':
result.finishElement(idx, 'Bad Exclusion', [null, '.', ',', '{', '['], { finReq: true });
result.startExclusion(idx);
break;
default:
break;
}
}
}
if (escaped === false) {
switch (char) {

@@ -83,5 +83,5 @@ case '(':

result.finishElement(inputLength, { err: 'Bad Terminator', fins: [']', '}'] });
result.finishElement(inputLength, 'Bad Terminator', [']', '}']);
return result.finalizeResult();
};
export default { parse };

@@ -62,3 +62,3 @@ import { escapeRegex, asRegex } from '../generic/helper.js';

anyMatch(key) {
recMatch(key) {
if (!this.isRec) {

@@ -65,0 +65,0 @@ return false;

{
"name": "object-scan",
"type": "module",
"version": "18.0.1",
"version": "18.0.2",
"description": "Traverse object hierarchies using matching and callbacks.",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

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