ast-get-values-by-key 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 ast-get-values-by-key
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 { getByKey } from "ast-get-values-by-key";
42
41
 
43
42
  // GETTER
@@ -97,7 +96,7 @@ assert.deepEqual(
97
96
 
98
97
  ## Documentation
99
98
 
100
- Please [visit codsen.com](https://codsen.com/os/ast-get-values-by-key/) for a full description of the API and examples.
99
+ Please [visit codsen.com](https://codsen.com/os/ast-get-values-by-key/) for a full description of the API.
101
100
 
102
101
  ## Contributing
103
102
 
@@ -107,6 +106,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
107
106
 
108
107
  MIT License
109
108
 
110
- Copyright (c) 2010-2021 Roy Revelt and other contributors
109
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
111
110
 
112
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">
@@ -1,44 +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.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/ast-get-values-by-key/}
8
8
  */
9
9
 
10
- import { traverse } from 'ast-monkey-traverse';
11
- import { isMatch } from 'matcher';
12
- import clone from 'lodash.clonedeep';
13
-
14
- var version$1 = "4.0.6";
15
-
16
- const version = version$1;
17
- function getByKey(originalInput, whatToFind, originalReplacement) {
18
- let replacement;
19
- if (originalReplacement !== undefined) {
20
- replacement = Array.isArray(originalReplacement)
21
- ? clone(originalReplacement)
22
- : [clone(originalReplacement)];
23
- }
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;
42
- }
43
-
44
- export { getByKey, version };
10
+ import{traverse as y}from"ast-monkey-traverse";import{isMatch as m}from"matcher";import d from"lodash.clonedeep";var i="4.0.12";var x=i;function k(a,o,t){let e;t!==void 0&&(e=Array.isArray(t)?d(t):[d(t)]);let r=[],p=y(a,(n,s,u)=>{let c=s!==void 0?s:n;if(s!==void 0&&m(n,o,{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,x as version};
@@ -1,26 +1,26 @@
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.6
4
+ * @version 4.0.12
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
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).astGetValuesByKey={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}};!function(t,r){var n="__lodash_hash_undefined__",o=9007199254740991,c="[object Arguments]",a="[object Boolean]",i="[object Date]",u="[object Function]",f="[object GeneratorFunction]",s="[object Map]",l="[object Number]",p="[object Object]",y="[object Promise]",h="[object RegExp]",d="[object Set]",v="[object String]",_="[object Symbol]",b="[object WeakMap]",g="[object ArrayBuffer]",j="[object DataView]",w="[object Float32Array]",O="[object Float64Array]",A="[object Int8Array]",m="[object Int16Array]",x="[object Int32Array]",$="[object Uint8Array]",S="[object Uint8ClampedArray]",E="[object Uint16Array]",T="[object Uint32Array]",P=/\w*$/,k=/^\[object .+?Constructor\]$/,I=/^(?:0|[1-9]\d*)$/,N={};N[c]=N["[object Array]"]=N[g]=N[j]=N[a]=N[i]=N[w]=N[O]=N[A]=N[m]=N[x]=N[s]=N[l]=N[p]=N[h]=N[d]=N[v]=N[_]=N[$]=N[S]=N[E]=N[T]=!0,N["[object Error]"]=N[u]=N[b]=!1;var B="object"==typeof self&&self&&self.Object===Object&&self,F="object"==typeof e&&e&&e.Object===Object&&e||B||Function("return this")(),M=r&&!r.nodeType&&r,K=M&&t&&!t.nodeType&&t,U=K&&K.exports===M;function R(t,e){return t.set(e[0],e[1]),t}function D(t,e){return t.add(e),t}function V(t,e,r,n){var o=-1,c=t?t.length:0;for(n&&c&&(r=t[++o]);++o<c;)r=e(r,t[o],o,t);return r}function z(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function C(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function G(t,e){return function(r){return t(e(r))}}function L(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var W,J=Array.prototype,q=Function.prototype,H=Object.prototype,Q=F["__core-js_shared__"],X=(W=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+W:"",Y=q.toString,Z=H.hasOwnProperty,tt=H.toString,et=RegExp("^"+Y.call(Z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=U?F.Buffer:void 0,nt=F.Symbol,ot=F.Uint8Array,ct=G(Object.getPrototypeOf,Object),at=Object.create,it=H.propertyIsEnumerable,ut=J.splice,ft=Object.getOwnPropertySymbols,st=rt?rt.isBuffer:void 0,lt=G(Object.keys,Object),pt=Kt(F,"DataView"),yt=Kt(F,"Map"),ht=Kt(F,"Promise"),dt=Kt(F,"Set"),vt=Kt(F,"WeakMap"),_t=Kt(Object,"create"),bt=zt(pt),gt=zt(yt),jt=zt(ht),wt=zt(dt),Ot=zt(vt),At=nt?nt.prototype:void 0,mt=At?At.valueOf:void 0;function xt(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 $t(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 St(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 Et(t){this.__data__=new $t(t)}function Tt(t,e){var r=Gt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Lt(t)}(t)&&Z.call(t,"callee")&&(!it.call(t,"callee")||tt.call(t)==c)}(t)?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],n=r.length,o=!!n;for(var a in t)!e&&!Z.call(t,a)||o&&("length"==a||Dt(a,n))||r.push(a);return r}function Pt(t,e,r){var n=t[e];Z.call(t,e)&&Ct(n,r)&&(void 0!==r||e in t)||(t[e]=r)}function kt(t,e){for(var r=t.length;r--;)if(Ct(t[r][0],e))return r;return-1}function It(t,e,r,n,o,y,b){var k;if(n&&(k=y?n(t,o,y,b):n(t)),void 0!==k)return k;if(!qt(t))return t;var I=Gt(t);if(I){if(k=function(t){var e=t.length,r=t.constructor(e);e&&"string"==typeof t[0]&&Z.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(t),!e)return function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(t,k)}else{var B=Rt(t),F=B==u||B==f;if(Wt(t))return function(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}(t,e);if(B==p||B==c||F&&!y){if(z(t))return y?t:{};if(k=function(t){return"function"!=typeof t.constructor||Vt(t)?{}:(e=ct(t),qt(e)?at(e):{});var e}(F?{}:t),!e)return function(t,e){return Ft(t,Ut(t),e)}(t,function(t,e){return t&&Ft(e,Ht(e),t)}(k,t))}else{if(!N[B])return y?t:{};k=function(t,e,r,n){var o=t.constructor;switch(e){case g:return Bt(t);case a:case i:return new o(+t);case j:return function(t,e){var r=e?Bt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,n);case w:case O:case A:case m:case x:case $:case S:case E:case T:return function(t,e){var r=e?Bt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,n);case s:return function(t,e,r){return V(e?r(C(t),!0):C(t),R,new t.constructor)}(t,n,r);case l:case v:return new o(t);case h:return function(t){var e=new t.constructor(t.source,P.exec(t));return e.lastIndex=t.lastIndex,e}(t);case d:return function(t,e,r){return V(e?r(L(t),!0):L(t),D,new t.constructor)}(t,n,r);case _:return c=t,mt?Object(mt.call(c)):{}}var c}(t,B,It,e)}}b||(b=new Et);var M=b.get(t);if(M)return M;if(b.set(t,k),!I)var K=r?function(t){return function(t,e,r){var n=e(t);return Gt(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,Ht,Ut)}(t):Ht(t);return function(t,e){for(var r=-1,n=t?t.length:0;++r<n&&!1!==e(t[r],r,t););}(K||t,(function(o,c){K&&(o=t[c=o]),Pt(k,c,It(o,e,r,n,c,t,b))})),k}function Nt(t){return!(!qt(t)||(e=t,X&&X in e))&&(Jt(t)||z(t)?et:k).test(zt(t));var e}function Bt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Ft(t,e,r,n){r||(r={});for(var o=-1,c=e.length;++o<c;){var a=e[o],i=n?n(r[a],t[a],a,r,t):void 0;Pt(r,a,void 0===i?t[a]:i)}return r}function Mt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Kt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Nt(r)?r:void 0}xt.prototype.clear=function(){this.__data__=_t?_t(null):{}},xt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},xt.prototype.get=function(t){var e=this.__data__;if(_t){var r=e[t];return r===n?void 0:r}return Z.call(e,t)?e[t]:void 0},xt.prototype.has=function(t){var e=this.__data__;return _t?void 0!==e[t]:Z.call(e,t)},xt.prototype.set=function(t,e){return this.__data__[t]=_t&&void 0===e?n:e,this},$t.prototype.clear=function(){this.__data__=[]},$t.prototype.delete=function(t){var e=this.__data__,r=kt(e,t);return!(r<0)&&(r==e.length-1?e.pop():ut.call(e,r,1),!0)},$t.prototype.get=function(t){var e=this.__data__,r=kt(e,t);return r<0?void 0:e[r][1]},$t.prototype.has=function(t){return kt(this.__data__,t)>-1},$t.prototype.set=function(t,e){var r=this.__data__,n=kt(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},St.prototype.clear=function(){this.__data__={hash:new xt,map:new(yt||$t),string:new xt}},St.prototype.delete=function(t){return Mt(this,t).delete(t)},St.prototype.get=function(t){return Mt(this,t).get(t)},St.prototype.has=function(t){return Mt(this,t).has(t)},St.prototype.set=function(t,e){return Mt(this,t).set(t,e),this},Et.prototype.clear=function(){this.__data__=new $t},Et.prototype.delete=function(t){return this.__data__.delete(t)},Et.prototype.get=function(t){return this.__data__.get(t)},Et.prototype.has=function(t){return this.__data__.has(t)},Et.prototype.set=function(t,e){var r=this.__data__;if(r instanceof $t){var n=r.__data__;if(!yt||n.length<199)return n.push([t,e]),this;r=this.__data__=new St(n)}return r.set(t,e),this};var Ut=ft?G(ft,Object):function(){return[]},Rt=function(t){return tt.call(t)};function Dt(t,e){return!!(e=null==e?o:e)&&("number"==typeof t||I.test(t))&&t>-1&&t%1==0&&t<e}function Vt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||H)}function zt(t){if(null!=t){try{return Y.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Ct(t,e){return t===e||t!=t&&e!=e}(pt&&Rt(new pt(new ArrayBuffer(1)))!=j||yt&&Rt(new yt)!=s||ht&&Rt(ht.resolve())!=y||dt&&Rt(new dt)!=d||vt&&Rt(new vt)!=b)&&(Rt=function(t){var e=tt.call(t),r=e==p?t.constructor:void 0,n=r?zt(r):void 0;if(n)switch(n){case bt:return j;case gt:return s;case jt:return y;case wt:return d;case Ot:return b}return e});var Gt=Array.isArray;function Lt(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=o}(t.length)&&!Jt(t)}var Wt=st||function(){return!1};function Jt(t){var e=qt(t)?tt.call(t):"";return e==u||e==f}function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Ht(t){return Lt(t)?Tt(t):function(t){if(!Vt(t))return lt(t);var e=[];for(var r in Object(t))Z.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}t.exports=function(t){return It(t,!0,!0)}}(r,r.exports);var n=r.exports;var o,c,a=Object.prototype,i=Function.prototype.toString,u=a.hasOwnProperty,f=i.call(Object),s=a.toString,l=(o=Object.getPrototypeOf,c=Object,function(t){return o(c(t))});var p=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||"[object Object]"!=s.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=l(t);if(null===e)return!0;var r=u.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&i.call(r)==f};
11
- /**
12
- * @name ast-monkey-util
13
- * @fileoverview Utility library of AST helper functions
14
- * @version 2.0.6
15
- * @author Roy Revelt, Codsen Ltd
16
- * @license MIT
17
- * {@link https://codsen.com/os/ast-monkey-util/}
18
- */function y(t){if(t.includes(".")){const 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}
10
+ var astGetValuesByKey=(()=>{var ue=Object.create;var T=Object.defineProperty,fe=Object.defineProperties,le=Object.getOwnPropertyDescriptor,pe=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,st=Object.getOwnPropertySymbols,he=Object.getPrototypeOf,ct=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var ut=(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={}))ct.call(e,r)&&ut(t,r,e[r]);if(st)for(var r of st(e))ge.call(e,r)&&ut(t,r,e[r]);return t},A=(t,e)=>fe(t,pe(e)),ft=t=>T(t,"__esModule",{value:!0});var lt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ye=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},pt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of de(e))!ct.call(t,o)&&(r||o!=="default")&&T(t,o,{get:()=>e[o],enumerable:!(n=le(e,o))||n.enumerable});return t},G=(t,e)=>pt(ft(T(t!=null?ue(he(t)):{},"default",!e&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),be=(t=>(e,r)=>t&&t.get(e)||(r=pt(ft({}),e,1),t&&t.set(e,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var rt=lt(($,S)=>{var _e=200,dt="__lodash_hash_undefined__",ht=9007199254740991,H="[object Arguments]",me="[object Array]",gt="[object Boolean]",yt="[object Date]",ve="[object Error]",L="[object Function]",bt="[object GeneratorFunction]",P="[object Map]",_t="[object Number]",U="[object Object]",mt="[object Promise]",vt="[object RegExp]",M="[object Set]",xt="[object String]",wt="[object Symbol]",V="[object WeakMap]",jt="[object ArrayBuffer]",R="[object DataView]",Ot="[object Float32Array]",St="[object Float64Array]",Tt="[object Int8Array]",At="[object Int16Array]",Ct="[object Int32Array]",Et="[object Uint8Array]",$t="[object Uint8ClampedArray]",It="[object Uint16Array]",Pt="[object Uint32Array]",xe=/[\\^$.*+?()[\]{}|]/g,we=/\w*$/,je=/^\[object .+?Constructor\]$/,Oe=/^(?:0|[1-9]\d*)$/,i={};i[H]=i[me]=i[jt]=i[R]=i[gt]=i[yt]=i[Ot]=i[St]=i[Tt]=i[At]=i[Ct]=i[P]=i[_t]=i[U]=i[vt]=i[M]=i[xt]=i[wt]=i[Et]=i[$t]=i[It]=i[Pt]=!0;i[ve]=i[L]=i[V]=!1;var Se=typeof global=="object"&&global&&global.Object===Object&&global,Te=typeof self=="object"&&self&&self.Object===Object&&self,d=Se||Te||Function("return this")(),Mt=typeof $=="object"&&$&&!$.nodeType&&$,Rt=Mt&&typeof S=="object"&&S&&!S.nodeType&&S,Ae=Rt&&Rt.exports===Mt;function Ce(t,e){return t.set(e[0],e[1]),t}function Ee(t,e){return t.add(e),t}function $e(t,e){for(var r=-1,n=t?t.length:0;++r<n&&e(t[r],r,t)!==!1;);return t}function Ie(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function Nt(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 Pe(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}function Me(t,e){return t==null?void 0:t[e]}function kt(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function Ft(t){var e=-1,r=Array(t.size);return t.forEach(function(n,o){r[++e]=[o,n]}),r}function W(t,e){return function(r){return t(e(r))}}function Kt(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var Re=Array.prototype,Ne=Function.prototype,N=Object.prototype,J=d["__core-js_shared__"],Bt=function(){var t=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Dt=Ne.toString,b=N.hasOwnProperty,k=N.toString,ke=RegExp("^"+Dt.call(b).replace(xe,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Gt=Ae?d.Buffer:void 0,Ht=d.Symbol,Lt=d.Uint8Array,Fe=W(Object.getPrototypeOf,Object),Ke=Object.create,Be=N.propertyIsEnumerable,De=Re.splice,Ut=Object.getOwnPropertySymbols,Ge=Gt?Gt.isBuffer:void 0,He=W(Object.keys,Object),q=O(d,"DataView"),C=O(d,"Map"),X=O(d,"Promise"),Y=O(d,"Set"),Z=O(d,"WeakMap"),E=O(Object,"create"),Le=x(q),Ue=x(C),Ve=x(X),We=x(Y),Je=x(Z),Vt=Ht?Ht.prototype:void 0,Wt=Vt?Vt.valueOf:void 0;function m(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__=E?E(null):{}}function Xe(t){return this.has(t)&&delete this.__data__[t]}function Ye(t){var e=this.__data__;if(E){var r=e[t];return r===dt?void 0:r}return b.call(e,t)?e[t]:void 0}function Ze(t){var e=this.__data__;return E?e[t]!==void 0:b.call(e,t)}function Qe(t,e){var r=this.__data__;return r[t]=E&&e===void 0?dt:e,this}m.prototype.clear=qe;m.prototype.delete=Xe;m.prototype.get=Ye;m.prototype.has=Ze;m.prototype.set=Qe;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 ze(){this.__data__=[]}function tr(t){var e=this.__data__,r=F(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():De.call(e,r,1),!0}function er(t){var e=this.__data__,r=F(e,t);return r<0?void 0:e[r][1]}function rr(t){return F(this.__data__,t)>-1}function nr(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=ze;h.prototype.delete=tr;h.prototype.get=er;h.prototype.has=rr;h.prototype.set=nr;function w(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 or(){this.__data__={hash:new m,map:new(C||h),string:new m}}function ar(t){return K(this,t).delete(t)}function ir(t){return K(this,t).get(t)}function sr(t){return K(this,t).has(t)}function cr(t,e){return K(this,t).set(t,e),this}w.prototype.clear=or;w.prototype.delete=ar;w.prototype.get=ir;w.prototype.has=sr;w.prototype.set=cr;function j(t){this.__data__=new h(t)}function ur(){this.__data__=new h}function fr(t){return this.__data__.delete(t)}function lr(t){return this.__data__.get(t)}function pr(t){return this.__data__.has(t)}function dr(t,e){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!C||n.length<_e-1)return n.push([t,e]),this;r=this.__data__=new w(n)}return r.set(t,e),this}j.prototype.clear=ur;j.prototype.delete=fr;j.prototype.get=lr;j.prototype.has=pr;j.prototype.set=dr;function hr(t,e){var r=tt(t)||Kr(t)?Pe(t.length,String):[],n=r.length,o=!!n;for(var s in t)(e||b.call(t,s))&&!(o&&(s=="length"||Rr(s,n)))&&r.push(s);return r}function Jt(t,e,r){var n=t[e];(!(b.call(t,e)&&Zt(n,r))||r===void 0&&!(e in t))&&(t[e]=r)}function F(t,e){for(var r=t.length;r--;)if(Zt(t[r][0],e))return r;return-1}function gr(t,e){return t&&qt(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=Ir(t),!e)return Cr(t,a)}else{var p=v(t),c=p==L||p==bt;if(Dr(t))return xr(t,e);if(p==U||p==H||c&&!s){if(kt(t))return s?t:{};if(a=Pr(c?{}:t),!e)return Er(t,gr(a,t))}else{if(!i[p])return s?t:{};a=Mr(t,p,Q,e)}}l||(l=new j);var f=l.get(t);if(f)return f;if(l.set(t,a),!u)var g=r?$r(t):et(t);return $e(g||t,function(_,I){g&&(I=_,_=t[I]),Jt(a,I,Q(_,e,r,n,I,t,l))}),a}function yr(t){return B(t)?Ke(t):{}}function br(t,e,r){var n=e(t);return tt(t)?n:Ie(n,r(t))}function _r(t){return k.call(t)}function mr(t){if(!B(t)||kr(t))return!1;var e=zt(t)||kt(t)?ke:je;return e.test(x(t))}function vr(t){if(!Yt(t))return He(t);var e=[];for(var r in Object(t))b.call(t,r)&&r!="constructor"&&e.push(r);return e}function xr(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 Lt(e).set(new Lt(t)),e}function wr(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}function jr(t,e,r){var n=e?r(Ft(t),!0):Ft(t);return Nt(n,Ce,new t.constructor)}function Or(t){var e=new t.constructor(t.source,we.exec(t));return e.lastIndex=t.lastIndex,e}function Sr(t,e,r){var n=e?r(Kt(t),!0):Kt(t);return Nt(n,Ee,new t.constructor)}function Tr(t){return Wt?Object(Wt.call(t)):{}}function Ar(t,e){var r=e?z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function Cr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}function qt(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;Jt(r,l,a===void 0?t[l]:a)}return r}function Er(t,e){return qt(t,Xt(t),e)}function $r(t){return br(t,et,Xt)}function K(t,e){var r=t.__data__;return Nr(e)?r[typeof e=="string"?"string":"hash"]:r.map}function O(t,e){var r=Me(t,e);return mr(r)?r:void 0}var Xt=Ut?W(Ut,Object):Lr,v=_r;(q&&v(new q(new ArrayBuffer(1)))!=R||C&&v(new C)!=P||X&&v(X.resolve())!=mt||Y&&v(new Y)!=M||Z&&v(new Z)!=V)&&(v=function(t){var e=k.call(t),r=e==U?t.constructor:void 0,n=r?x(r):void 0;if(n)switch(n){case Le:return R;case Ue:return P;case Ve:return mt;case We:return M;case Je:return V}return e});function Ir(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 Pr(t){return typeof t.constructor=="function"&&!Yt(t)?yr(Fe(t)):{}}function Mr(t,e,r,n){var o=t.constructor;switch(e){case jt:return z(t);case gt:case yt:return new o(+t);case R:return wr(t,n);case Ot:case St:case Tt:case At:case Ct:case Et:case $t:case It:case Pt:return Ar(t,n);case P:return jr(t,n,r);case _t:case xt:return new o(t);case vt:return Or(t);case M:return Sr(t,n,r);case wt:return Tr(t)}}function Rr(t,e){return e=e==null?ht:e,!!e&&(typeof t=="number"||Oe.test(t))&&t>-1&&t%1==0&&t<e}function Nr(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function kr(t){return!!Bt&&Bt in t}function Yt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||N;return t===r}function x(t){if(t!=null){try{return Dt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function Fr(t){return Q(t,!0,!0)}function Zt(t,e){return t===e||t!==t&&e!==e}function Kr(t){return Br(t)&&b.call(t,"callee")&&(!Be.call(t,"callee")||k.call(t)==H)}var tt=Array.isArray;function Qt(t){return t!=null&&Gr(t.length)&&!zt(t)}function Br(t){return Hr(t)&&Qt(t)}var Dr=Ge||Ur;function zt(t){var e=B(t)?k.call(t):"";return e==L||e==bt}function Gr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=ht}function B(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Hr(t){return!!t&&typeof t=="object"}function et(t){return Qt(t)?hr(t):vr(t)}function Lr(){return[]}function Ur(){return!1}S.exports=Fr});var ne=lt((fn,re)=>{var Vr="[object Object]";function Wr(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function Jr(t,e){return function(r){return t(e(r))}}var qr=Function.prototype,te=Object.prototype,ee=qr.toString,Xr=te.hasOwnProperty,Yr=ee.call(Object),Zr=te.toString,Qr=Jr(Object.getPrototypeOf,Object);function zr(t){return!!t&&typeof t=="object"}function tn(t){if(!zr(t)||Zr.call(t)!=Vr||Wr(t))return!1;var e=Qr(t);if(e===null)return!0;var r=Xr.call(e,"constructor")&&e.constructor;return typeof r=="function"&&r instanceof r&&ee.call(r)==Yr}re.exports=tn});var cn={};ye(cn,{getByKey:()=>sn,version:()=>an});var D=G(rt(),1),oe=G(ne(),1);function en(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=en;function ae(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,oe.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,ie=(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=="undefined")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})},rn=(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},nn=(t,e,r,n)=>{if(t=ie(t,"inputs"),e=ie(e,"patterns"),e.length===0)return[];e=e.map(l=>rn(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 se(t,e,r){return nn(t,e,r,!0).length>0}var it=G(rt(),1);var ce="4.0.12";var an=ce;function sn(t,e,r){let n;r!==void 0&&(n=Array.isArray(r)?(0,it.default)(r):[(0,it.default)(r)]);let o=[],s=ae(t,(l,a,u)=>{let p=a!==void 0?a:l;if(a!==void 0&&se(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 be(cn);})();
19
11
  /**
20
12
  * @name ast-monkey-traverse
21
13
  * @fileoverview Utility library to traverse AST
22
- * @version 3.0.6
14
+ * @version 3.0.12
23
15
  * @author Roy Revelt, Codsen Ltd
24
16
  * @license MIT
25
17
  * {@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.6",Object.defineProperty(t,"__esModule",{value:!0})}));
18
+ */
19
+ /**
20
+ * @name ast-monkey-util
21
+ * @fileoverview Utility library of AST helper functions
22
+ * @version 2.0.12
23
+ * @author Roy Revelt, Codsen Ltd
24
+ * @license MIT
25
+ * {@link https://codsen.com/os/ast-monkey-util/}
26
+ */
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
5
6
 
6
7
  // GETTER
@@ -1,6 +1,7 @@
1
1
  // Replace all null's in keys `amount` with zero, but only under `orders`
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
5
6
 
6
7
  const source = {
@@ -1,6 +1,7 @@
1
1
  // Using wildcards (`matcher` api)
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { getByKey } from "../dist/ast-get-values-by-key.esm.js";
5
6
 
6
7
  const source = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ast-get-values-by-key",
3
- "version": "4.0.6",
3
+ "version": "4.0.12",
4
4
  "description": "Extract values and paths from AST by keys OR set them by keys",
5
5
  "keywords": [
6
6
  "ast",
@@ -43,97 +43,45 @@
43
43
  },
44
44
  "types": "types/index.d.ts",
45
45
  "scripts": {
46
- "build": "rollup -c",
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",
50
- "clean_types": "../../scripts/cleanTypes.js",
51
- "dev": "rollup -c --dev",
52
- "devunittest": "npm run dev && tap --only -R 'base'",
53
- "format": "npm run lect && npm run prettier && npm run lint",
54
- "lect": "lect",
55
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
56
- "perf": "node perf/check",
57
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
58
- "republish": "npm publish || :",
59
- "tap": "tap",
60
- "pretest": "npm run build",
61
- "test": "npm run test:ci && npm run perf",
62
- "test:ci": "npm run unittest && npm run test:examples && npm run format",
63
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
64
- "tsc": "tsc",
65
- "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
46
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
47
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
48
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
49
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
50
+ "examples": "node '../../ops/scripts/run-examples.js'",
51
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
52
+ "letspublish": "yarn publish || :",
53
+ "lint": "eslint . --fix",
54
+ "perf": "node perf/check.js",
55
+ "prepare": "echo 'ready'",
56
+ "prettier": "prettier",
57
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
58
+ "pretest": "yarn run lect && yarn run build",
59
+ "test": "yarn run devtest",
60
+ "unit": "uvu test"
66
61
  },
67
- "tap": {
68
- "check-coverage": false,
69
- "node-arg": [
70
- "--no-warnings",
71
- "--experimental-loader",
72
- "@istanbuljs/esm-loader-hook"
62
+ "engines": {
63
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
64
+ },
65
+ "c8": {
66
+ "check-coverage": true,
67
+ "exclude": [
68
+ "**/test/**/*.*"
73
69
  ],
74
- "timeout": 0
70
+ "lines": 100
75
71
  },
76
72
  "lect": {
77
73
  "licence": {
78
74
  "extras": [
79
75
  ""
80
76
  ]
81
- },
82
- "req": "{ getByKey }",
83
- "various": {
84
- "devDependencies": [
85
- "@types/lodash.clonedeep",
86
- "object-path"
87
- ]
88
77
  }
89
78
  },
90
79
  "dependencies": {
91
- "@babel/runtime": "^7.16.3",
92
- "ast-monkey-traverse": "^3.0.6",
80
+ "ast-monkey-traverse": "^3.0.12",
93
81
  "lodash.clonedeep": "^4.5.0",
94
82
  "matcher": "^5.0.0"
95
83
  },
96
84
  "devDependencies": {
97
- "@babel/cli": "^7.16.0",
98
- "@babel/core": "^7.16.0",
99
- "@babel/node": "^7.16.0",
100
- "@babel/plugin-external-helpers": "^7.16.0",
101
- "@babel/plugin-proposal-class-properties": "^7.16.0",
102
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
103
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
104
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
105
- "@babel/plugin-transform-runtime": "^7.16.4",
106
- "@babel/preset-env": "^7.16.4",
107
- "@babel/preset-typescript": "^7.16.0",
108
- "@babel/register": "^7.16.0",
109
- "@istanbuljs/esm-loader-hook": "^0.1.2",
110
- "@rollup/plugin-babel": "^5.3.0",
111
- "@rollup/plugin-commonjs": "^21.0.1",
112
- "@rollup/plugin-json": "^4.1.0",
113
- "@rollup/plugin-node-resolve": "^13.0.6",
114
- "@rollup/plugin-strip": "^2.1.0",
115
- "@rollup/plugin-typescript": "^8.3.0",
116
- "@types/lodash.clonedeep": "^4.5.6",
117
- "@types/node": "^16.11.9",
118
- "@types/tap": "^15.0.5",
119
- "@typescript-eslint/eslint-plugin": "^5.4.0",
120
- "@typescript-eslint/parser": "^5.4.0",
121
- "core-js": "^3.19.1",
122
- "cross-env": "^7.0.3",
123
- "eslint": "^8.3.0",
124
- "lect": "^0.18.6",
125
- "object-path": "^0.11.8",
126
- "rollup": "^2.60.0",
127
- "rollup-plugin-ascii": "^0.0.3",
128
- "rollup-plugin-banner": "^0.2.1",
129
- "rollup-plugin-cleanup": "^3.2.1",
130
- "rollup-plugin-dts": "^4.0.1",
131
- "rollup-plugin-terser": "^7.0.2",
132
- "tap": "^15.1.2",
133
- "tslib": "^2.3.1",
134
- "typescript": "^4.5.2"
135
- },
136
- "engines": {
137
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
85
+ "@types/lodash.clonedeep": "^4.5.6"
138
86
  }
139
87
  }
package/types/index.d.ts CHANGED
@@ -2,6 +2,10 @@ declare const version: string;
2
2
  /**
3
3
  * Extract values and paths from AST by keys OR set them by keys
4
4
  */
5
- declare function getByKey(originalInput: any, whatToFind: string | string[], originalReplacement?: any): any;
5
+ declare function getByKey(
6
+ originalInput: any,
7
+ whatToFind: string | string[],
8
+ originalReplacement?: any
9
+ ): any;
6
10
 
7
11
  export { getByKey, 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; getByKey &#x7D; from \"ast-get-values-by-key\";\n\n// GETTER\n// ======\n\n// returns \"object-path\" notation paths where arrays use dots:\nassert.deepEqual(\n getByKey(\n &#x7B;\n parsed: [\n &#x7B;\n tag: \"html\",\n &#x7D;,\n ],\n &#x7D;,\n \"tag\" // value to search for\n ),\n [&#x7B; val: \"html\", path: \"parsed.0.tag\" &#x7D;]\n);\n\n// SETTER\n// ======\n\nassert.deepEqual(\n getByKey(\n &#x7B;\n parsed: [\n &#x7B;\n tag: \"html\",\n &#x7D;,\n ],\n foo: &#x7B;\n tag: null,\n &#x7D;,\n bar: &#x7B;\n tag: null,\n &#x7D;,\n &#x7D;,\n \"tag\", // value to search for\n [123, 456] // pot of values to pick from (one result not enough)\n ),\n &#x7B;\n parsed: [\n &#x7B;\n tag: 123,\n &#x7D;,\n ],\n foo: &#x7B;\n tag: 456,\n &#x7D;,\n bar: &#x7B;\n tag: null, // value pot was depleted and there was nothing left to put here\n &#x7D;,\n &#x7D;\n);"},"real-use.js":{"title":"Replace all null's in keys `amount` with zero, but only under `orders`","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; getByKey &#x7D; from \"ast-get-values-by-key\";\n\nconst source = &#x7B;\n orders: [\n &#x7B;\n date: \"2020-09-26\",\n amount: null, // replace\n product: \"Bramble\",\n &#x7D;,\n &#x7B;\n date: \"2020-09-26\",\n amount: 2,\n product: \"Croodle\",\n &#x7D;,\n &#x7B;\n date: \"2020-09-26\",\n amount: null, // replace\n product: \"Zapple\",\n &#x7D;,\n ],\n&#x7D;;\n\n// first GET\nconst findings = getByKey(\n source, // what to process\n \"amount\" // what to look for\n);\nassert.deepEqual(findings, [\n &#x7B; val: null, path: \"orders.0.amount\" &#x7D;,\n &#x7B; val: 2, path: \"orders.1.amount\" &#x7D;,\n &#x7B; val: null, path: \"orders.2.amount\" &#x7D;,\n]);\n\n// prepare replacement array for SET third input argument\nconst replacement = findings.map((&#x7B; val &#x7D;) => +val);\nassert.deepEqual(replacement, [0, 2, 0]);\n\n// then SET\nconst result = getByKey(\n source, // what to process\n \"amount\", // what to look for\n replacement // pot of replacement values to consume (single-use, FIFO stack)\n);\nassert.deepEqual(result, &#x7B;\n orders: [\n &#x7B;\n date: \"2020-09-26\",\n amount: 0, // replace\n product: \"Bramble\",\n &#x7D;,\n &#x7B;\n date: \"2020-09-26\",\n amount: 2,\n product: \"Croodle\",\n &#x7D;,\n &#x7B;\n date: \"2020-09-26\",\n amount: 0, // replace\n product: \"Zapple\",\n &#x7D;,\n ],\n&#x7D;);"},"wildcards.js":{"title":"Using wildcards (`matcher` api)","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; getByKey &#x7D; from \"ast-get-values-by-key\";\n\nconst source = &#x7B;\n popsicles: 1,\n tentacles: 0,\n nested: [\n &#x7B;\n cutticles: \"yes\",\n &#x7D;,\n ],\n&#x7D;;\n\n// Two input arguments - getter:\nconst findings = getByKey(source, [\"*cles\"]);\n\nassert.deepEqual(findings, [\n &#x7B;\n val: 1,\n path: \"popsicles\",\n &#x7D;,\n &#x7B;\n val: 0,\n path: \"tentacles\",\n &#x7D;,\n &#x7B;\n val: \"yes\",\n path: \"nested.0.cutticles\",\n &#x7D;,\n]);\n\n// notice the path \"nested.0.cutticles\" is as per object-path notation -\n// it's not \"nested[0].cutticles\" as in \"normal\" JS paths\n\n// Three input arguments - setter:\nassert.deepEqual(getByKey(source, [\"*cles\"], [\"a\", \"b\", \"c\"]), &#x7B;\n popsicles: \"a\",\n tentacles: \"b\",\n nested: [\n &#x7B;\n cutticles: \"c\",\n &#x7D;,\n ],\n&#x7D;);"}}