object-no-new-keys 4.0.4 → 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/CHANGELOG.md +0 -20
- package/LICENSE +1 -1
- package/README.md +4 -1
- package/dist/object-no-new-keys.esm.js +2 -67
- package/dist/object-no-new-keys.umd.js +2 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +21 -83
- package/types/index.d.ts +1 -1
- package/examples/api.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## 4.0.3 (2021-11-02)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
-
|
|
16
|
-
### BREAKING CHANGES
|
|
17
|
-
|
|
18
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
-
|
|
20
|
-
## 4.0.1 (2021-09-13)
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
25
|
-
|
|
26
6
|
## 4.0.0 (2021-09-09)
|
|
27
7
|
|
|
28
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
3
|
+
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
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,75 +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,
|
|
24
|
-
...originalOptsOuter
|
|
25
|
-
};
|
|
26
|
-
if (typeof optsOuter.mode === "string" && ["1", "2"].includes(optsOuter.mode)) {
|
|
27
|
-
optsOuter.mode = +optsOuter.mode;
|
|
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
|
-
} else if (isObj(input[key]) || Array.isArray(input[key])) {
|
|
40
|
-
temp = {
|
|
41
|
-
path: innerVar.path.length > 0 ? `${innerVar.path}.${key}` : key,
|
|
42
|
-
res: innerVar.res
|
|
43
|
-
};
|
|
44
|
-
innerVar.res = objectNoNewKeysInternal(input[key], reference[key], opts, temp).res;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
innerVar.res = innerVar.res.concat(Object.keys(input).map(key => innerVar.path.length > 0 ? `${innerVar.path}.${key}` : key));
|
|
49
|
-
}
|
|
50
|
-
} else if (Array.isArray(input)) {
|
|
51
|
-
if (Array.isArray(reference)) {
|
|
52
|
-
for (let i = 0, len = input.length; i < len; i++) {
|
|
53
|
-
temp = {
|
|
54
|
-
path: `${innerVar.path.length > 0 ? innerVar.path : ""}[${i}]`,
|
|
55
|
-
res: innerVar.res
|
|
56
|
-
};
|
|
57
|
-
if (opts.mode === 2) {
|
|
58
|
-
innerVar.res = objectNoNewKeysInternal(input[i], reference[0], opts, temp).res;
|
|
59
|
-
} else {
|
|
60
|
-
innerVar.res = objectNoNewKeysInternal(input[i], reference[i], opts, temp).res;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
innerVar.res = innerVar.res.concat(input.map((_el, i) => `${innerVar.path.length > 0 ? innerVar.path : ""}[${i}]`));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return innerVar;
|
|
68
|
-
}
|
|
69
|
-
return objectNoNewKeysInternal(inputOuter, referenceOuter, optsOuter, {
|
|
70
|
-
path: "",
|
|
71
|
-
res: []
|
|
72
|
-
}).res;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
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,96 +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
|
-
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
51
|
-
"republish": "npm publish || :",
|
|
52
|
-
"tap": "tap",
|
|
53
|
-
"pretest": "npm run build",
|
|
54
|
-
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
55
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
56
|
-
"tsc": "tsc",
|
|
57
|
-
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
"--no-warnings",
|
|
67
|
-
"--experimental-loader",
|
|
68
|
-
"@istanbuljs/esm-loader-hook"
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"c8": {
|
|
55
|
+
"check-coverage": true,
|
|
56
|
+
"exclude": [
|
|
57
|
+
"**/test/**/*.*"
|
|
69
58
|
],
|
|
70
|
-
"
|
|
59
|
+
"lines": 100
|
|
71
60
|
},
|
|
72
61
|
"lect": {
|
|
73
62
|
"licence": {
|
|
74
63
|
"extras": [
|
|
75
64
|
""
|
|
76
65
|
]
|
|
77
|
-
},
|
|
78
|
-
"req": "{ noNewKeys }",
|
|
79
|
-
"various": {
|
|
80
|
-
"devDependencies": [
|
|
81
|
-
"type-fest"
|
|
82
|
-
]
|
|
83
66
|
}
|
|
84
|
-
},
|
|
85
|
-
"dependencies": {
|
|
86
|
-
"@babel/runtime": "^7.16.0"
|
|
87
|
-
},
|
|
88
|
-
"devDependencies": {
|
|
89
|
-
"@babel/cli": "^7.16.0",
|
|
90
|
-
"@babel/core": "^7.16.0",
|
|
91
|
-
"@babel/node": "^7.16.0",
|
|
92
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
93
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
94
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
95
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
96
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
97
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
98
|
-
"@babel/preset-env": "^7.16.0",
|
|
99
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
100
|
-
"@babel/register": "^7.16.0",
|
|
101
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
102
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
103
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
104
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
105
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
106
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
107
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
108
|
-
"@types/node": "^16.11.6",
|
|
109
|
-
"@types/tap": "^15.0.5",
|
|
110
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
111
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
112
|
-
"core-js": "^3.19.1",
|
|
113
|
-
"cross-env": "^7.0.3",
|
|
114
|
-
"eslint": "^8.1.0",
|
|
115
|
-
"lect": "^0.18.4",
|
|
116
|
-
"rollup": "^2.59.0",
|
|
117
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
118
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
119
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
120
|
-
"rollup-plugin-dts": "^4.0.0",
|
|
121
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
122
|
-
"tap": "^15.0.10",
|
|
123
|
-
"tslib": "^2.3.1",
|
|
124
|
-
"type-fest": "^2.5.2",
|
|
125
|
-
"typescript": "^4.4.4"
|
|
126
|
-
},
|
|
127
|
-
"engines": {
|
|
128
|
-
"node": ">=12"
|
|
129
67
|
}
|
|
130
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);"}}
|