object-no-new-keys 4.0.6 → 4.0.12

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2022 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
@@ -26,18 +26,17 @@
26
26
 
27
27
  ## Install
28
28
 
29
- This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
29
+ The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `3.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i object-no-new-keys
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 3.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { noNewKeys } from "object-no-new-keys";
42
41
 
43
42
  assert.deepEqual(
@@ -61,7 +60,7 @@ assert.deepEqual(
61
60
 
62
61
  ## Documentation
63
62
 
64
- Please [visit codsen.com](https://codsen.com/os/object-no-new-keys/) for a full description of the API and examples.
63
+ Please [visit codsen.com](https://codsen.com/os/object-no-new-keys/) for a full description of the API.
65
64
 
66
65
  ## Contributing
67
66
 
@@ -71,6 +70,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
71
70
 
72
71
  MIT License
73
72
 
74
- Copyright (c) 2010-2021 Roy Revelt and other contributors
73
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
75
74
 
76
75
  <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">
@@ -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.6
4
+ * @version 4.0.12
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 version$1 = "4.0.6";
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 i="4.0.12";var f=i;function y(a){return a&&typeof a=="object"&&!Array.isArray(a)}function w(a,u,c){if(c&&!y(c))throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(c,null,4)} (type ${typeof c})`);let r={...{mode:2},...c};if(typeof r.mode=="string"&&["1","2"].includes(r.mode))r.mode=+r.mode;else if(![1,2].includes(r.mode))throw new TypeError('object-no-new-keys/objectNoNewKeys(): [THROW_ID_01] opts.mode should be "1" or "2" (string or number).');function l(s,n,p,e){let o;if(y(s))y(n)?Object.keys(s).forEach(t=>{Object.prototype.hasOwnProperty.call(n,t)?(y(s[t])||Array.isArray(s[t]))&&(o={path:e.path.length>0?`${e.path}.${t}`:t,res:e.res},e.res=l(s[t],n[t],p,o).res):(o=e.path.length>0?`${e.path}.${t}`:t,e.res.push(o))}):e.res=e.res.concat(Object.keys(s).map(t=>e.path.length>0?`${e.path}.${t}`:t));else if(Array.isArray(s))if(Array.isArray(n))for(let t=0,d=s.length;t<d;t++)o={path:`${e.path.length>0?e.path:""}[${t}]`,res:e.res},p.mode===2?e.res=l(s[t],n[0],p,o).res:e.res=l(s[t],n[t],p,o).res;else e.res=e.res.concat(s.map((t,d)=>`${e.path.length>0?e.path:""}[${d}]`));return e}return l(a,u,r,{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.6
4
+ * @version 4.0.12
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
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).objectNoNewKeys={})}(this,(function(e){"use strict";function t(e){return e&&"object"==typeof e&&!Array.isArray(e)}e.noNewKeys=function(e,r,o){if(o&&!t(o))throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(o,null,4)} (type ${typeof o})`);const s={mode:2,...o};if("string"==typeof s.mode&&["1","2"].includes(s.mode))s.mode=+s.mode;else if(![1,2].includes(s.mode))throw new TypeError('object-no-new-keys/objectNoNewKeys(): [THROW_ID_01] opts.mode should be "1" or "2" (string or number).');return function e(r,o,s,n){let a;if(t(r))t(o)?Object.keys(r).forEach((p=>{Object.prototype.hasOwnProperty.call(o,p)?(t(r[p])||Array.isArray(r[p]))&&(a={path:n.path.length>0?`${n.path}.${p}`:p,res:n.res},n.res=e(r[p],o[p],s,a).res):(a=n.path.length>0?`${n.path}.${p}`:p,n.res.push(a))})):n.res=n.res.concat(Object.keys(r).map((e=>n.path.length>0?`${n.path}.${e}`:e)));else if(Array.isArray(r))if(Array.isArray(o))for(let t=0,p=r.length;t<p;t++)a={path:`${n.path.length>0?n.path:""}[${t}]`,res:n.res},n.res=2===s.mode?e(r[t],o[0],s,a).res:e(r[t],o[t],s,a).res;else n.res=n.res.concat(r.map(((e,t)=>`${n.path.length>0?n.path:""}[${t}]`)));return n}(e,r,s,{path:"",res:[]}).res},e.version="4.0.6",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ var objectNoNewKeys=(()=>{var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var f=(e,t,s)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,b=(e,t)=>{for(var s in t||(t={}))j.call(t,s)&&f(e,s,t[s]);if(m)for(var s of m(t))v.call(t,s)&&f(e,s,t[s]);return e};var J=e=>d(e,"__esModule",{value:!0});var $=(e,t)=>{for(var s in t)d(e,s,{get:t[s],enumerable:!0})},x=(e,t,s,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of A(t))!j.call(e,n)&&(s||n!=="default")&&d(e,n,{get:()=>t[n],enumerable:!(u=g(t,n))||u.enumerable});return e};var O=(e=>(t,s)=>e&&e.get(t)||(s=x(J({}),t,1),e&&e.set(t,s),s))(typeof WeakMap!="undefined"?new WeakMap:0);var E={};$(E,{noNewKeys:()=>T,version:()=>k});var w="4.0.12";var k=w;function i(e){return e&&typeof e=="object"&&!Array.isArray(e)}function T(e,t,s){if(s&&!i(s))throw new TypeError(`object-no-new-keys/noNewKeys(): [THROW_ID_02] opts should be a plain object. It was given as ${JSON.stringify(s,null,4)} (type ${typeof s})`);let n=b(b({},{mode:2}),s);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 p(a,l,y,o){let c;if(i(a))i(l)?Object.keys(a).forEach(r=>{Object.prototype.hasOwnProperty.call(l,r)?(i(a[r])||Array.isArray(a[r]))&&(c={path:o.path.length>0?`${o.path}.${r}`:r,res:o.res},o.res=p(a[r],l[r],y,c).res):(c=o.path.length>0?`${o.path}.${r}`:r,o.res.push(c))}):o.res=o.res.concat(Object.keys(a).map(r=>o.path.length>0?`${o.path}.${r}`:r));else if(Array.isArray(a))if(Array.isArray(l))for(let r=0,h=a.length;r<h;r++)c={path:`${o.path.length>0?o.path:""}[${r}]`,res:o.res},y.mode===2?o.res=p(a[r],l[0],y,c).res:o.res=p(a[r],l[r],y,c).res;else o.res=o.res.concat(a.map((r,h)=>`${o.path.length>0?o.path:""}[${h}]`));return o}return p(e,t,n,{path:"",res:[]}).res}return O(E);})();
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { noNewKeys } from "../dist/object-no-new-keys.esm.js";
5
6
 
6
7
  assert.deepEqual(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "object-no-new-keys",
3
- "version": "4.0.6",
3
+ "version": "4.0.12",
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,37 @@
35
35
  },
36
36
  "types": "types/index.d.ts",
37
37
  "scripts": {
38
- "build": "rollup -c",
39
- "build:esbuild": "node '../../scripts/esbuild.js'",
40
- "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
41
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
42
- "clean_types": "../../scripts/cleanTypes.js",
43
- "dev": "rollup -c --dev",
44
- "devunittest": "npm run dev && tap --only -R 'base'",
45
- "format": "npm run lect && npm run prettier && npm run lint",
46
- "lect": "lect",
47
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
48
- "perf": "node perf/check",
49
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
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
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
41
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
42
+ "examples": "node '../../ops/scripts/run-examples.js'",
43
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
44
+ "letspublish": "yarn publish || :",
45
+ "lint": "eslint . --fix",
46
+ "perf": "node perf/check.js",
47
+ "prepare": "echo 'ready'",
48
+ "prettier": "prettier",
49
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
50
+ "pretest": "yarn run lect && yarn run build",
51
+ "test": "yarn run devtest",
52
+ "unit": "uvu test"
58
53
  },
59
- "tap": {
60
- "check-coverage": false,
61
- "node-arg": [
62
- "--no-warnings",
63
- "--experimental-loader",
64
- "@istanbuljs/esm-loader-hook"
54
+ "engines": {
55
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
56
+ },
57
+ "c8": {
58
+ "check-coverage": true,
59
+ "exclude": [
60
+ "**/test/**/*.*"
65
61
  ],
66
- "timeout": 0
62
+ "lines": 100
67
63
  },
68
64
  "lect": {
69
65
  "licence": {
70
66
  "extras": [
71
67
  ""
72
68
  ]
73
- },
74
- "req": "{ noNewKeys }",
75
- "various": {
76
- "devDependencies": [
77
- "type-fest"
78
- ]
79
69
  }
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.9",
105
- "@types/tap": "^15.0.5",
106
- "@typescript-eslint/eslint-plugin": "^5.4.0",
107
- "@typescript-eslint/parser": "^5.4.0",
108
- "core-js": "^3.19.1",
109
- "cross-env": "^7.0.3",
110
- "eslint": "^8.3.0",
111
- "lect": "^0.18.6",
112
- "rollup": "^2.60.0",
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.2",
119
- "tslib": "^2.3.1",
120
- "type-fest": "^2.5.4",
121
- "typescript": "^4.5.2"
122
- },
123
- "engines": {
124
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
125
70
  }
126
71
  }
package/types/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  declare const version: string;
2
- declare type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
2
+ declare type JsonValue =
3
+ | string
4
+ | number
5
+ | boolean
6
+ | null
7
+ | JsonObject
8
+ | JsonArray;
3
9
  declare type JsonObject = {
4
- [Key in string]?: JsonValue;
10
+ [Key in string]?: JsonValue;
5
11
  };
6
- declare type JsonArray = Array<JsonValue>;
12
+ declare type JsonArray = JsonValue[];
7
13
  interface Opts {
8
- mode: 1 | 2;
14
+ mode: 1 | 2;
9
15
  }
10
- declare function noNewKeys(inputOuter: JsonValue, referenceOuter: JsonValue, originalOptsOuter?: Opts): any;
16
+ declare function noNewKeys(
17
+ inputOuter: JsonValue,
18
+ referenceOuter: JsonValue,
19
+ originalOptsOuter?: Opts
20
+ ): any;
11
21
 
12
22
  export { noNewKeys, version };
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; noNewKeys &#x7D; from \"object-no-new-keys\";\n\nassert.deepEqual(\n noNewKeys(\n &#x7B;\n a: &#x7B;\n b: \"b\",\n c: \"c\",\n &#x7D;,\n x: \"y\",\n &#x7D;,\n &#x7B;\n a: &#x7B;\n c: \"z\",\n &#x7D;,\n &#x7D;\n ),\n [\"a.b\", \"x\"]\n);"}}