object-grep
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.objectGrep=t():e.objectGrep=t()}(this,(function(){return(()=>{"use strict";var e={138:(e,t,r)=>{function n({target:e,searchExpr:t,depth:r,path:o,result:u}){return r<1||Object.keys(e).forEach((i=>{const c=o?`${o}.${i}`:i,a=e[i];i.match(t)&&(u.inKeys[c]=a),["string","number","boolean","undefined"].includes(typeof a)||null===a?String(a).match(t)&&(u.inValues[c]=a):n({searchExpr:t,result:u,path:c,target:a,depth:r-1})})),u}function o(e,t,r=20){const o=Object.create({short:function(){return{inKeys:Object.keys(this.inKeys),inValues:Object.keys(this.inValues)}}},{inValues:{writable:!0,configurable:!0,enumerable:!0,value:{}},inKeys:{writable:!0,configurable:!0,enumerable:!0,value:{}}});return t||(t=String(t)),n({target:e,searchExpr:t,depth:r,path:"",result:o})}r.r(t),r.d(t,{objectGrep:()=>o}),o.inject=function(){Object.defineProperty(Object.prototype,"grep",{enumerable:!1,value:function(e,t){return o(this,e,t)}})}}},t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(138)})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.objectGrep=t():e.objectGrep=t()}(this,(function(){return(()=>{"use strict";var e={138:(e,t,r)=>{function o({target:e,searchExpr:t,depth:r,path:n,result:c}){return r<1||Object.keys(e).forEach((i=>{const a=n?`${n}.${i}`:i,s=e[i];i.match(t)&&(c.inKeys[a]=s),["string","number","boolean","undefined"].includes(typeof s)||null===s?String(s).match(t)&&(c.inValues[a]=s):o({searchExpr:t,result:c,path:a,target:s,depth:r-1})})),c}function n(e,t,r=20){const n=Object.create({short:function(){return{inKeys:Object.keys(this.inKeys),inValues:Object.keys(this.inValues)}}},{inValues:{writable:!0,configurable:!0,enumerable:!0,value:{}},inKeys:{writable:!0,configurable:!0,enumerable:!0,value:{}}});return t||(t=String(t)),o({target:e,searchExpr:t,depth:r,path:"",result:n})}r.r(t),r.d(t,{objectGrep:()=>n});const c=Symbol("grep");n.inject=function(e="grep"){if(e in Object.prototype)throw new Error(`Object.prototype already has ${e}. Choose another name`);const t=function(e,t){return n(this,e,t)};t.symbol=c,Object.defineProperty(Object.prototype,e,{configurable:!0,enumerable:!1,value:t})},n.revoke=function(){const e=Object.prototype;Object.getOwnPropertyNames(Object.prototype).forEach((t=>{e[t]&&e[t].symbol&&e[t].symbol===c&&delete e[t]}))}}},t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{}};return e[o](n,n.exports,r),n.exports}return r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(138)})()})); |
{ | ||
"name": "object-grep", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "A javascript tool for searching text in keys and content inspired by linux grep", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -64,9 +64,29 @@ function grep({target, searchExpr, depth, path, result}) { | ||
objectGrep.inject = function () { | ||
Object.defineProperty(Object.prototype, 'grep', { | ||
const symbol = Symbol('grep'); | ||
objectGrep.inject = function (propertyName = 'grep') { | ||
if (propertyName in Object.prototype) { | ||
throw new Error(`Object.prototype already has ${propertyName}. Choose another name`); | ||
} | ||
const fn = function (regex, depth) { | ||
return objectGrep(this, regex, depth); | ||
}; | ||
fn.symbol = symbol; | ||
Object.defineProperty(Object.prototype, propertyName, { | ||
configurable: true, | ||
enumerable: false, | ||
value: function (regex, depth) { | ||
return objectGrep(this, regex, depth); | ||
value: fn | ||
}); | ||
}; | ||
objectGrep.revoke = function () { | ||
const prototype = Object.prototype; | ||
Object.getOwnPropertyNames(Object.prototype).forEach(propertyName => { | ||
if (prototype[propertyName] && prototype[propertyName].symbol && prototype[propertyName].symbol === symbol) { | ||
delete prototype[propertyName]; | ||
} | ||
}); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8889
75