ast-get-values-by-key 4.1.3 → 4.1.5
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 +3 -3
- package/README.md +13 -16
- package/dist/ast-get-values-by-key.esm.js +2 -2
- package/dist/ast-get-values-by-key.umd.js +4 -4
- package/package.json +3 -3
- package/examples/_quickTake.js +0 -59
- package/examples/real-use.js +0 -66
- package/examples/wildcards.js +0 -47
package/CHANGELOG.md
CHANGED
|
@@ -17,7 +17,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
17
17
|
|
|
18
18
|
### BREAKING CHANGES
|
|
19
19
|
|
|
20
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
20
|
+
- programs now are in ES Modules and won't work with Common JS `require()`
|
|
21
21
|
|
|
22
22
|
## 3.1.0 (2021-05-24)
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
35
35
|
|
|
36
36
|
### Fixed
|
|
37
37
|
|
|
38
|
-
- add testStats to npmignore ([f3c84e9](https://github.com/codsen/codsen/commit/f3c84e95afc5514214312f913692d85b2e12eb29))
|
|
38
|
+
- add `testStats` to npmignore ([f3c84e9](https://github.com/codsen/codsen/commit/f3c84e95afc5514214312f913692d85b2e12eb29))
|
|
39
39
|
|
|
40
40
|
## 3.0.0 (2021-01-23)
|
|
41
41
|
|
|
@@ -49,7 +49,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
49
49
|
|
|
50
50
|
## 2.8.0 (2020-11-28)
|
|
51
51
|
|
|
52
|
-
Accidental version bump during migration to
|
|
52
|
+
Accidental version bump during migration to SourceHut. Sorry about that.
|
|
53
53
|
|
|
54
54
|
## 2.7.0 (2020-09-27)
|
|
55
55
|
|
package/README.md
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">ast-get-values-by-key</h1>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
<p align="center">Extract values and paths from AST by keys OR set them by keys</p>
|
|
4
4
|
|
|
5
|
-
<
|
|
6
|
-
<a href="https://www.npmjs.com/package/ast-get-values-by-key" rel="nofollow noreferrer noopener">
|
|
7
|
-
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
|
|
8
|
-
</a>
|
|
5
|
+
<p align="center">
|
|
9
6
|
<a href="https://codsen.com/os/ast-get-values-by-key" rel="nofollow noreferrer noopener">
|
|
10
7
|
<img src="https://img.shields.io/badge/-codsen-blue?style=flat-square" alt="page on codsen.com">
|
|
11
8
|
</a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/ast-get-values-by-key" rel="nofollow noreferrer noopener">
|
|
10
|
+
<img src="https://img.shields.io/badge/-npm-blue?style=flat-square" alt="page on npm">
|
|
11
|
+
</a>
|
|
12
12
|
<a href="https://github.com/codsen/codsen/tree/main/packages/ast-get-values-by-key" rel="nofollow noreferrer noopener">
|
|
13
13
|
<img src="https://img.shields.io/badge/-github-blue?style=flat-square" alt="page on github">
|
|
14
14
|
</a>
|
|
15
15
|
<a href="https://npmcharts.com/compare/ast-get-values-by-key?interval=30" rel="nofollow noreferrer noopener" target="_blank">
|
|
16
16
|
<img src="https://img.shields.io/npm/dm/ast-get-values-by-key.svg?style=flat-square" alt="Downloads per month">
|
|
17
17
|
</a>
|
|
18
|
-
<a href="https://
|
|
19
|
-
<img src="https://img.shields.io/badge/
|
|
20
|
-
</a>
|
|
21
|
-
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT License">
|
|
22
|
-
<a href="https://liberamanifesto.com" rel="nofollow noreferrer noopener" target="_blank">
|
|
23
|
-
<img src="https://img.shields.io/badge/libera-manifesto-lightgrey.svg?style=flat-square" alt="libera manifesto">
|
|
18
|
+
<a href="https://codsen.com/os/ast-get-values-by-key/changelog" rel="nofollow noreferrer noopener">
|
|
19
|
+
<img src="https://img.shields.io/badge/changelog-here-brightgreen?style=flat-square" alt="changelog">
|
|
24
20
|
</a>
|
|
25
|
-
|
|
21
|
+
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT Licence">
|
|
22
|
+
</p>
|
|
26
23
|
|
|
27
24
|
## Install
|
|
28
25
|
|
|
@@ -104,8 +101,8 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
104
101
|
|
|
105
102
|
## Licence
|
|
106
103
|
|
|
107
|
-
MIT License
|
|
104
|
+
MIT License.
|
|
108
105
|
|
|
109
|
-
Copyright
|
|
106
|
+
Copyright © 2010-2022 Roy Revelt and other contributors.
|
|
110
107
|
|
|
111
|
-
<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">
|
|
108
|
+
<p align="center"><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"></p>
|
|
@@ -1,10 +1,10 @@
|
|
|
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.1.
|
|
4
|
+
* @version 4.1.5
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import{traverse as y}from"ast-monkey-traverse";import{isMatch as m}from"matcher";import d from"lodash.clonedeep";var i="4.1.
|
|
10
|
+
import{traverse as y}from"ast-monkey-traverse";import{isMatch as m}from"matcher";import d from"lodash.clonedeep";var i="4.1.5";var b=i;function k(o,a,t){let e;t!==void 0&&(e=Array.isArray(t)?d(t):[d(t)]);let r=[],p=y(o,(n,s,u)=>{let c=s!==void 0?s:n;if(s!==void 0&&m(n,a,{caseSensitive:!0})){if(e===void 0)r.push({val:s,path:u.path});else if(e.length)return e.shift()}return c});return e===void 0?r:p}export{k as getByKey,b as version};
|
|
@@ -1,17 +1,17 @@
|
|
|
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.1.
|
|
4
|
+
* @version 4.1.5
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-get-values-by-key/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";var astGetValuesByKey=(()=>{var ce=Object.create;var T=Object.defineProperty,ue=Object.defineProperties,fe=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertyNames,st=Object.getOwnPropertySymbols,de=Object.getPrototypeOf,ut=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var ct=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,y=(t,e)=>{for(var r in e||(e={}))ut.call(e,r)&&ct(t,r,e[r]);if(st)for(var r of st(e))he.call(e,r)&&ct(t,r,e[r]);return t},A=(t,e)=>ue(t,le(e));var ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ge=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},lt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pe(e))!ut.call(t,o)&&o!==r&&T(t,o,{get:()=>e[o],enumerable:!(n=fe(e,o))||n.enumerable});return t};var G=(t,e,r)=>(r=t!=null?ce(de(t)):{},lt(e||!t||!t.__esModule?T(r,"default",{value:t,enumerable:!0}):r,t)),ye=t=>lt(T({},"__esModule",{value:!0}),t);var rt=ft((C,w)=>{var be=200,jt="__lodash_hash_undefined__",Ot=9007199254740991,X="[object Arguments]",_e="[object Array]",St="[object Boolean]",Tt="[object Date]",me="[object Error]",Y="[object Function]",At="[object GeneratorFunction]",P="[object Map]",Ct="[object Number]",Z="[object Object]",pt="[object Promise]",Et="[object RegExp]",M="[object Set]",$t="[object String]",It="[object Symbol]",L="[object WeakMap]",Pt="[object ArrayBuffer]",R="[object DataView]",Mt="[object Float32Array]",Rt="[object Float64Array]",Nt="[object Int8Array]",kt="[object Int16Array]",Ft="[object Int32Array]",Kt="[object Uint8Array]",Bt="[object Uint8ClampedArray]",Dt="[object Uint16Array]",Gt="[object Uint32Array]",ve=/[\\^$.*+?()[\]{}|]/g,xe=/\w*$/,we=/^\[object .+?Constructor\]$/,je=/^(?:0|[1-9]\d*)$/,i={};i[X]=i[_e]=i[Pt]=i[R]=i[St]=i[Tt]=i[Mt]=i[Rt]=i[Nt]=i[kt]=i[Ft]=i[P]=i[Ct]=i[Z]=i[Et]=i[M]=i[$t]=i[It]=i[Kt]=i[Bt]=i[Dt]=i[Gt]=!0;i[me]=i[Y]=i[L]=!1;var Oe=typeof global=="object"&&global&&global.Object===Object&&global,Se=typeof self=="object"&&self&&self.Object===Object&&self,d=Oe||Se||Function("return this")(),Ht=typeof C=="object"&&C&&!C.nodeType&&C,dt=Ht&&typeof w=="object"&&w&&!w.nodeType&&w,Te=dt&&dt.exports===Ht;function Ae(t,e){return t.set(e[0],e[1]),t}function Ce(t,e){return t.add(e),t}function Ee(t,e){for(var r=-1,n=t?t.length:0;++r<n&&e(t[r],r,t)!==!1;);return t}function $e(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function Lt(t,e,r,n){var o=-1,s=t?t.length:0;for(n&&s&&(r=t[++o]);++o<s;)r=e(r,t[o],o,t);return r}function Ie(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}function Pe(t,e){return t==null?void 0:t[e]}function Ut(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function ht(t){var e=-1,r=Array(t.size);return t.forEach(function(n,o){r[++e]=[o,n]}),r}function Q(t,e){return function(r){return t(e(r))}}function gt(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var Me=Array.prototype,Re=Function.prototype,N=Object.prototype,H=d["__core-js_shared__"],yt=function(){var t=/[^.]+$/.exec(H&&H.keys&&H.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Vt=Re.toString,b=N.hasOwnProperty,k=N.toString,Ne=RegExp("^"+Vt.call(b).replace(ve,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),bt=Te?d.Buffer:void 0,_t=d.Symbol,mt=d.Uint8Array,ke=Q(Object.getPrototypeOf,Object),Fe=Object.create,Ke=N.propertyIsEnumerable,Be=Me.splice,vt=Object.getOwnPropertySymbols,De=bt?bt.isBuffer:void 0,Ge=Q(Object.keys,Object),U=S(d,"DataView"),E=S(d,"Map"),V=S(d,"Promise"),W=S(d,"Set"),J=S(d,"WeakMap"),$=S(Object,"create"),He=x(U),Le=x(E),Ue=x(V),Ve=x(W),We=x(J),xt=_t?_t.prototype:void 0,wt=xt?xt.valueOf:void 0;function v(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Je(){this.__data__=$?$(null):{}}function qe(t){return this.has(t)&&delete this.__data__[t]}function Xe(t){var e=this.__data__;if($){var r=e[t];return r===jt?void 0:r}return b.call(e,t)?e[t]:void 0}function Ye(t){var e=this.__data__;return $?e[t]!==void 0:b.call(e,t)}function Ze(t,e){var r=this.__data__;return r[t]=$&&e===void 0?jt:e,this}v.prototype.clear=Je;v.prototype.delete=qe;v.prototype.get=Xe;v.prototype.has=Ye;v.prototype.set=Ze;function h(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Qe(){this.__data__=[]}function ze(t){var e=this.__data__,r=F(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():Be.call(e,r,1),!0}function tr(t){var e=this.__data__,r=F(e,t);return r<0?void 0:e[r][1]}function er(t){return F(this.__data__,t)>-1}function rr(t,e){var r=this.__data__,n=F(r,t);return n<0?r.push([t,e]):r[n][1]=e,this}h.prototype.clear=Qe;h.prototype.delete=ze;h.prototype.get=tr;h.prototype.has=er;h.prototype.set=rr;function j(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function nr(){this.__data__={hash:new v,map:new(E||h),string:new v}}function or(t){return K(this,t).delete(t)}function ar(t){return K(this,t).get(t)}function ir(t){return K(this,t).has(t)}function sr(t,e){return K(this,t).set(t,e),this}j.prototype.clear=nr;j.prototype.delete=or;j.prototype.get=ar;j.prototype.has=ir;j.prototype.set=sr;function O(t){this.__data__=new h(t)}function cr(){this.__data__=new h}function ur(t){return this.__data__.delete(t)}function fr(t){return this.__data__.get(t)}function lr(t){return this.__data__.has(t)}function pr(t,e){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!E||n.length<be-1)return n.push([t,e]),this;r=this.__data__=new j(n)}return r.set(t,e),this}O.prototype.clear=cr;O.prototype.delete=ur;O.prototype.get=fr;O.prototype.has=lr;O.prototype.set=pr;function dr(t,e){var r=tt(t)||Fr(t)?Ie(t.length,String):[],n=r.length,o=!!n;for(var s in t)(e||b.call(t,s))&&!(o&&(s=="length"||Mr(s,n)))&&r.push(s);return r}function Wt(t,e,r){var n=t[e];(!(b.call(t,e)&&Yt(n,r))||r===void 0&&!(e in t))&&(t[e]=r)}function F(t,e){for(var r=t.length;r--;)if(Yt(t[r][0],e))return r;return-1}function hr(t,e){return t&&Jt(e,et(e),t)}function q(t,e,r,n,o,s,l){var a;if(n&&(a=s?n(t,o,s,l):n(t)),a!==void 0)return a;if(!B(t))return t;var u=tt(t);if(u){if(a=$r(t),!e)return Ar(t,a)}else{var p=m(t),c=p==Y||p==At;if(Br(t))return vr(t,e);if(p==Z||p==X||c&&!s){if(Ut(t))return s?t:{};if(a=Ir(c?{}:t),!e)return Cr(t,hr(a,t))}else{if(!i[p])return s?t:{};a=Pr(t,p,q,e)}}l||(l=new O);var f=l.get(t);if(f)return f;if(l.set(t,a),!u)var g=r?Er(t):et(t);return Ee(g||t,function(_,I){g&&(I=_,_=t[I]),Wt(a,I,q(_,e,r,n,I,t,l))}),a}function gr(t){return B(t)?Fe(t):{}}function yr(t,e,r){var n=e(t);return tt(t)?n:$e(n,r(t))}function br(t){return k.call(t)}function _r(t){if(!B(t)||Nr(t))return!1;var e=Qt(t)||Ut(t)?Ne:we;return e.test(x(t))}function mr(t){if(!Xt(t))return Ge(t);var e=[];for(var r in Object(t))b.call(t,r)&&r!="constructor"&&e.push(r);return e}function vr(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}function z(t){var e=new t.constructor(t.byteLength);return new mt(e).set(new mt(t)),e}function xr(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}function wr(t,e,r){var n=e?r(ht(t),!0):ht(t);return Lt(n,Ae,new t.constructor)}function jr(t){var e=new t.constructor(t.source,xe.exec(t));return e.lastIndex=t.lastIndex,e}function Or(t,e,r){var n=e?r(gt(t),!0):gt(t);return Lt(n,Ce,new t.constructor)}function Sr(t){return wt?Object(wt.call(t)):{}}function Tr(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function Ar(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}function Jt(t,e,r,n){r||(r={});for(var o=-1,s=e.length;++o<s;){var l=e[o],a=n?n(r[l],t[l],l,r,t):void 0;Wt(r,l,a===void 0?t[l]:a)}return r}function Cr(t,e){return Jt(t,qt(t),e)}function Er(t){return yr(t,et,qt)}function K(t,e){var r=t.__data__;return Rr(e)?r[typeof e=="string"?"string":"hash"]:r.map}function S(t,e){var r=Pe(t,e);return _r(r)?r:void 0}var qt=vt?Q(vt,Object):Hr,m=br;(U&&m(new U(new ArrayBuffer(1)))!=R||E&&m(new E)!=P||V&&m(V.resolve())!=pt||W&&m(new W)!=M||J&&m(new J)!=L)&&(m=function(t){var e=k.call(t),r=e==Z?t.constructor:void 0,n=r?x(r):void 0;if(n)switch(n){case He:return R;case Le:return P;case Ue:return pt;case Ve:return M;case We:return L}return e});function $r(t){var e=t.length,r=t.constructor(e);return e&&typeof t[0]=="string"&&b.call(t,"index")&&(r.index=t.index,r.input=t.input),r}function Ir(t){return typeof t.constructor=="function"&&!Xt(t)?gr(ke(t)):{}}function Pr(t,e,r,n){var o=t.constructor;switch(e){case Pt:return z(t);case St:case Tt:return new o(+t);case R:return xr(t,n);case Mt:case Rt:case Nt:case kt:case Ft:case Kt:case Bt:case Dt:case Gt:return Tr(t,n);case P:return wr(t,n,r);case Ct:case $t:return new o(t);case Et:return jr(t);case M:return Or(t,n,r);case It:return Sr(t)}}function Mr(t,e){return e=e==null?Ot:e,!!e&&(typeof t=="number"||je.test(t))&&t>-1&&t%1==0&&t<e}function Rr(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Nr(t){return!!yt&&yt in t}function Xt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||N;return t===r}function x(t){if(t!=null){try{return Vt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function kr(t){return q(t,!0,!0)}function Yt(t,e){return t===e||t!==t&&e!==e}function Fr(t){return Kr(t)&&b.call(t,"callee")&&(!Ke.call(t,"callee")||k.call(t)==X)}var tt=Array.isArray;function Zt(t){return t!=null&&Dr(t.length)&&!Qt(t)}function Kr(t){return Gr(t)&&Zt(t)}var Br=De||Lr;function Qt(t){var e=B(t)?k.call(t):"";return e==Y||e==At}function Dr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Ot}function B(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Gr(t){return!!t&&typeof t=="object"}function et(t){return Zt(t)?dr(t):mr(t)}function Hr(){return[]}function Lr(){return!1}w.exports=kr});var re=ft((un,ee)=>{var Ur="[object Object]";function Vr(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function Wr(t,e){return function(r){return t(e(r))}}var Jr=Function.prototype,zt=Object.prototype,te=Jr.toString,qr=zt.hasOwnProperty,Xr=te.call(Object),Yr=zt.toString,Zr=Wr(Object.getPrototypeOf,Object);function Qr(t){return!!t&&typeof t=="object"}function zr(t){if(!Qr(t)||Yr.call(t)!=Ur||Vr(t))return!1;var e=Zr(t);if(e===null)return!0;var r=qr.call(e,"constructor")&&e.constructor;return typeof r=="function"&&r instanceof r&&te.call(r)==Xr}ee.exports=zr});var sn={};ge(sn,{getByKey:()=>an,version:()=>on});var D=G(rt(),1),ne=G(re(),1);function tn(t){if(t.includes(".")){let e=t.lastIndexOf(".");if(!t.slice(0,e).includes("."))return t.slice(0,e);for(let r=e-1;r--;)if(t[r]===".")return t.slice(r+1,e)}return null}var nt=tn;function oe(t,e){let r={now:!1};function n(o,s,l,a){let u=(0,D.default)(o),p,c=y({depth:-1,path:""},l);if(c.depth+=1,Array.isArray(u))for(let f=0,g=u.length;f<g&&!a.now;f++){let _=c.path?`${c.path}.${f}`:`${f}`;u[f]!==void 0?(c.parent=(0,D.default)(u),c.parentType="array",c.parentKey=nt(_),p=n(s(u[f],void 0,A(y({},c),{path:_}),a),s,A(y({},c),{path:_}),a),Number.isNaN(p)&&f<u.length?(u.splice(f,1),f-=1):u[f]=p):u.splice(f,1)}else if((0,ne.default)(u))for(let f in u){if(a.now&&f!=null)break;let g=c.path?`${c.path}.${f}`:f;c.depth===0&&f!=null&&(c.topmostKey=f),c.parent=(0,D.default)(u),c.parentType="object",c.parentKey=nt(g),p=n(s(f,u[f],A(y({},c),{path:g}),a),s,A(y({},c),{path:g}),a),Number.isNaN(p)?delete u[f]:u[f]=p}return u}return n(t,e,{},r)}function ot(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var at=new Map,ae=(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(r=>{if(typeof r!="string"){if(typeof r>"u")return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof r}' in the array`)}return!0})},en=(t,e)=>{e=y({caseSensitive:!1},e);let r=t+JSON.stringify(e);if(at.has(r))return at.get(r);let n=t[0]==="!";n&&(t=t.slice(1)),t=ot(t).replace(/\\\*/g,"[\\s\\S]*");let o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,at.set(r,o),o},rn=(t,e,r,n)=>{if(t=ae(t,"inputs"),e=ae(e,"patterns"),e.length===0)return[];e=e.map(l=>en(l,r));let{allPatterns:o}=r||{},s=[];for(let l of t){let a,u=[...e].fill(!1);for(let[p,c]of e.entries())if(c.test(l)&&(u[p]=!0,a=!c.negated,!a))break;if(!(a===!1||a===void 0&&e.some(p=>!p.negated)||o&&u.some((p,c)=>!p&&!e[c].negated))&&(s.push(l),n))break}return s};function ie(t,e,r){return rn(t,e,r,!0).length>0}var it=G(rt(),1);var se="4.1.3";var on=se;function an(t,e,r){let n;r!==void 0&&(n=Array.isArray(r)?(0,it.default)(r):[(0,it.default)(r)]);let o=[],s=oe(t,(l,a,u)=>{let p=a!==void 0?a:l;if(a!==void 0&&ie(l,e,{caseSensitive:!0})){if(n===void 0)o.push({val:a,path:u.path});else if(n.length)return n.shift()}return p});return n===void 0?o:s}return ye(sn);})();
|
|
10
|
+
"use strict";var astGetValuesByKey=(()=>{var ce=Object.create;var T=Object.defineProperty,ue=Object.defineProperties,fe=Object.getOwnPropertyDescriptor,le=Object.getOwnPropertyDescriptors,pe=Object.getOwnPropertyNames,st=Object.getOwnPropertySymbols,de=Object.getPrototypeOf,ut=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var ct=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,y=(t,e)=>{for(var r in e||(e={}))ut.call(e,r)&&ct(t,r,e[r]);if(st)for(var r of st(e))he.call(e,r)&&ct(t,r,e[r]);return t},A=(t,e)=>ue(t,le(e));var ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ge=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},lt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pe(e))!ut.call(t,o)&&o!==r&&T(t,o,{get:()=>e[o],enumerable:!(n=fe(e,o))||n.enumerable});return t};var G=(t,e,r)=>(r=t!=null?ce(de(t)):{},lt(e||!t||!t.__esModule?T(r,"default",{value:t,enumerable:!0}):r,t)),ye=t=>lt(T({},"__esModule",{value:!0}),t);var rt=ft((C,w)=>{var be=200,jt="__lodash_hash_undefined__",Ot=9007199254740991,X="[object Arguments]",_e="[object Array]",St="[object Boolean]",Tt="[object Date]",me="[object Error]",Y="[object Function]",At="[object GeneratorFunction]",P="[object Map]",Ct="[object Number]",Z="[object Object]",pt="[object Promise]",Et="[object RegExp]",M="[object Set]",$t="[object String]",It="[object Symbol]",L="[object WeakMap]",Pt="[object ArrayBuffer]",R="[object DataView]",Mt="[object Float32Array]",Rt="[object Float64Array]",Nt="[object Int8Array]",kt="[object Int16Array]",Ft="[object Int32Array]",Kt="[object Uint8Array]",Bt="[object Uint8ClampedArray]",Dt="[object Uint16Array]",Gt="[object Uint32Array]",ve=/[\\^$.*+?()[\]{}|]/g,xe=/\w*$/,we=/^\[object .+?Constructor\]$/,je=/^(?:0|[1-9]\d*)$/,i={};i[X]=i[_e]=i[Pt]=i[R]=i[St]=i[Tt]=i[Mt]=i[Rt]=i[Nt]=i[kt]=i[Ft]=i[P]=i[Ct]=i[Z]=i[Et]=i[M]=i[$t]=i[It]=i[Kt]=i[Bt]=i[Dt]=i[Gt]=!0;i[me]=i[Y]=i[L]=!1;var Oe=typeof global=="object"&&global&&global.Object===Object&&global,Se=typeof self=="object"&&self&&self.Object===Object&&self,d=Oe||Se||Function("return this")(),Ht=typeof C=="object"&&C&&!C.nodeType&&C,dt=Ht&&typeof w=="object"&&w&&!w.nodeType&&w,Te=dt&&dt.exports===Ht;function Ae(t,e){return t.set(e[0],e[1]),t}function Ce(t,e){return t.add(e),t}function Ee(t,e){for(var r=-1,n=t?t.length:0;++r<n&&e(t[r],r,t)!==!1;);return t}function $e(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function Lt(t,e,r,n){var o=-1,s=t?t.length:0;for(n&&s&&(r=t[++o]);++o<s;)r=e(r,t[o],o,t);return r}function Ie(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}function Pe(t,e){return t==null?void 0:t[e]}function Ut(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function ht(t){var e=-1,r=Array(t.size);return t.forEach(function(n,o){r[++e]=[o,n]}),r}function Q(t,e){return function(r){return t(e(r))}}function gt(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var Me=Array.prototype,Re=Function.prototype,N=Object.prototype,H=d["__core-js_shared__"],yt=function(){var t=/[^.]+$/.exec(H&&H.keys&&H.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Vt=Re.toString,b=N.hasOwnProperty,k=N.toString,Ne=RegExp("^"+Vt.call(b).replace(ve,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),bt=Te?d.Buffer:void 0,_t=d.Symbol,mt=d.Uint8Array,ke=Q(Object.getPrototypeOf,Object),Fe=Object.create,Ke=N.propertyIsEnumerable,Be=Me.splice,vt=Object.getOwnPropertySymbols,De=bt?bt.isBuffer:void 0,Ge=Q(Object.keys,Object),U=S(d,"DataView"),E=S(d,"Map"),V=S(d,"Promise"),W=S(d,"Set"),J=S(d,"WeakMap"),$=S(Object,"create"),He=x(U),Le=x(E),Ue=x(V),Ve=x(W),We=x(J),xt=_t?_t.prototype:void 0,wt=xt?xt.valueOf:void 0;function v(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Je(){this.__data__=$?$(null):{}}function qe(t){return this.has(t)&&delete this.__data__[t]}function Xe(t){var e=this.__data__;if($){var r=e[t];return r===jt?void 0:r}return b.call(e,t)?e[t]:void 0}function Ye(t){var e=this.__data__;return $?e[t]!==void 0:b.call(e,t)}function Ze(t,e){var r=this.__data__;return r[t]=$&&e===void 0?jt:e,this}v.prototype.clear=Je;v.prototype.delete=qe;v.prototype.get=Xe;v.prototype.has=Ye;v.prototype.set=Ze;function h(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Qe(){this.__data__=[]}function ze(t){var e=this.__data__,r=F(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():Be.call(e,r,1),!0}function tr(t){var e=this.__data__,r=F(e,t);return r<0?void 0:e[r][1]}function er(t){return F(this.__data__,t)>-1}function rr(t,e){var r=this.__data__,n=F(r,t);return n<0?r.push([t,e]):r[n][1]=e,this}h.prototype.clear=Qe;h.prototype.delete=ze;h.prototype.get=tr;h.prototype.has=er;h.prototype.set=rr;function j(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function nr(){this.__data__={hash:new v,map:new(E||h),string:new v}}function or(t){return K(this,t).delete(t)}function ar(t){return K(this,t).get(t)}function ir(t){return K(this,t).has(t)}function sr(t,e){return K(this,t).set(t,e),this}j.prototype.clear=nr;j.prototype.delete=or;j.prototype.get=ar;j.prototype.has=ir;j.prototype.set=sr;function O(t){this.__data__=new h(t)}function cr(){this.__data__=new h}function ur(t){return this.__data__.delete(t)}function fr(t){return this.__data__.get(t)}function lr(t){return this.__data__.has(t)}function pr(t,e){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!E||n.length<be-1)return n.push([t,e]),this;r=this.__data__=new j(n)}return r.set(t,e),this}O.prototype.clear=cr;O.prototype.delete=ur;O.prototype.get=fr;O.prototype.has=lr;O.prototype.set=pr;function dr(t,e){var r=tt(t)||Fr(t)?Ie(t.length,String):[],n=r.length,o=!!n;for(var s in t)(e||b.call(t,s))&&!(o&&(s=="length"||Mr(s,n)))&&r.push(s);return r}function Wt(t,e,r){var n=t[e];(!(b.call(t,e)&&Yt(n,r))||r===void 0&&!(e in t))&&(t[e]=r)}function F(t,e){for(var r=t.length;r--;)if(Yt(t[r][0],e))return r;return-1}function hr(t,e){return t&&Jt(e,et(e),t)}function q(t,e,r,n,o,s,l){var a;if(n&&(a=s?n(t,o,s,l):n(t)),a!==void 0)return a;if(!B(t))return t;var u=tt(t);if(u){if(a=$r(t),!e)return Ar(t,a)}else{var p=m(t),c=p==Y||p==At;if(Br(t))return vr(t,e);if(p==Z||p==X||c&&!s){if(Ut(t))return s?t:{};if(a=Ir(c?{}:t),!e)return Cr(t,hr(a,t))}else{if(!i[p])return s?t:{};a=Pr(t,p,q,e)}}l||(l=new O);var f=l.get(t);if(f)return f;if(l.set(t,a),!u)var g=r?Er(t):et(t);return Ee(g||t,function(_,I){g&&(I=_,_=t[I]),Wt(a,I,q(_,e,r,n,I,t,l))}),a}function gr(t){return B(t)?Fe(t):{}}function yr(t,e,r){var n=e(t);return tt(t)?n:$e(n,r(t))}function br(t){return k.call(t)}function _r(t){if(!B(t)||Nr(t))return!1;var e=Qt(t)||Ut(t)?Ne:we;return e.test(x(t))}function mr(t){if(!Xt(t))return Ge(t);var e=[];for(var r in Object(t))b.call(t,r)&&r!="constructor"&&e.push(r);return e}function vr(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}function z(t){var e=new t.constructor(t.byteLength);return new mt(e).set(new mt(t)),e}function xr(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}function wr(t,e,r){var n=e?r(ht(t),!0):ht(t);return Lt(n,Ae,new t.constructor)}function jr(t){var e=new t.constructor(t.source,xe.exec(t));return e.lastIndex=t.lastIndex,e}function Or(t,e,r){var n=e?r(gt(t),!0):gt(t);return Lt(n,Ce,new t.constructor)}function Sr(t){return wt?Object(wt.call(t)):{}}function Tr(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function Ar(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}function Jt(t,e,r,n){r||(r={});for(var o=-1,s=e.length;++o<s;){var l=e[o],a=n?n(r[l],t[l],l,r,t):void 0;Wt(r,l,a===void 0?t[l]:a)}return r}function Cr(t,e){return Jt(t,qt(t),e)}function Er(t){return yr(t,et,qt)}function K(t,e){var r=t.__data__;return Rr(e)?r[typeof e=="string"?"string":"hash"]:r.map}function S(t,e){var r=Pe(t,e);return _r(r)?r:void 0}var qt=vt?Q(vt,Object):Hr,m=br;(U&&m(new U(new ArrayBuffer(1)))!=R||E&&m(new E)!=P||V&&m(V.resolve())!=pt||W&&m(new W)!=M||J&&m(new J)!=L)&&(m=function(t){var e=k.call(t),r=e==Z?t.constructor:void 0,n=r?x(r):void 0;if(n)switch(n){case He:return R;case Le:return P;case Ue:return pt;case Ve:return M;case We:return L}return e});function $r(t){var e=t.length,r=t.constructor(e);return e&&typeof t[0]=="string"&&b.call(t,"index")&&(r.index=t.index,r.input=t.input),r}function Ir(t){return typeof t.constructor=="function"&&!Xt(t)?gr(ke(t)):{}}function Pr(t,e,r,n){var o=t.constructor;switch(e){case Pt:return z(t);case St:case Tt:return new o(+t);case R:return xr(t,n);case Mt:case Rt:case Nt:case kt:case Ft:case Kt:case Bt:case Dt:case Gt:return Tr(t,n);case P:return wr(t,n,r);case Ct:case $t:return new o(t);case Et:return jr(t);case M:return Or(t,n,r);case It:return Sr(t)}}function Mr(t,e){return e=e==null?Ot:e,!!e&&(typeof t=="number"||je.test(t))&&t>-1&&t%1==0&&t<e}function Rr(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Nr(t){return!!yt&&yt in t}function Xt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||N;return t===r}function x(t){if(t!=null){try{return Vt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function kr(t){return q(t,!0,!0)}function Yt(t,e){return t===e||t!==t&&e!==e}function Fr(t){return Kr(t)&&b.call(t,"callee")&&(!Ke.call(t,"callee")||k.call(t)==X)}var tt=Array.isArray;function Zt(t){return t!=null&&Dr(t.length)&&!Qt(t)}function Kr(t){return Gr(t)&&Zt(t)}var Br=De||Lr;function Qt(t){var e=B(t)?k.call(t):"";return e==Y||e==At}function Dr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Ot}function B(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Gr(t){return!!t&&typeof t=="object"}function et(t){return Zt(t)?dr(t):mr(t)}function Hr(){return[]}function Lr(){return!1}w.exports=kr});var re=ft((un,ee)=>{var Ur="[object Object]";function Vr(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function Wr(t,e){return function(r){return t(e(r))}}var Jr=Function.prototype,zt=Object.prototype,te=Jr.toString,qr=zt.hasOwnProperty,Xr=te.call(Object),Yr=zt.toString,Zr=Wr(Object.getPrototypeOf,Object);function Qr(t){return!!t&&typeof t=="object"}function zr(t){if(!Qr(t)||Yr.call(t)!=Ur||Vr(t))return!1;var e=Zr(t);if(e===null)return!0;var r=qr.call(e,"constructor")&&e.constructor;return typeof r=="function"&&r instanceof r&&te.call(r)==Xr}ee.exports=zr});var sn={};ge(sn,{getByKey:()=>an,version:()=>on});var D=G(rt(),1),ne=G(re(),1);function tn(t){if(t.includes(".")){let e=t.lastIndexOf(".");if(!t.slice(0,e).includes("."))return t.slice(0,e);for(let r=e-1;r--;)if(t[r]===".")return t.slice(r+1,e)}return null}var nt=tn;function oe(t,e){let r={now:!1};function n(o,s,l,a){let u=(0,D.default)(o),p,c=y({depth:-1,path:""},l);if(c.depth+=1,Array.isArray(u))for(let f=0,g=u.length;f<g&&!a.now;f++){let _=c.path?`${c.path}.${f}`:`${f}`;u[f]!==void 0?(c.parent=(0,D.default)(u),c.parentType="array",c.parentKey=nt(_),p=n(s(u[f],void 0,A(y({},c),{path:_}),a),s,A(y({},c),{path:_}),a),Number.isNaN(p)&&f<u.length?(u.splice(f,1),f-=1):u[f]=p):u.splice(f,1)}else if((0,ne.default)(u))for(let f in u){if(a.now&&f!=null)break;let g=c.path?`${c.path}.${f}`:f;c.depth===0&&f!=null&&(c.topmostKey=f),c.parent=(0,D.default)(u),c.parentType="object",c.parentKey=nt(g),p=n(s(f,u[f],A(y({},c),{path:g}),a),s,A(y({},c),{path:g}),a),Number.isNaN(p)?delete u[f]:u[f]=p}return u}return n(t,e,{},r)}function ot(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var at=new Map,ae=(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(r=>{if(typeof r!="string"){if(typeof r>"u")return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof r}' in the array`)}return!0})},en=(t,e)=>{e=y({caseSensitive:!1},e);let r=t+JSON.stringify(e);if(at.has(r))return at.get(r);let n=t[0]==="!";n&&(t=t.slice(1)),t=ot(t).replace(/\\\*/g,"[\\s\\S]*");let o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,at.set(r,o),o},rn=(t,e,r,n)=>{if(t=ae(t,"inputs"),e=ae(e,"patterns"),e.length===0)return[];e=e.map(l=>en(l,r));let{allPatterns:o}=r||{},s=[];for(let l of t){let a,u=[...e].fill(!1);for(let[p,c]of e.entries())if(c.test(l)&&(u[p]=!0,a=!c.negated,!a))break;if(!(a===!1||a===void 0&&e.some(p=>!p.negated)||o&&u.some((p,c)=>!p&&!e[c].negated))&&(s.push(l),n))break}return s};function ie(t,e,r){return rn(t,e,r,!0).length>0}var it=G(rt(),1);var se="4.1.5";var on=se;function an(t,e,r){let n;r!==void 0&&(n=Array.isArray(r)?(0,it.default)(r):[(0,it.default)(r)]);let o=[],s=oe(t,(l,a,u)=>{let p=a!==void 0?a:l;if(a!==void 0&&ie(l,e,{caseSensitive:!0})){if(n===void 0)o.push({val:a,path:u.path});else if(n.length)return n.shift()}return p});return n===void 0?o:s}return ye(sn);})();
|
|
11
11
|
/**
|
|
12
12
|
* @name ast-monkey-traverse
|
|
13
13
|
* @fileoverview Utility library to traverse AST
|
|
14
|
-
* @version 3.1.
|
|
14
|
+
* @version 3.1.5
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* @name ast-monkey-util
|
|
21
21
|
* @fileoverview Utility library of AST helper functions
|
|
22
|
-
* @version 2.1.
|
|
22
|
+
* @version 2.1.5
|
|
23
23
|
* @author Roy Revelt, Codsen Ltd
|
|
24
24
|
* @license MIT
|
|
25
25
|
* {@link https://codsen.com/os/ast-monkey-util/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ast-get-values-by-key",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.5",
|
|
4
4
|
"description": "Extract values and paths from AST by keys OR set them by keys",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
52
52
|
"lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
|
|
53
53
|
"letspublish": "yarn publish || :",
|
|
54
|
-
"lint": "eslint . --fix",
|
|
54
|
+
"lint": "eslint . --ext .js --ext .ts --fix",
|
|
55
55
|
"perf": "node perf/check.js",
|
|
56
56
|
"prepare": "echo 'ready'",
|
|
57
57
|
"prettier": "prettier",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"ast-monkey-traverse": "^3.1.
|
|
81
|
+
"ast-monkey-traverse": "^3.1.5",
|
|
82
82
|
"lodash.clonedeep": "^4.5.0",
|
|
83
83
|
"matcher": "^5.0.0"
|
|
84
84
|
},
|
package/examples/_quickTake.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Quick Take
|
|
2
|
-
|
|
3
|
-
import { strict as assert } from "assert";
|
|
4
|
-
|
|
5
|
-
import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
|
|
6
|
-
|
|
7
|
-
// GETTER
|
|
8
|
-
// ======
|
|
9
|
-
|
|
10
|
-
// returns "object-path" notation paths where arrays use dots:
|
|
11
|
-
assert.deepEqual(
|
|
12
|
-
getByKey(
|
|
13
|
-
{
|
|
14
|
-
parsed: [
|
|
15
|
-
{
|
|
16
|
-
tag: "html",
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
"tag" // value to search for
|
|
21
|
-
),
|
|
22
|
-
[{ val: "html", path: "parsed.0.tag" }]
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
// SETTER
|
|
26
|
-
// ======
|
|
27
|
-
|
|
28
|
-
assert.deepEqual(
|
|
29
|
-
getByKey(
|
|
30
|
-
{
|
|
31
|
-
parsed: [
|
|
32
|
-
{
|
|
33
|
-
tag: "html",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
foo: {
|
|
37
|
-
tag: null,
|
|
38
|
-
},
|
|
39
|
-
bar: {
|
|
40
|
-
tag: null,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
"tag", // value to search for
|
|
44
|
-
[123, 456] // pot of values to pick from (one result not enough)
|
|
45
|
-
),
|
|
46
|
-
{
|
|
47
|
-
parsed: [
|
|
48
|
-
{
|
|
49
|
-
tag: 123,
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
foo: {
|
|
53
|
-
tag: 456,
|
|
54
|
-
},
|
|
55
|
-
bar: {
|
|
56
|
-
tag: null, // value pot was depleted and there was nothing left to put here
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
);
|
package/examples/real-use.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Replace all null's in keys `amount` with zero, but only under `orders`
|
|
2
|
-
|
|
3
|
-
import { strict as assert } from "assert";
|
|
4
|
-
|
|
5
|
-
import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
|
|
6
|
-
|
|
7
|
-
const source = {
|
|
8
|
-
orders: [
|
|
9
|
-
{
|
|
10
|
-
date: "2020-09-26",
|
|
11
|
-
amount: null, // replace
|
|
12
|
-
product: "Bramble",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
date: "2020-09-26",
|
|
16
|
-
amount: 2,
|
|
17
|
-
product: "Croodle",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
date: "2020-09-26",
|
|
21
|
-
amount: null, // replace
|
|
22
|
-
product: "Zapple",
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// first GET
|
|
28
|
-
const findings = getByKey(
|
|
29
|
-
source, // what to process
|
|
30
|
-
"amount" // what to look for
|
|
31
|
-
);
|
|
32
|
-
assert.deepEqual(findings, [
|
|
33
|
-
{ val: null, path: "orders.0.amount" },
|
|
34
|
-
{ val: 2, path: "orders.1.amount" },
|
|
35
|
-
{ val: null, path: "orders.2.amount" },
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
// prepare replacement array for SET third input argument
|
|
39
|
-
const replacement = findings.map(({ val }) => +val);
|
|
40
|
-
assert.deepEqual(replacement, [0, 2, 0]);
|
|
41
|
-
|
|
42
|
-
// then SET
|
|
43
|
-
const result = getByKey(
|
|
44
|
-
source, // what to process
|
|
45
|
-
"amount", // what to look for
|
|
46
|
-
replacement // pot of replacement values to consume (single-use, FIFO stack)
|
|
47
|
-
);
|
|
48
|
-
assert.deepEqual(result, {
|
|
49
|
-
orders: [
|
|
50
|
-
{
|
|
51
|
-
date: "2020-09-26",
|
|
52
|
-
amount: 0, // replace
|
|
53
|
-
product: "Bramble",
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
date: "2020-09-26",
|
|
57
|
-
amount: 2,
|
|
58
|
-
product: "Croodle",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
date: "2020-09-26",
|
|
62
|
-
amount: 0, // replace
|
|
63
|
-
product: "Zapple",
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
});
|
package/examples/wildcards.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// Using wildcards (`matcher` api)
|
|
2
|
-
|
|
3
|
-
import { strict as assert } from "assert";
|
|
4
|
-
|
|
5
|
-
import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
|
|
6
|
-
|
|
7
|
-
const source = {
|
|
8
|
-
popsicles: 1,
|
|
9
|
-
tentacles: 0,
|
|
10
|
-
nested: [
|
|
11
|
-
{
|
|
12
|
-
cutticles: "yes",
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Two input arguments - getter:
|
|
18
|
-
const findings = getByKey(source, ["*cles"]);
|
|
19
|
-
|
|
20
|
-
assert.deepEqual(findings, [
|
|
21
|
-
{
|
|
22
|
-
val: 1,
|
|
23
|
-
path: "popsicles",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
val: 0,
|
|
27
|
-
path: "tentacles",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
val: "yes",
|
|
31
|
-
path: "nested.0.cutticles",
|
|
32
|
-
},
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
// notice the path "nested.0.cutticles" is as per object-path notation -
|
|
36
|
-
// it's not "nested[0].cutticles" as in "normal" JS paths
|
|
37
|
-
|
|
38
|
-
// Three input arguments - setter:
|
|
39
|
-
assert.deepEqual(getByKey(source, ["*cles"], ["a", "b", "c"]), {
|
|
40
|
-
popsicles: "a",
|
|
41
|
-
tentacles: "b",
|
|
42
|
-
nested: [
|
|
43
|
-
{
|
|
44
|
-
cutticles: "c",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|