ast-get-values-by-key 4.0.3 → 4.0.7
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/dist/ast-get-values-by-key.esm.js +25 -23
- package/dist/ast-get-values-by-key.umd.js +4 -4
- package/package.json +22 -26
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-get-values-by-key
|
|
3
3
|
* @fileoverview Extract values and paths from AST by keys OR set them by keys
|
|
4
|
-
* @version 4.0.
|
|
4
|
+
* @version 4.0.7
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
@@ -11,32 +11,34 @@ import { traverse } from 'ast-monkey-traverse';
|
|
|
11
11
|
import { isMatch } from 'matcher';
|
|
12
12
|
import clone from 'lodash.clonedeep';
|
|
13
13
|
|
|
14
|
-
var version$1 = "4.0.
|
|
14
|
+
var version$1 = "4.0.7";
|
|
15
15
|
|
|
16
16
|
const version = version$1;
|
|
17
17
|
function getByKey(originalInput, whatToFind, originalReplacement) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const amended = traverse(originalInput, (key, val, innerObj) => {
|
|
24
|
-
const current = val !== undefined ? val : key;
|
|
25
|
-
if (val !== undefined && isMatch(key, whatToFind, {
|
|
26
|
-
caseSensitive: true
|
|
27
|
-
})) {
|
|
28
|
-
if (replacement === undefined) {
|
|
29
|
-
findings.push({
|
|
30
|
-
val,
|
|
31
|
-
path: innerObj.path
|
|
32
|
-
});
|
|
33
|
-
} else if (replacement.length) {
|
|
34
|
-
return replacement.shift();
|
|
35
|
-
}
|
|
18
|
+
let replacement;
|
|
19
|
+
if (originalReplacement !== undefined) {
|
|
20
|
+
replacement = Array.isArray(originalReplacement)
|
|
21
|
+
? clone(originalReplacement)
|
|
22
|
+
: [clone(originalReplacement)];
|
|
36
23
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const findings = [];
|
|
25
|
+
const amended = traverse(originalInput, (key, val, innerObj) => {
|
|
26
|
+
const current = val !== undefined ? val : key;
|
|
27
|
+
if (val !== undefined &&
|
|
28
|
+
isMatch(key, whatToFind, { caseSensitive: true })) {
|
|
29
|
+
if (replacement === undefined) {
|
|
30
|
+
findings.push({
|
|
31
|
+
val,
|
|
32
|
+
path: innerObj.path,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (replacement.length) {
|
|
36
|
+
return replacement.shift();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return current;
|
|
40
|
+
});
|
|
41
|
+
return replacement === undefined ? findings : amended;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export { getByKey, version };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-get-values-by-key
|
|
3
3
|
* @fileoverview Extract values and paths from AST by keys OR set them by keys
|
|
4
|
-
* @version 4.0.
|
|
4
|
+
* @version 4.0.7
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @name ast-monkey-util
|
|
13
13
|
* @fileoverview Utility library of AST helper functions
|
|
14
|
-
* @version 2.0.
|
|
14
|
+
* @version 2.0.7
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ast-monkey-util/}
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* @name ast-monkey-traverse
|
|
21
21
|
* @fileoverview Utility library to traverse AST
|
|
22
|
-
* @version 3.0.
|
|
22
|
+
* @version 3.0.7
|
|
23
23
|
* @author Roy Revelt, Codsen Ltd
|
|
24
24
|
* @license MIT
|
|
25
25
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
26
|
-
*/const h=new Map,d=(t,e)=>{if(!Array.isArray(t))switch(typeof t){case"string":t=[t];break;case"undefined":t=[];break;default:throw new TypeError(`Expected '${e}' to be a string or an array, but got a type of '${typeof t}'`)}return t.filter((t=>{if("string"!=typeof t){if(void 0===t)return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof t}' in the array`)}return!0}))},v=(t,e)=>{e={caseSensitive:!1,...e};const r=t+JSON.stringify(e);if(h.has(r))return h.get(r);const n="!"===t[0];n&&(t=t.slice(1)),t=function(t){if("string"!=typeof t)throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(t).replace(/\\\*/g,"[\\s\\S]*");const o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,h.set(r,o),o};function _(t,e,r){return((t,e,r,n)=>{if(t=d(t,"inputs"),0===(e=d(e,"patterns")).length)return[];e=e.map((t=>v(t,r)));const{allPatterns:o}=r||{},c=[];for(const r of t){let t;const a=[...e].fill(!1);for(const[n,o]of e.entries())if(o.test(r)&&(a[n]=!0,t=!o.negated,!t))break;if(!(!1===t||void 0===t&&e.some((t=>!t.negated))||o&&a.some(((t,r)=>!t&&!e[r].negated)))&&(c.push(r),n))break}return c})(t,e,r,!0).length>0}t.getByKey=function(t,e,r){let o;void 0!==r&&(o=Array.isArray(r)?n(r):[n(r)]);const c=[],a=function t(e,r,o,c){const a=n(e);let i;const u={depth:-1,path:"",...o};if(u.depth+=1,Array.isArray(a))for(let e=0,o=a.length;e<o&&!c.now;e++){const o=u.path?`${u.path}.${e}`:`${e}`;void 0!==a[e]?(u.parent=n(a),u.parentType="array",u.parentKey=y(o),i=t(r(a[e],void 0,{...u,path:o},c),r,{...u,path:o},c),Number.isNaN(i)&&e<a.length?(a.splice(e,1),e-=1):a[e]=i):a.splice(e,1)}else if(p(a))for(const e in a){if(c.now&&null!=e)break;const o=u.path?`${u.path}.${e}`:e;0===u.depth&&null!=e&&(u.topmostKey=e),u.parent=n(a),u.parentType="object",u.parentKey=y(o),i=t(r(e,a[e],{...u,path:o},c),r,{...u,path:o},c),Number.isNaN(i)?delete a[e]:a[e]=i}return a}(t,((t,r,n)=>{const a=void 0!==r?r:t;if(void 0!==r&&_(t,e,{caseSensitive:!0}))if(void 0===o)c.push({val:r,path:n.path});else if(o.length)return o.shift();return a}),{},{now:!1});return void 0===o?c:a},t.version="4.0.
|
|
26
|
+
*/const h=new Map,d=(t,e)=>{if(!Array.isArray(t))switch(typeof t){case"string":t=[t];break;case"undefined":t=[];break;default:throw new TypeError(`Expected '${e}' to be a string or an array, but got a type of '${typeof t}'`)}return t.filter((t=>{if("string"!=typeof t){if(void 0===t)return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof t}' in the array`)}return!0}))},v=(t,e)=>{e={caseSensitive:!1,...e};const r=t+JSON.stringify(e);if(h.has(r))return h.get(r);const n="!"===t[0];n&&(t=t.slice(1)),t=function(t){if("string"!=typeof t)throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(t).replace(/\\\*/g,"[\\s\\S]*");const o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,h.set(r,o),o};function _(t,e,r){return((t,e,r,n)=>{if(t=d(t,"inputs"),0===(e=d(e,"patterns")).length)return[];e=e.map((t=>v(t,r)));const{allPatterns:o}=r||{},c=[];for(const r of t){let t;const a=[...e].fill(!1);for(const[n,o]of e.entries())if(o.test(r)&&(a[n]=!0,t=!o.negated,!t))break;if(!(!1===t||void 0===t&&e.some((t=>!t.negated))||o&&a.some(((t,r)=>!t&&!e[r].negated)))&&(c.push(r),n))break}return c})(t,e,r,!0).length>0}t.getByKey=function(t,e,r){let o;void 0!==r&&(o=Array.isArray(r)?n(r):[n(r)]);const c=[],a=function t(e,r,o,c){const a=n(e);let i;const u={depth:-1,path:"",...o};if(u.depth+=1,Array.isArray(a))for(let e=0,o=a.length;e<o&&!c.now;e++){const o=u.path?`${u.path}.${e}`:`${e}`;void 0!==a[e]?(u.parent=n(a),u.parentType="array",u.parentKey=y(o),i=t(r(a[e],void 0,{...u,path:o},c),r,{...u,path:o},c),Number.isNaN(i)&&e<a.length?(a.splice(e,1),e-=1):a[e]=i):a.splice(e,1)}else if(p(a))for(const e in a){if(c.now&&null!=e)break;const o=u.path?`${u.path}.${e}`:e;0===u.depth&&null!=e&&(u.topmostKey=e),u.parent=n(a),u.parentType="object",u.parentKey=y(o),i=t(r(e,a[e],{...u,path:o},c),r,{...u,path:o},c),Number.isNaN(i)?delete a[e]:a[e]=i}return a}(t,((t,r,n)=>{const a=void 0!==r?r:t;if(void 0!==r&&_(t,e,{caseSensitive:!0}))if(void 0===o)c.push({val:r,path:n.path});else if(o.length)return o.shift();return a}),{},{now:!1});return void 0===o?c:a},t.version="4.0.7",Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ast-get-values-by-key",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.7",
|
|
4
4
|
"description": "Extract values and paths from AST by keys OR set them by keys",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -44,13 +44,12 @@
|
|
|
44
44
|
"types": "types/index.d.ts",
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "rollup -c",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
48
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
49
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
49
50
|
"clean_types": "../../scripts/cleanTypes.js",
|
|
50
51
|
"dev": "rollup -c --dev",
|
|
51
52
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
52
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
53
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
54
53
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
55
54
|
"lect": "lect",
|
|
56
55
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -59,17 +58,14 @@
|
|
|
59
58
|
"republish": "npm publish || :",
|
|
60
59
|
"tap": "tap",
|
|
61
60
|
"pretest": "npm run build",
|
|
62
|
-
"test": "npm run
|
|
61
|
+
"test": "npm run test:ci && npm run perf",
|
|
62
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
63
63
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
64
64
|
"tsc": "tsc",
|
|
65
|
-
"unittest": "tap --no-only --
|
|
65
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
66
66
|
},
|
|
67
67
|
"tap": {
|
|
68
68
|
"check-coverage": false,
|
|
69
|
-
"coverage-report": [
|
|
70
|
-
"json-summary",
|
|
71
|
-
"text"
|
|
72
|
-
],
|
|
73
69
|
"node-arg": [
|
|
74
70
|
"--no-warnings",
|
|
75
71
|
"--experimental-loader",
|
|
@@ -92,8 +88,8 @@
|
|
|
92
88
|
}
|
|
93
89
|
},
|
|
94
90
|
"dependencies": {
|
|
95
|
-
"@babel/runtime": "^7.16.
|
|
96
|
-
"ast-monkey-traverse": "^3.0.
|
|
91
|
+
"@babel/runtime": "^7.16.3",
|
|
92
|
+
"ast-monkey-traverse": "^3.0.7",
|
|
97
93
|
"lodash.clonedeep": "^4.5.0",
|
|
98
94
|
"matcher": "^5.0.0"
|
|
99
95
|
},
|
|
@@ -106,8 +102,8 @@
|
|
|
106
102
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
107
103
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
108
104
|
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
109
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
110
|
-
"@babel/preset-env": "^7.16.
|
|
105
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
106
|
+
"@babel/preset-env": "^7.16.4",
|
|
111
107
|
"@babel/preset-typescript": "^7.16.0",
|
|
112
108
|
"@babel/register": "^7.16.0",
|
|
113
109
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
@@ -118,26 +114,26 @@
|
|
|
118
114
|
"@rollup/plugin-strip": "^2.1.0",
|
|
119
115
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
120
116
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
121
|
-
"@types/node": "^16.11.
|
|
117
|
+
"@types/node": "^16.11.10",
|
|
122
118
|
"@types/tap": "^15.0.5",
|
|
123
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
124
|
-
"@typescript-eslint/parser": "^5.
|
|
125
|
-
"core-js": "^3.19.
|
|
119
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
120
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
121
|
+
"core-js": "^3.19.2",
|
|
126
122
|
"cross-env": "^7.0.3",
|
|
127
|
-
"eslint": "^8.
|
|
128
|
-
"lect": "^0.18.
|
|
123
|
+
"eslint": "^8.3.0",
|
|
124
|
+
"lect": "^0.18.7",
|
|
129
125
|
"object-path": "^0.11.8",
|
|
130
|
-
"rollup": "^2.
|
|
126
|
+
"rollup": "^2.60.1",
|
|
131
127
|
"rollup-plugin-ascii": "^0.0.3",
|
|
132
128
|
"rollup-plugin-banner": "^0.2.1",
|
|
133
129
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
134
|
-
"rollup-plugin-dts": "^4.0.
|
|
130
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
135
131
|
"rollup-plugin-terser": "^7.0.2",
|
|
136
|
-
"tap": "^15.
|
|
132
|
+
"tap": "^15.1.5",
|
|
137
133
|
"tslib": "^2.3.1",
|
|
138
|
-
"typescript": "^4.
|
|
134
|
+
"typescript": "^4.5.2"
|
|
139
135
|
},
|
|
140
136
|
"engines": {
|
|
141
|
-
"node": ">=
|
|
137
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
142
138
|
}
|
|
143
139
|
}
|