Skip to content

Commit d3680b9

Browse files
author
Sascha Goldhofer
committed
remove: gson-conform dependency
1 parent 6bbc495 commit d3680b9

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

lib/interpreter/nodes.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,36 @@ function nodeAsRegex(node) {
1616
return new RegExp(node.text.replace(/(^{|}$)/g, ""));
1717
}
1818

19+
/**
20+
* Iterates over object or array, passing each key, value and parentObject to the callback
21+
* @param value - to iterate
22+
* @param callback - receiving key on given input value
23+
*/
24+
function forEach(parent: Record<string, unknown> | unknown[], callback) {
25+
if (Array.isArray(parent)) {
26+
parent.forEach(callback);
27+
} else if (Object.prototype.toString.call(parent) === "[object Object]") {
28+
Object.keys(parent).forEach(function (key) {
29+
callback(parent[key], key, parent);
30+
});
31+
}
32+
}
33+
1934
/**
2035
* Returns all keys of the given input data
21-
*
2236
* @param value
2337
* @return {Array} containing keys of given value
2438
*/
25-
function getKeys(value: unknown) {
26-
let keys;
39+
function getKeys(value: unknown): string[] {
2740
if (Array.isArray(value)) {
28-
keys = value.map(function (value, index) {
29-
return index;
41+
return value.map(function (value, index) {
42+
return `${index}`;
3043
});
31-
} else if (Object.prototype.toString.call(value) === "[object Object]") {
44+
}
45+
if (Object.prototype.toString.call(value) === "[object Object]") {
3246
return Object.keys(value);
33-
} else {
34-
keys = [];
3547
}
36-
return keys;
48+
return [];
3749
}
3850

3951
const cache = {
@@ -70,7 +82,7 @@ const expand = {
7082

7183
all(node: IToken, entry) {
7284
const result = [entry];
73-
o.forEach(entry[VALUE_INDEX], (value, prop) => {
85+
forEach(entry[VALUE_INDEX], (value, prop) => {
7486
const childEntry = cache.get(entry, prop);
7587
// const childEntry = [value, prop, entry[VALUE_INDEX], join(entry[POINTER_INDEX], prop)];
7688
childEntry && result.push(...expand.all(node, childEntry));
@@ -154,15 +166,13 @@ function expressionMatches(value, cmp, test) {
154166
}
155167

156168
let valid;
157-
const valueString = "" + value;
158-
169+
const valueString = `${value}`;
159170
if (test.type === "regex") {
160171
const regex = nodeAsRegex(test);
161172
valid = regex.test(valueString);
162173
} else {
163174
valid = valueString === test.text;
164175
}
165-
166176
if (cmp.type === "isnot") {
167177
valid = valid === false && value !== undefined;
168178
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@sagold/json-pointer": "^5.0.0",
27-
"ebnf": "^1.9.0",
28-
"gson-conform": "^1.0.3"
27+
"ebnf": "^1.9.0"
2928
},
3029
"devDependencies": {
3130
"@types/chai": "^4.2.14",

yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -1448,11 +1448,6 @@ grapheme-splitter@^1.0.4:
14481448
resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e"
14491449
integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==
14501450

1451-
gson-conform@^1.0.3:
1452-
version "1.0.3"
1453-
resolved "https://registry.yarnpkg.com/gson-conform/-/gson-conform-1.0.3.tgz#6f982f98ea84199280bd48b6bfbcd0ae7447f1e2"
1454-
integrity sha512-gaZQN/5ZbohkLBOs4JKHkg/IdOB9kuuEr5SVLAjHUs+Q+Nl746DRe18GgQy4oxxVXStO//Zga2wg4eWL9Mfshw==
1455-
14561451
has-flag@^3.0.0:
14571452
version "3.0.0"
14581453
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"

0 commit comments

Comments
 (0)