object-delete-key
Advanced tools
Comparing version 3.2.11 to 3.2.12
@@ -81,10 +81,10 @@ # Change Log | ||
- ✨ Various documentation and setup tweaks after we migrated to monorepo | ||
- ✨ Setup refresh: updated dependencies and all config files using automated tools | ||
- Various documentation and setup tweaks after we migrated to monorepo | ||
- Setup refresh: updated dependencies and all config files using automated tools | ||
## 1.5.0 (2018-10-24) | ||
- ✨ Updated all dependencies | ||
- ✨ Restored coveralls.io reporting | ||
- ✨ Restored unit test linting | ||
- Updated all dependencies | ||
- Restored coveralls.io reporting | ||
- Restored unit test linting | ||
@@ -95,23 +95,23 @@ ## 1.4.0 (2018-06-19) | ||
- ✨ Migrated to Bitbucket (to host repo + perform CI) and Codacy (for code quality audit) | ||
- ✨ Dropped BitHound (RIP) and Travis | ||
- Migrated to Bitbucket (to host repo + perform CI) and Codacy (for code quality audit) | ||
- Dropped BitHound (RIP) and Travis | ||
## 1.3.0 (2018-05-25) | ||
- ✨ Set up [Prettier](https://prettier.io) on a custom ESLint rule set. | ||
- ✨ Removed `package.lock` and `.editorconfig` | ||
- ✨ Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — there's no need to comment-out `console.log` statements or care about them not spilling into production. Now it's done automatically. | ||
- ✨ Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed. This is important because now code coverage is real again and now there are no excuses not to perfect it. | ||
- Set up [Prettier](https://prettier.io) on a custom ESLint rule set. | ||
- Removed `package.lock` and `.editorconfig` | ||
- Wired Rollup to remove comments from non-dev builds. This means we can now leave the `console.log`s in the source code — there's no need to comment-out `console.log` statements or care about them not spilling into production. Now it's done automatically. | ||
- Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed. This is important because now code coverage is real again and now there are no excuses not to perfect it. | ||
## 1.2.0 (2018-03-11) | ||
- ✨ Updated all dependencies | ||
- ✨ Switched from deprecated `posthtml-ast-is-empty` to `ast-is-empty` ([npm](https://www.npmjs.com/package/ast-is-empty), [GitLab](https://gitlab.com/codsen/codsen/tree/master/packages/ast-is-empty)) | ||
- Updated all dependencies | ||
- Switched from deprecated `posthtml-ast-is-empty` to `ast-is-empty` ([npm](https://www.npmjs.com/package/ast-is-empty), [GitLab](https://gitlab.com/codsen/codsen/tree/master/packages/ast-is-empty)) | ||
## 1.1.0 (2017-10-30) | ||
- ✨ Now accepts globs everywhere, see [matcher](https://github.com/sindresorhus/matcher)'s API which is driving the globbing. This comes from `ast-monkey` ([npm](https://www.npmjs.com/package/ast-monkey), [GitLab](https://gitlab.com/codsen/codsen/tree/master/packages/ast-monkey)) tapping `matcher`. | ||
- Now accepts globs everywhere, see [matcher](https://github.com/sindresorhus/matcher)'s API which is driving the globbing. This comes from `ast-monkey` ([npm](https://www.npmjs.com/package/ast-monkey), [GitLab](https://gitlab.com/codsen/codsen/tree/master/packages/ast-monkey)) tapping `matcher`. | ||
## 1.0.0 (2017-10-23) | ||
- ✨ First public release | ||
- First public release |
/** | ||
* @name object-delete-key | ||
* @fileoverview Delete keys from all arrays or plain objects, nested within anything, by key or by value or by both, and clean up afterwards. Accepts wildcards. | ||
* @version 3.2.11 | ||
* @version 3.2.12 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,2 +10,2 @@ * @license MIT | ||
import{find as y,get as m,drop as b,del as p}from"ast-monkey";import{isEmpty as v}from"ast-is-empty";import $ from"lodash.clonedeep";import{arrObjOrBoth as f}from"util-array-object-or-both";var d="3.2.11";var E=d,g={key:null,val:void 0,cleanup:!0,only:"any"};function I(i,u){function n(t){return t!=null}if(!n(i))throw new Error("object-delete-key/deleteKey(): [THROW_ID_01] Please provide the first argument, something to work upon.");let e={...g,...u};if(e.only=f(e.only,{msg:"object-delete-key/deleteKey(): [THROW_ID_03]",optsVarName:"resolvedOpts.only"}),!n(e.key)&&!n(e.val))throw new Error("object-delete-key/deleteKey(): [THROW_ID_04] Please provide at least a key or a value.");let l=$(i);if(e.cleanup){let t=y(l,{key:e.key,val:e.val,only:e.only}),o,r;for(;Array.isArray(t)&&t.length;){r=t[0].index;for(let s=1,a=t[0].path.length;s<a;s++)o=t[0].path[a-1-s],v(p(m(l,{index:o}),{key:e.key,val:e.val,only:e.only}))&&(r=o);l=b(l,{index:r}),t=y(l,{key:e.key,val:e.val,only:e.only})}return l}return p(l,{key:e.key,val:e.val,only:e.only})}export{g as defaults,I as deleteKey,E as version}; | ||
import{find as y,get as m,drop as b,del as p}from"ast-monkey";import{isEmpty as v}from"ast-is-empty";import $ from"lodash.clonedeep";import{arrObjOrBoth as f}from"util-array-object-or-both";var d="3.2.12";var E=d,g={key:null,val:void 0,cleanup:!0,only:"any"};function I(i,u){function n(t){return t!=null}if(!n(i))throw new Error("object-delete-key/deleteKey(): [THROW_ID_01] Please provide the first argument, something to work upon.");let e={...g,...u};if(e.only=f(e.only,{msg:"object-delete-key/deleteKey(): [THROW_ID_03]",optsVarName:"resolvedOpts.only"}),!n(e.key)&&!n(e.val))throw new Error("object-delete-key/deleteKey(): [THROW_ID_04] Please provide at least a key or a value.");let l=$(i);if(e.cleanup){let t=y(l,{key:e.key,val:e.val,only:e.only}),o,r;for(;Array.isArray(t)&&t.length;){r=t[0].index;for(let s=1,a=t[0].path.length;s<a;s++)o=t[0].path[a-1-s],v(p(m(l,{index:o}),{key:e.key,val:e.val,only:e.only}))&&(r=o);l=b(l,{index:r}),t=y(l,{key:e.key,val:e.val,only:e.only})}return l}return p(l,{key:e.key,val:e.val,only:e.only})}export{g as defaults,I as deleteKey,E as version}; |
/** | ||
* @name object-delete-key | ||
* @fileoverview Delete keys from all arrays or plain objects, nested within anything, by key or by value or by both, and clean up afterwards. Accepts wildcards. | ||
* @version 3.2.11 | ||
* @version 3.2.12 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -25,7 +25,7 @@ * @license MIT | ||
`);if(p){let u=ze(i.schema[g.path]).map(m=>`${m}`.toLowerCase());if(be.default.set(i.schema,g.path,u),(0,$r.default)(u,l).length)h.push(g.path);else if(d!==!0&&d!==!1&&!u.includes((0,$.default)(d).toLowerCase())||(d===!0||d===!1)&&!u.includes(String(d))&&!u.includes("boolean"))if(Array.isArray(d)&&i.acceptArrays){for(let m=0,_=d.length;m<_;m++)if(!u.includes((0,$.default)(d[m]).toLowerCase()))throw new TypeError(`${i.msg}: ${i.optsVarName}.${g.path}.${m}, the ${m}th element (equal to ${JSON.stringify(d[m],null,0)}) is of a type ${(0,$.default)(d[m]).toLowerCase()}, but only the following are allowed by the ${i.optsVarName}.schema: ${u.join(", ")}`)}else throw new TypeError(`${i.msg}: ${i.optsVarName}.${g.path} was customised to ${(0,$.default)(d)!=="string"?'"':""}${JSON.stringify(d,null,0)}${(0,$.default)(d)!=="string"?'"':""} (type: ${(0,$.default)(d).toLowerCase()}) which is not among the allowed types in schema (which is equal to ${JSON.stringify(u,null,0)})`)}else if(t&&s(t)&&c){let u=be.default.get(t,g.path);if(i.acceptArrays&&Array.isArray(d)&&!i.acceptArraysIgnore.includes(o)){if(!d.every(m=>(0,$.default)(m).toLowerCase()===(0,$.default)(t[o]).toLowerCase()))throw new TypeError(`${i.msg}: ${i.optsVarName}.${g.path} was customised to be array, but not all of its elements are ${(0,$.default)(t[o]).toLowerCase()}-type`)}else if((0,$.default)(d)!==(0,$.default)(u))throw new TypeError(`${i.msg}: ${i.optsVarName}.${g.path} was customised to ${(0,$.default)(d).toLowerCase()==="string"?"":'"'}${JSON.stringify(d,null,0)}${(0,$.default)(d).toLowerCase()==="string"?"":'"'} which is not ${(0,$.default)(u).toLowerCase()} but ${(0,$.default)(d).toLowerCase()}`)}return d})}function Ze(e,t,r){_s(e,t,r)}var V=T(Ee(),1);function S(e){if(typeof e=="string")return!e.trim();if(!["object","string"].includes(typeof e)||!e)return!1;let t=!0;return e=H(e,(r,n,s,a)=>{let y=n!==void 0?n:r;return typeof y=="string"&&y.trim()&&(t=!1,a.now=!0),y}),t}var N=T(pe(),1);function $s(e){return(0,N.default)(e)?!Object.keys(e).length:Array.isArray(e)||typeof e=="string"?!e.length:!1}var xs={hungryForWhitespace:!1,matchStrictly:!1,verboseWhenMismatches:!1,useWildcards:!1};function ve(e,t,r){let n,s,a,y=0,l=b(b({},xs),r);if(l.hungryForWhitespace&&l.matchStrictly&&(0,N.default)(e)&&S(e)&&(0,N.default)(t)&&!Object.keys(t).length)return!0;if((!l.hungryForWhitespace||l.hungryForWhitespace&&!S(e)&&S(t))&&(0,N.default)(e)&&Object.keys(e).length!==0&&(0,N.default)(t)&&Object.keys(t).length===0||(0,V.default)(e)!==(0,V.default)(t)&&(!l.hungryForWhitespace||l.hungryForWhitespace&&!S(e)))return!1;if(typeof e=="string"&&typeof t=="string")return l.hungryForWhitespace&&S(e)&&S(t)?!0:l.verboseWhenMismatches?e===t?!0:`Given string ${t} is not matched! We have ${e} on the other end.`:l.useWildcards?R(e,t,{caseSensitive:!0}):e===t;if(Array.isArray(e)&&Array.isArray(t)){if(l.hungryForWhitespace&&S(t)&&(!l.matchStrictly||l.matchStrictly&&e.length===t.length))return!0;if(!l.hungryForWhitespace&&t.length>e.length||l.matchStrictly&&t.length!==e.length)return l.verboseWhenMismatches?`The length of a given array, ${JSON.stringify(t,null,4)} is ${t.length} but the length of an array on the other end, ${JSON.stringify(e,null,4)} is ${e.length}`:!1;if(t.length===0)return e.length===0?!0:l.verboseWhenMismatches?`The given array has no elements, but the array on the other end, ${JSON.stringify(e,null,4)} does have some`:!1;for(let i=0,h=t.length;i<h;i++){a=!1;for(let o=y,f=e.length;o<f;o++)if(y+=1,ve(e[o],t[i],l)===!0){a=!0;break}if(!a)return l.verboseWhenMismatches?`The given array ${JSON.stringify(t,null,4)} is not a subset of an array on the other end, ${JSON.stringify(e,null,4)}`:!1}}else if((0,N.default)(e)&&(0,N.default)(t)){if(n=new Set(Object.keys(t)),s=new Set(Object.keys(e)),l.matchStrictly&&n.size!==s.size){if(!l.verboseWhenMismatches)return!1;let i=new Set([...n].filter(g=>!s.has(g))),h=i.size?` First object has unique keys: ${JSON.stringify(i,null,4)}.`:"",o=new Set([...s].filter(g=>!n.has(g))),f=o.size?` Second object has unique keys: | ||
${JSON.stringify(o,null,4)}.`:"";return`When matching strictly, we found that both objects have different amount of keys.${h}${f}`}for(let i of n){if(!Object.prototype.hasOwnProperty.call(e,i))return!l.useWildcards||l.useWildcards&&!i.includes("*")?l.verboseWhenMismatches?`The given object has key "${i}" which the other-one does not have.`:!1:Object.keys(e).some(h=>R(h,i,{caseSensitive:!0}))?!0:l.verboseWhenMismatches?`The given object has key "${i}" which the other-one does not have.`:!1;if(e[i]!=null&&(0,V.default)(e[i])!==(0,V.default)(t[i])){if(!(S(e[i])&&S(t[i])&&l.hungryForWhitespace))return l.verboseWhenMismatches?`The given key ${i} is of a different type on both objects. On the first-one, it's ${(0,V.default)(t[i])}, on the second-one, it's ${(0,V.default)(e[i])}`:!1}else if(ve(e[i],t[i],l)!==!0)return l.verboseWhenMismatches?`The given piece ${JSON.stringify(t[i],null,4)} and ${JSON.stringify(e[i],null,4)} don't match.`:!1}}else return l.hungryForWhitespace&&S(e)&&S(t)&&(!l.matchStrictly||l.matchStrictly&&$s(t))?!0:e===t;return!0}function k(e){return e!=null}function we(e,t){return typeof e!=typeof t?!1:!!ve(e,t,{matchStrictly:!0,useWildcards:!0})}function Oe(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function _e(e,t){let r=b({},t),n={count:0,gatherPath:[],finding:null},s=[],a=!1,y=!1;k(r.key)&&r.val===void 0&&(a=!0),!k(r.key)&&r.val!==void 0&&(y=!0);let l=e;return r.mode==="arrayFirstOnly"&&Array.isArray(l)&&l.length&&(l=[l[0]]),l=H(l,(i,h,o)=>{let f;if(n.count+=1,n.gatherPath.length=o.depth,n.gatherPath.push(n.count),r.mode==="get")n.count===r.index&&(o.parentType==="object"?(n.finding={},n.finding[i]=h):n.finding=i);else if(r.mode==="find"||r.mode==="del")if((r.only==="any"||r.only==="array"&&o.parentType==="array"||r.only==="object"&&o.parentType!=="array")&&(a&&we(i,r.key)||y&&we(h,r.val)||!a&&!y&&we(i,r.key)&&we(h,r.val)))if(r.mode==="find")f={index:n.count,key:i,val:h,path:[...n.gatherPath]},s.push(f);else return NaN;else return o.parentType==="object"?h:i;return r.mode==="set"&&n.count===r.index?r.val:r.mode==="drop"&&n.count===r.index?NaN:r.mode==="arrayFirstOnly"?o.parentType==="object"&&Array.isArray(h)?[h[0]]:k(i)&&Array.isArray(i)?[i[0]]:o.parentType==="object"?h:i:o.parentType==="object"?h:i}),r.mode==="get"?n.finding:r.mode==="find"?s:l}function et(e,t){if(!k(e))throw new Error("ast-monkey/main.js/find(): [THROW_ID_02] Please provide the input");if(!Oe(t)||t.key===void 0&&t.val===void 0)throw new Error("ast-monkey/main.js/find(): [THROW_ID_03] Please provide resolvedOpts.key or resolvedOpts.val");let r=b({},t);return Ze(r,null,{schema:{key:["null","string"],val:"any",only:["undefined","null","string"]},msg:"ast-monkey/get(): [THROW_ID_04*]"}),typeof r.only=="string"&&r.only.length?r.only=z(r.only,{optsVarName:"resolvedOpts.only",msg:"ast-monkey/find(): [THROW_ID_05*]"}):r.only="any",_e(e,A(b({},r),{mode:"find"}))}function xr(e,t){if(!k(e))throw new Error("ast-monkey/main.js/get(): [THROW_ID_06] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/get(): [THROW_ID_07] Please provide the resolvedOpts");if(!k(t.index))throw new Error("ast-monkey/main.js/get(): [THROW_ID_08] Please provide resolvedOpts.index");let r=b({},t);if(typeof r.index=="string"&&/^\d+$/.test(r.index))r.index=+r.index;else if(!Number.isInteger(r.index))throw new Error(`ast-monkey/main.js/get(): [THROW_ID_11] resolvedOpts.index must be a natural number. It was given as: ${r.index} (type ${typeof r.index})`);return _e(e,A(b({},r),{mode:"get"}))}function jr(e,t){if(!k(e))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_19] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_20] Please provide the input");if(!k(t.index))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_21] Please provide resolvedOpts.index");let r=b({},t);if(typeof r.index=="string"&&/^\d+$/.test(r.index))r.index=+r.index;else if(!Number.isInteger(r.index))throw new Error(`ast-monkey/main.js/drop(): [THROW_ID_23] resolvedOpts.index must be a natural number. It was given as: ${r.index}`);return _e(e,A(b({},r),{mode:"drop"}))}function tt(e,t){if(!k(e))throw new Error("ast-monkey/main.js/del(): [THROW_ID_26] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/del(): [THROW_ID_27] Please provide the resolvedOpts object");if(!k(t.key)&&t.val===void 0)throw new Error("ast-monkey/main.js/del(): [THROW_ID_28] Please provide resolvedOpts.key or resolvedOpts.val");let r=b({},t);return Ze(r,null,{schema:{key:[null,"string"],val:"any",only:["undefined","null","string"]},msg:"ast-monkey/drop(): [THROW_ID_29*]"}),typeof r.only=="string"&&r.only.length?r.only=z(r.only,{msg:"ast-monkey/del(): [THROW_ID_30*]",optsVarName:"resolvedOpts.only"}):r.only="any",_e(e,A(b({},r),{mode:"del"}))}var Sr=T(pe(),1);function $e(e){let t,r,n=!0;if(Array.isArray(e)){if(e.length===0)return!0;for(t=0,r=e.length;t<r;t++){if(n=$e(e[t]),n===null)return null;if(!n)return!1}}else if((0,Sr.default)(e)){if(Object.keys(e).length===0)return!0;for(t=0,r=Object.keys(e).length;t<r;t++){if(n=$e(e[Object.keys(e)[t]]),n===null)return null;if(!n)return!1}}else if(typeof e=="string"){if(e.length!==0)return!1}else return null;return n}var Ar=T(Ge(),1);var Tr="3.2.11";var Ss=Tr,kr={key:null,val:void 0,cleanup:!0,only:"any"};function Ts(e,t){function r(a){return a!=null}if(!r(e))throw new Error("object-delete-key/deleteKey(): [THROW_ID_01] Please provide the first argument, something to work upon.");let n=b(b({},kr),t);if(n.only=z(n.only,{msg:"object-delete-key/deleteKey(): [THROW_ID_03]",optsVarName:"resolvedOpts.only"}),!r(n.key)&&!r(n.val))throw new Error("object-delete-key/deleteKey(): [THROW_ID_04] Please provide at least a key or a value.");let s=(0,Ar.default)(e);if(n.cleanup){let a=et(s,{key:n.key,val:n.val,only:n.only}),y,l;for(;Array.isArray(a)&&a.length;){l=a[0].index;for(let i=1,h=a[0].path.length;i<h;i++)y=a[0].path[h-1-i],$e(tt(xr(s,{index:y}),{key:n.key,val:n.val,only:n.only}))&&(l=y);s=jr(s,{index:l}),a=et(s,{key:n.key,val:n.val,only:n.only})}return s}return tt(s,{key:n.key,val:n.val,only:n.only})}return Hr(As);})(); | ||
${JSON.stringify(o,null,4)}.`:"";return`When matching strictly, we found that both objects have different amount of keys.${h}${f}`}for(let i of n){if(!Object.prototype.hasOwnProperty.call(e,i))return!l.useWildcards||l.useWildcards&&!i.includes("*")?l.verboseWhenMismatches?`The given object has key "${i}" which the other-one does not have.`:!1:Object.keys(e).some(h=>R(h,i,{caseSensitive:!0}))?!0:l.verboseWhenMismatches?`The given object has key "${i}" which the other-one does not have.`:!1;if(e[i]!=null&&(0,V.default)(e[i])!==(0,V.default)(t[i])){if(!(S(e[i])&&S(t[i])&&l.hungryForWhitespace))return l.verboseWhenMismatches?`The given key ${i} is of a different type on both objects. On the first-one, it's ${(0,V.default)(t[i])}, on the second-one, it's ${(0,V.default)(e[i])}`:!1}else if(ve(e[i],t[i],l)!==!0)return l.verboseWhenMismatches?`The given piece ${JSON.stringify(t[i],null,4)} and ${JSON.stringify(e[i],null,4)} don't match.`:!1}}else return l.hungryForWhitespace&&S(e)&&S(t)&&(!l.matchStrictly||l.matchStrictly&&$s(t))?!0:e===t;return!0}function k(e){return e!=null}function we(e,t){return typeof e!=typeof t?!1:!!ve(e,t,{matchStrictly:!0,useWildcards:!0})}function Oe(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function _e(e,t){let r=b({},t),n={count:0,gatherPath:[],finding:null},s=[],a=!1,y=!1;k(r.key)&&r.val===void 0&&(a=!0),!k(r.key)&&r.val!==void 0&&(y=!0);let l=e;return r.mode==="arrayFirstOnly"&&Array.isArray(l)&&l.length&&(l=[l[0]]),l=H(l,(i,h,o)=>{let f;if(n.count+=1,n.gatherPath.length=o.depth,n.gatherPath.push(n.count),r.mode==="get")n.count===r.index&&(o.parentType==="object"?(n.finding={},n.finding[i]=h):n.finding=i);else if(r.mode==="find"||r.mode==="del")if((r.only==="any"||r.only==="array"&&o.parentType==="array"||r.only==="object"&&o.parentType!=="array")&&(a&&we(i,r.key)||y&&we(h,r.val)||!a&&!y&&we(i,r.key)&&we(h,r.val)))if(r.mode==="find")f={index:n.count,key:i,val:h,path:[...n.gatherPath]},s.push(f);else return NaN;else return o.parentType==="object"?h:i;return r.mode==="set"&&n.count===r.index?r.val:r.mode==="drop"&&n.count===r.index?NaN:r.mode==="arrayFirstOnly"?o.parentType==="object"&&Array.isArray(h)?[h[0]]:k(i)&&Array.isArray(i)?[i[0]]:o.parentType==="object"?h:i:o.parentType==="object"?h:i}),r.mode==="get"?n.finding:r.mode==="find"?s:l}function et(e,t){if(!k(e))throw new Error("ast-monkey/main.js/find(): [THROW_ID_02] Please provide the input");if(!Oe(t)||t.key===void 0&&t.val===void 0)throw new Error("ast-monkey/main.js/find(): [THROW_ID_03] Please provide resolvedOpts.key or resolvedOpts.val");let r=b({},t);return Ze(r,null,{schema:{key:["null","string"],val:"any",only:["undefined","null","string"]},msg:"ast-monkey/get(): [THROW_ID_04*]"}),typeof r.only=="string"&&r.only.length?r.only=z(r.only,{optsVarName:"resolvedOpts.only",msg:"ast-monkey/find(): [THROW_ID_05*]"}):r.only="any",_e(e,A(b({},r),{mode:"find"}))}function xr(e,t){if(!k(e))throw new Error("ast-monkey/main.js/get(): [THROW_ID_06] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/get(): [THROW_ID_07] Please provide the resolvedOpts");if(!k(t.index))throw new Error("ast-monkey/main.js/get(): [THROW_ID_08] Please provide resolvedOpts.index");let r=b({},t);if(typeof r.index=="string"&&/^\d+$/.test(r.index))r.index=+r.index;else if(!Number.isInteger(r.index))throw new Error(`ast-monkey/main.js/get(): [THROW_ID_11] resolvedOpts.index must be a natural number. It was given as: ${r.index} (type ${typeof r.index})`);return _e(e,A(b({},r),{mode:"get"}))}function jr(e,t){if(!k(e))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_19] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_20] Please provide the input");if(!k(t.index))throw new Error("ast-monkey/main.js/drop(): [THROW_ID_21] Please provide resolvedOpts.index");let r=b({},t);if(typeof r.index=="string"&&/^\d+$/.test(r.index))r.index=+r.index;else if(!Number.isInteger(r.index))throw new Error(`ast-monkey/main.js/drop(): [THROW_ID_23] resolvedOpts.index must be a natural number. It was given as: ${r.index}`);return _e(e,A(b({},r),{mode:"drop"}))}function tt(e,t){if(!k(e))throw new Error("ast-monkey/main.js/del(): [THROW_ID_26] Please provide the input");if(!Oe(t))throw new Error("ast-monkey/main.js/del(): [THROW_ID_27] Please provide the resolvedOpts object");if(!k(t.key)&&t.val===void 0)throw new Error("ast-monkey/main.js/del(): [THROW_ID_28] Please provide resolvedOpts.key or resolvedOpts.val");let r=b({},t);return Ze(r,null,{schema:{key:[null,"string"],val:"any",only:["undefined","null","string"]},msg:"ast-monkey/drop(): [THROW_ID_29*]"}),typeof r.only=="string"&&r.only.length?r.only=z(r.only,{msg:"ast-monkey/del(): [THROW_ID_30*]",optsVarName:"resolvedOpts.only"}):r.only="any",_e(e,A(b({},r),{mode:"del"}))}var Sr=T(pe(),1);function $e(e){let t,r,n=!0;if(Array.isArray(e)){if(e.length===0)return!0;for(t=0,r=e.length;t<r;t++){if(n=$e(e[t]),n===null)return null;if(!n)return!1}}else if((0,Sr.default)(e)){if(Object.keys(e).length===0)return!0;for(t=0,r=Object.keys(e).length;t<r;t++){if(n=$e(e[Object.keys(e)[t]]),n===null)return null;if(!n)return!1}}else if(typeof e=="string"){if(e.length!==0)return!1}else return null;return n}var Ar=T(Ge(),1);var Tr="3.2.12";var Ss=Tr,kr={key:null,val:void 0,cleanup:!0,only:"any"};function Ts(e,t){function r(a){return a!=null}if(!r(e))throw new Error("object-delete-key/deleteKey(): [THROW_ID_01] Please provide the first argument, something to work upon.");let n=b(b({},kr),t);if(n.only=z(n.only,{msg:"object-delete-key/deleteKey(): [THROW_ID_03]",optsVarName:"resolvedOpts.only"}),!r(n.key)&&!r(n.val))throw new Error("object-delete-key/deleteKey(): [THROW_ID_04] Please provide at least a key or a value.");let s=(0,Ar.default)(e);if(n.cleanup){let a=et(s,{key:n.key,val:n.val,only:n.only}),y,l;for(;Array.isArray(a)&&a.length;){l=a[0].index;for(let i=1,h=a[0].path.length;i<h;i++)y=a[0].path[h-1-i],$e(tt(xr(s,{index:y}),{key:n.key,val:n.val,only:n.only}))&&(l=y);s=jr(s,{index:l}),a=et(s,{key:n.key,val:n.val,only:n.only})}return s}return tt(s,{key:n.key,val:n.val,only:n.only})}return Hr(As);})(); | ||
/** | ||
* @name arrayiffy-if-string | ||
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else. | ||
* @version 4.1.1 | ||
* @version 4.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -38,3 +38,3 @@ * @license MIT | ||
* @fileoverview Compare anything: AST, objects, arrays, strings and nested thereof | ||
* @version 3.2.11 | ||
* @version 3.2.12 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -47,3 +47,3 @@ * @license MIT | ||
* @fileoverview Does AST contain only empty space? | ||
* @version 3.2.1 | ||
* @version 3.2.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -56,3 +56,3 @@ * @license MIT | ||
* @fileoverview Find out, is nested array/object/string/AST tree is empty | ||
* @version 3.1.1 | ||
* @version 3.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -65,3 +65,3 @@ * @license MIT | ||
* @fileoverview Traverse and edit AST | ||
* @version 8.1.11 | ||
* @version 8.1.12 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -74,3 +74,3 @@ * @license MIT | ||
* @fileoverview Utility library to traverse AST | ||
* @version 3.1.1 | ||
* @version 3.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -83,3 +83,3 @@ * @license MIT | ||
* @fileoverview Utility library of AST helper functions | ||
* @version 2.1.1 | ||
* @version 2.1.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -92,3 +92,3 @@ * @license MIT | ||
* @fileoverview Validate options object | ||
* @version 7.2.1 | ||
* @version 7.2.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -101,3 +101,3 @@ * @license MIT | ||
* @fileoverview Validate and normalise user choice: array, object or both? | ||
* @version 4.2.1 | ||
* @version 4.2.2 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -104,0 +104,0 @@ * @license MIT |
{ | ||
"name": "object-delete-key", | ||
"version": "3.2.11", | ||
"version": "3.2.12", | ||
"description": "Delete keys from all arrays or plain objects, nested within anything, by key or by value or by both, and clean up afterwards. Accepts wildcards.", | ||
@@ -77,6 +77,6 @@ "keywords": [ | ||
"dependencies": { | ||
"ast-is-empty": "^3.1.1", | ||
"ast-monkey": "^8.1.11", | ||
"ast-is-empty": "^3.1.2", | ||
"ast-monkey": "^8.1.12", | ||
"lodash.clonedeep": "^4.5.0", | ||
"util-array-object-or-both": "^4.2.1" | ||
"util-array-object-or-both": "^4.2.2" | ||
}, | ||
@@ -83,0 +83,0 @@ "devDependencies": { |
58446
Updatedast-is-empty@^3.1.2
Updatedast-monkey@^8.1.12