object-no-new-keys 4.0.7 → 4.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/object-no-new-keys.esm.js +2 -72
- package/dist/object-no-new-keys.umd.js +2 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +21 -79
- package/types/index.d.ts +1 -1
- package/examples/api.json +0 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 3.1.0
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
import { strict as assert } from "assert";
|
|
41
|
+
|
|
41
42
|
import { noNewKeys } from "object-no-new-keys";
|
|
42
43
|
|
|
43
44
|
assert.deepEqual(
|
|
@@ -61,7 +62,7 @@ assert.deepEqual(
|
|
|
61
62
|
|
|
62
63
|
## Documentation
|
|
63
64
|
|
|
64
|
-
Please [visit codsen.com](https://codsen.com/os/object-no-new-keys/) for a full description of the API
|
|
65
|
+
Please [visit codsen.com](https://codsen.com/os/object-no-new-keys/) for a full description of the API.
|
|
65
66
|
|
|
66
67
|
## Contributing
|
|
67
68
|
|
|
@@ -73,4 +74,6 @@ MIT License
|
|
|
73
74
|
|
|
74
75
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
75
76
|
|
|
77
|
+
|
|
76
78
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
79
|
+
|
|
@@ -1,80 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name object-no-new-keys
|
|
3
3
|
* @fileoverview Check, does a plain object (AST/JSON) has any unique keys, not present in a reference object (another AST/JSON)
|
|
4
|
-
* @version 4.0.
|
|
4
|
+
* @version 4.0.10
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/object-no-new-keys/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
const version = version$1;
|
|
13
|
-
function isObj(something) {
|
|
14
|
-
return (something && typeof something === "object" && !Array.isArray(something));
|
|
15
|
-
}
|
|
16
|
-
function noNewKeys(inputOuter, referenceOuter, originalOptsOuter) {
|
|
17
|
-
if (originalOptsOuter && !isObj(originalOptsOuter)) {
|
|
18
|
-
throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(originalOptsOuter, null, 4)} (type ${typeof originalOptsOuter})`);
|
|
19
|
-
}
|
|
20
|
-
const defaults = {
|
|
21
|
-
mode: 2,
|
|
22
|
-
};
|
|
23
|
-
const optsOuter = { ...defaults, ...originalOptsOuter };
|
|
24
|
-
if (typeof optsOuter.mode === "string" &&
|
|
25
|
-
["1", "2"].includes(optsOuter.mode)) {
|
|
26
|
-
optsOuter.mode = +optsOuter.mode;
|
|
27
|
-
}
|
|
28
|
-
else if (![1, 2].includes(optsOuter.mode)) {
|
|
29
|
-
throw new TypeError(`object-no-new-keys/objectNoNewKeys(): [THROW_ID_01] opts.mode should be "1" or "2" (string or number).`);
|
|
30
|
-
}
|
|
31
|
-
function objectNoNewKeysInternal(input, reference, opts, innerVar) {
|
|
32
|
-
let temp;
|
|
33
|
-
if (isObj(input)) {
|
|
34
|
-
if (isObj(reference)) {
|
|
35
|
-
Object.keys(input).forEach((key) => {
|
|
36
|
-
if (!Object.prototype.hasOwnProperty.call(reference, key)) {
|
|
37
|
-
temp = innerVar.path.length > 0 ? `${innerVar.path}.${key}` : key;
|
|
38
|
-
innerVar.res.push(temp);
|
|
39
|
-
}
|
|
40
|
-
else if (isObj(input[key]) || Array.isArray(input[key])) {
|
|
41
|
-
temp = {
|
|
42
|
-
path: innerVar.path.length > 0 ? `${innerVar.path}.${key}` : key,
|
|
43
|
-
res: innerVar.res,
|
|
44
|
-
};
|
|
45
|
-
innerVar.res = objectNoNewKeysInternal(input[key], reference[key], opts, temp).res;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
innerVar.res = innerVar.res.concat(Object.keys(input).map((key) => innerVar.path.length > 0 ? `${innerVar.path}.${key}` : key));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (Array.isArray(input)) {
|
|
54
|
-
if (Array.isArray(reference)) {
|
|
55
|
-
for (let i = 0, len = input.length; i < len; i++) {
|
|
56
|
-
temp = {
|
|
57
|
-
path: `${innerVar.path.length > 0 ? innerVar.path : ""}[${i}]`,
|
|
58
|
-
res: innerVar.res,
|
|
59
|
-
};
|
|
60
|
-
if (opts.mode === 2) {
|
|
61
|
-
innerVar.res = objectNoNewKeysInternal(input[i], reference[0], opts, temp).res;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
innerVar.res = objectNoNewKeysInternal(input[i], reference[i], opts, temp).res;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
innerVar.res = innerVar.res.concat(input.map((_el, i) => `${innerVar.path.length > 0 ? innerVar.path : ""}[${i}]`));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return innerVar;
|
|
73
|
-
}
|
|
74
|
-
return objectNoNewKeysInternal(inputOuter, referenceOuter, optsOuter, {
|
|
75
|
-
path: "",
|
|
76
|
-
res: [],
|
|
77
|
-
}).res;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { noNewKeys, version };
|
|
10
|
+
var u="4.0.10";var f=u;function y(l){return l&&typeof l=="object"&&!Array.isArray(l)}function w(l,h,r){if(r&&!y(r))throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(r,null,4)} (type ${typeof r})`);let n={...{mode:2},...r};if(typeof n.mode=="string"&&["1","2"].includes(n.mode))n.mode=+n.mode;else if(![1,2].includes(n.mode))throw new TypeError('object-no-new-keys/objectNoNewKeys(): [THROW_ID_01] opts.mode should be "1" or "2" (string or number).');function a(t,c,p,e){let o;if(y(t))y(c)?Object.keys(t).forEach(s=>{Object.prototype.hasOwnProperty.call(c,s)?(y(t[s])||Array.isArray(t[s]))&&(o={path:e.path.length>0?`${e.path}.${s}`:s,res:e.res},e.res=a(t[s],c[s],p,o).res):(o=e.path.length>0?`${e.path}.${s}`:s,e.res.push(o))}):e.res=e.res.concat(Object.keys(t).map(s=>e.path.length>0?`${e.path}.${s}`:s));else if(Array.isArray(t))if(Array.isArray(c))for(let s=0,d=t.length;s<d;s++)o={path:`${e.path.length>0?e.path:""}[${s}]`,res:e.res},p.mode===2?e.res=a(t[s],c[0],p,o).res:e.res=a(t[s],c[s],p,o).res;else e.res=e.res.concat(t.map((s,d)=>`${e.path.length>0?e.path:""}[${d}]`));return e}return a(l,h,n,{path:"",res:[]}).res}export{w as noNewKeys,f as version};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name object-no-new-keys
|
|
3
3
|
* @fileoverview Check, does a plain object (AST/JSON) has any unique keys, not present in a reference object (another AST/JSON)
|
|
4
|
-
* @version 4.0.
|
|
4
|
+
* @version 4.0.10
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/object-no-new-keys/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var objectNoNewKeys=(()=>{var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var f=(e,s,t)=>s in e?d(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,b=(e,s)=>{for(var t in s||(s={}))j.call(s,t)&&f(e,t,s[t]);if(m)for(var t of m(s))J.call(s,t)&&f(e,t,s[t]);return e};var $=e=>d(e,"__esModule",{value:!0});var v=(e,s)=>{for(var t in s)d(e,t,{get:s[t],enumerable:!0})},O=(e,s,t,h)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of A(s))!j.call(e,c)&&(t||c!=="default")&&d(e,c,{get:()=>s[c],enumerable:!(h=g(s,c))||h.enumerable});return e};var x=(e=>(s,t)=>e&&e.get(s)||(t=O($({}),s,1),e&&e.set(s,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var I={};v(I,{noNewKeys:()=>T,version:()=>k});var w="4.0.10";var k=w;function u(e){return e&&typeof e=="object"&&!Array.isArray(e)}function T(e,s,t){if(t&&!u(t))throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(t,null,4)} (type ${typeof t})`);let c=b(b({},{mode:2}),t);if(typeof c.mode=="string"&&["1","2"].includes(c.mode))c.mode=+c.mode;else if(![1,2].includes(c.mode))throw new TypeError('object-no-new-keys/objectNoNewKeys(): [THROW_ID_01] opts.mode should be "1" or "2" (string or number).');function p(l,a,y,o){let r;if(u(l))u(a)?Object.keys(l).forEach(n=>{Object.prototype.hasOwnProperty.call(a,n)?(u(l[n])||Array.isArray(l[n]))&&(r={path:o.path.length>0?`${o.path}.${n}`:n,res:o.res},o.res=p(l[n],a[n],y,r).res):(r=o.path.length>0?`${o.path}.${n}`:n,o.res.push(r))}):o.res=o.res.concat(Object.keys(l).map(n=>o.path.length>0?`${o.path}.${n}`:n));else if(Array.isArray(l))if(Array.isArray(a))for(let n=0,i=l.length;n<i;n++)r={path:`${o.path.length>0?o.path:""}[${n}]`,res:o.res},y.mode===2?o.res=p(l[n],a[0],y,r).res:o.res=p(l[n],a[n],y,r).res;else o.res=o.res.concat(l.map((n,i)=>`${o.path.length>0?o.path:""}[${i}]`));return o}return p(e,s,c,{path:"",res:[]}).res}return x(I);})();
|
package/examples/_quickTake.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "object-no-new-keys",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.10",
|
|
4
4
|
"description": "Check, does a plain object (AST/JSON) has any unique keys, not present in a reference object (another AST/JSON)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compare",
|
|
@@ -35,92 +35,34 @@
|
|
|
35
35
|
},
|
|
36
36
|
"types": "types/index.d.ts",
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"republish": "npm publish || :",
|
|
51
|
-
"tap": "tap",
|
|
52
|
-
"pretest": "npm run build",
|
|
53
|
-
"test": "npm run test:ci && npm run perf",
|
|
54
|
-
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
55
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
56
|
-
"tsc": "tsc",
|
|
57
|
-
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
38
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
39
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
40
|
+
"dts": "rollup -c",
|
|
41
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
42
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
43
|
+
"letspublish": "yarn publish || :",
|
|
44
|
+
"lint": "eslint . --fix",
|
|
45
|
+
"perf": "node perf/check.js",
|
|
46
|
+
"prepare": "echo 'ready'",
|
|
47
|
+
"pretest": "yarn run lect && yarn run build",
|
|
48
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
49
|
+
"unit": "uvu test"
|
|
58
50
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"c8": {
|
|
55
|
+
"check-coverage": true,
|
|
56
|
+
"exclude": [
|
|
57
|
+
"**/test/**/*.*"
|
|
65
58
|
],
|
|
66
|
-
"
|
|
59
|
+
"lines": 100
|
|
67
60
|
},
|
|
68
61
|
"lect": {
|
|
69
62
|
"licence": {
|
|
70
63
|
"extras": [
|
|
71
64
|
""
|
|
72
65
|
]
|
|
73
|
-
},
|
|
74
|
-
"req": "{ noNewKeys }",
|
|
75
|
-
"various": {
|
|
76
|
-
"devDependencies": [
|
|
77
|
-
"type-fest"
|
|
78
|
-
]
|
|
79
66
|
}
|
|
80
|
-
},
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"@babel/runtime": "^7.16.3"
|
|
83
|
-
},
|
|
84
|
-
"devDependencies": {
|
|
85
|
-
"@babel/cli": "^7.16.0",
|
|
86
|
-
"@babel/core": "^7.16.0",
|
|
87
|
-
"@babel/node": "^7.16.0",
|
|
88
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
89
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
90
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
91
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
92
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
94
|
-
"@babel/preset-env": "^7.16.4",
|
|
95
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
96
|
-
"@babel/register": "^7.16.0",
|
|
97
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
98
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
99
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
100
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
101
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
102
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
103
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
104
|
-
"@types/node": "^16.11.10",
|
|
105
|
-
"@types/tap": "^15.0.5",
|
|
106
|
-
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
107
|
-
"@typescript-eslint/parser": "^5.5.0",
|
|
108
|
-
"core-js": "^3.19.2",
|
|
109
|
-
"cross-env": "^7.0.3",
|
|
110
|
-
"eslint": "^8.3.0",
|
|
111
|
-
"lect": "^0.18.7",
|
|
112
|
-
"rollup": "^2.60.1",
|
|
113
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
114
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
115
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
116
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
117
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
118
|
-
"tap": "^15.1.5",
|
|
119
|
-
"tslib": "^2.3.1",
|
|
120
|
-
"type-fest": "^2.6.0",
|
|
121
|
-
"typescript": "^4.5.2"
|
|
122
|
-
},
|
|
123
|
-
"engines": {
|
|
124
|
-
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
125
67
|
}
|
|
126
68
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare type JsonValue = string | number | boolean | null | JsonObject | JsonArr
|
|
|
3
3
|
declare type JsonObject = {
|
|
4
4
|
[Key in string]?: JsonValue;
|
|
5
5
|
};
|
|
6
|
-
declare type JsonArray =
|
|
6
|
+
declare type JsonArray = JsonValue[];
|
|
7
7
|
interface Opts {
|
|
8
8
|
mode: 1 | 2;
|
|
9
9
|
}
|
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { noNewKeys } from \"object-no-new-keys\";\n\nassert.deepEqual(\n noNewKeys(\n {\n a: {\n b: \"b\",\n c: \"c\",\n },\n x: \"y\",\n },\n {\n a: {\n c: \"z\",\n },\n }\n ),\n [\"a.b\", \"x\"]\n);"}}
|