ast-get-values-by-key 4.0.4 → 4.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md 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-%YEAR% Roy Revelt and other contributors
3
+ Copyright (c) 2010-2021 Roy Revelt and other contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 3.1.0
38
38
 
39
39
  ```js
40
40
  import { strict as assert } from "assert";
41
+
41
42
  import { getByKey } from "ast-get-values-by-key";
42
43
 
43
44
  // GETTER
@@ -97,7 +98,7 @@ assert.deepEqual(
97
98
 
98
99
  ## Documentation
99
100
 
100
- Please [visit codsen.com](https://codsen.com/os/ast-get-values-by-key/) for a full description of the API and examples.
101
+ Please [visit codsen.com](https://codsen.com/os/ast-get-values-by-key/) for a full description of the API.
101
102
 
102
103
  ## Contributing
103
104
 
@@ -109,4 +110,6 @@ MIT License
109
110
 
110
111
  Copyright (c) 2010-2021 Roy Revelt and other contributors
111
112
 
113
+
112
114
  <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">
115
+
@@ -1,42 +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.4
4
+ * @version 4.0.10
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.4";
15
-
16
- const version = version$1;
17
- function getByKey(originalInput, whatToFind, originalReplacement) {
18
- let replacement;
19
- if (originalReplacement !== undefined) {
20
- replacement = Array.isArray(originalReplacement) ? clone(originalReplacement) : [clone(originalReplacement)];
21
- }
22
- const findings = [];
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
- }
36
- }
37
- return current;
38
- });
39
- return replacement === undefined ? findings : amended;
40
- }
41
-
42
- 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.10";var k=i;function x(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{x as getByKey,k 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.4
4
+ * @version 4.0.10
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.4
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},D=(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((E,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]",Ot="[object ArrayBuffer]",N="[object DataView]",jt="[object Float32Array]",St="[object Float64Array]",Tt="[object Int8Array]",At="[object Int16Array]",Ct="[object Int32Array]",$t="[object Uint8Array]",Et="[object Uint8ClampedArray]",It="[object Uint16Array]",Pt="[object Uint32Array]",xe=/[\\^$.*+?()[\]{}|]/g,we=/\w*$/,Oe=/^\[object .+?Constructor\]$/,je=/^(?:0|[1-9]\d*)$/,i={};i[H]=i[me]=i[Ot]=i[N]=i[gt]=i[yt]=i[jt]=i[St]=i[Tt]=i[At]=i[Ct]=i[P]=i[_t]=i[U]=i[vt]=i[M]=i[xt]=i[wt]=i[$t]=i[Et]=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 E=="object"&&E&&!E.nodeType&&E,Nt=Mt&&typeof S=="object"&&S&&!S.nodeType&&S,Ae=Nt&&Nt.exports===Mt;function Ce(t,e){return t.set(e[0],e[1]),t}function $e(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 Ie(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function Rt(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 Ne=Array.prototype,Re=Function.prototype,R=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:""}(),Gt=Re.toString,b=R.hasOwnProperty,k=R.toString,ke=RegExp("^"+Gt.call(b).replace(xe,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Dt=Ae?d.Buffer:void 0,Ht=d.Symbol,Lt=d.Uint8Array,Fe=W(Object.getPrototypeOf,Object),Ke=Object.create,Be=R.propertyIsEnumerable,Ge=Ne.splice,Ut=Object.getOwnPropertySymbols,De=Dt?Dt.isBuffer:void 0,He=W(Object.keys,Object),q=j(d,"DataView"),C=j(d,"Map"),X=j(d,"Promise"),Y=j(d,"Set"),Z=j(d,"WeakMap"),$=j(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__=$?$(null):{}}function Xe(t){return this.has(t)&&delete this.__data__[t]}function Ye(t){var e=this.__data__;if($){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[t]!==void 0:b.call(e,t)}function Qe(t,e){var r=this.__data__;return r[t]=$&&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():Ge.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 O(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}O.prototype.clear=ur;O.prototype.delete=fr;O.prototype.get=lr;O.prototype.has=pr;O.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"||Nr(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(Gr(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 $r(t,gr(a,t))}else{if(!i[p])return s?t:{};a=Mr(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]),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:Oe;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 Or(t,e,r){var n=e?r(Ft(t),!0):Ft(t);return Rt(n,Ce,new t.constructor)}function jr(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 Rt(n,$e,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 $r(t,e){return qt(t,Xt(t),e)}function Er(t){return br(t,et,Xt)}function K(t,e){var r=t.__data__;return Rr(e)?r[typeof e=="string"?"string":"hash"]:r.map}function j(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)))!=N||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 N;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 Ot:return z(t);case gt:case yt:return new o(+t);case N:return wr(t,n);case jt:case St:case Tt:case At:case Ct:case $t:case Et:case It:case Pt:return Ar(t,n);case P:return Or(t,n,r);case _t:case xt:return new o(t);case vt:return jr(t);case M:return Sr(t,n,r);case wt:return Tr(t)}}function Nr(t,e){return e=e==null?ht: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 kr(t){return!!Bt&&Bt in t}function Yt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||R;return t===r}function x(t){if(t!=null){try{return Gt.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&&Dr(t.length)&&!zt(t)}function Br(t){return Hr(t)&&Qt(t)}var Gr=De||Ur;function zt(t){var e=B(t)?k.call(t):"";return e==L||e==bt}function Dr(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 G=D(rt(),1),oe=D(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,G.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,G.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,G.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=D(rt(),1);var ce="4.0.10";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.4
14
+ * @version 3.0.10
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.4",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.10
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.4",
3
+ "version": "4.0.10",
4
4
  "description": "Extract values and paths from AST by keys OR set them by keys",
5
5
  "keywords": [
6
6
  "ast",
@@ -43,101 +43,42 @@
43
43
  },
44
44
  "types": "types/index.d.ts",
45
45
  "scripts": {
46
- "build": "rollup -c",
47
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
48
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
49
- "clean_types": "../../scripts/cleanTypes.js",
50
- "dev": "rollup -c --dev",
51
- "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
- "format": "npm run lect && npm run prettier && npm run lint",
55
- "lect": "lect",
56
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
57
- "perf": "node perf/check",
58
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
59
- "republish": "npm publish || :",
60
- "tap": "tap",
61
- "pretest": "npm run build",
62
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
63
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
64
- "tsc": "tsc",
65
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
46
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
47
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
48
+ "dts": "rollup -c",
49
+ "examples": "node '../../ops/scripts/run-examples.js'",
50
+ "lect": "node '../../ops/lect/lect.js'",
51
+ "letspublish": "yarn publish || :",
52
+ "lint": "eslint . --fix",
53
+ "perf": "node perf/check.js",
54
+ "prepare": "echo 'ready'",
55
+ "pretest": "yarn run lect && yarn run build",
56
+ "test": "c8 yarn run unit && yarn run examples && yarn run lint",
57
+ "unit": "uvu test"
66
58
  },
67
- "tap": {
68
- "check-coverage": false,
69
- "coverage-report": [
70
- "json-summary",
71
- "text"
72
- ],
73
- "node-arg": [
74
- "--no-warnings",
75
- "--experimental-loader",
76
- "@istanbuljs/esm-loader-hook"
59
+ "engines": {
60
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
61
+ },
62
+ "c8": {
63
+ "check-coverage": true,
64
+ "exclude": [
65
+ "**/test/**/*.*"
77
66
  ],
78
- "timeout": 0
67
+ "lines": 100
79
68
  },
80
69
  "lect": {
81
70
  "licence": {
82
71
  "extras": [
83
72
  ""
84
73
  ]
85
- },
86
- "req": "{ getByKey }",
87
- "various": {
88
- "devDependencies": [
89
- "@types/lodash.clonedeep",
90
- "object-path"
91
- ]
92
74
  }
93
75
  },
94
76
  "dependencies": {
95
- "@babel/runtime": "^7.16.0",
96
- "ast-monkey-traverse": "^3.0.4",
77
+ "ast-monkey-traverse": "^3.0.10",
97
78
  "lodash.clonedeep": "^4.5.0",
98
79
  "matcher": "^5.0.0"
99
80
  },
100
81
  "devDependencies": {
101
- "@babel/cli": "^7.16.0",
102
- "@babel/core": "^7.16.0",
103
- "@babel/node": "^7.16.0",
104
- "@babel/plugin-external-helpers": "^7.16.0",
105
- "@babel/plugin-proposal-class-properties": "^7.16.0",
106
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
107
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
108
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
109
- "@babel/plugin-transform-runtime": "^7.16.0",
110
- "@babel/preset-env": "^7.16.0",
111
- "@babel/preset-typescript": "^7.16.0",
112
- "@babel/register": "^7.16.0",
113
- "@istanbuljs/esm-loader-hook": "^0.1.2",
114
- "@rollup/plugin-babel": "^5.3.0",
115
- "@rollup/plugin-commonjs": "^21.0.1",
116
- "@rollup/plugin-json": "^4.1.0",
117
- "@rollup/plugin-node-resolve": "^13.0.6",
118
- "@rollup/plugin-strip": "^2.1.0",
119
- "@rollup/plugin-typescript": "^8.3.0",
120
- "@types/lodash.clonedeep": "^4.5.6",
121
- "@types/node": "^16.11.6",
122
- "@types/tap": "^15.0.5",
123
- "@typescript-eslint/eslint-plugin": "^5.3.0",
124
- "@typescript-eslint/parser": "^5.3.0",
125
- "core-js": "^3.19.1",
126
- "cross-env": "^7.0.3",
127
- "eslint": "^8.1.0",
128
- "lect": "^0.18.4",
129
- "object-path": "^0.11.8",
130
- "rollup": "^2.59.0",
131
- "rollup-plugin-ascii": "^0.0.3",
132
- "rollup-plugin-banner": "^0.2.1",
133
- "rollup-plugin-cleanup": "^3.2.1",
134
- "rollup-plugin-dts": "^4.0.0",
135
- "rollup-plugin-terser": "^7.0.2",
136
- "tap": "^15.0.10",
137
- "tslib": "^2.3.1",
138
- "typescript": "^4.4.4"
139
- },
140
- "engines": {
141
- "node": ">=12"
82
+ "@types/lodash.clonedeep": "^4.5.6"
142
83
  }
143
84
  }
package/types/index.d.ts CHANGED
File without changes
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;);"}}