@re-flex/object-path
Version:
Re-flex UTILS _> object-path
3 lines (2 loc) • 904 B
JavaScript
module.exports=/*#__PURE__*/function(){function t(t){this.source=t}var r=t.prototype;return r.parsingKey=function(t){return t.split(".").map(function(t){return Number.isNaN(Number(t))?t:Number(t)})},r.get=function(t){return t?this.parsingKey(t).reduce(function(t,r,e,n){return void 0===t||void 0===(null==t?void 0:t[r])?void 0:t=t[r]},this.source):this.source},r.set=function(t,r,e){if(void 0===e&&(e=!0),0!==t.length){var n=this.parsingKey(t);n.reduce(function(t,i,u){return u===n.length-1?(t[i]=r,!0):(void 0===t[i]&&e&&(t[i]={}),t[i])},this.source)}},r.push=function(t,r){var e=this.get(t);return!!Array.isArray(e)&&(e.push(r),this.set(t,e),!0)},r.del=function(t){if(0===t.length)return!1;var r=this.parsingKey(t);return r.reduce(function(t,e,n){return n===r.length-1?(delete t[e],!0):t[e]},this.source),!1},r.has=function(t){return void 0!==this.get(t)},t}();
//# sourceMappingURL=object-path.js.map