dot-object
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -28,3 +28,3 @@ { | ||
}, | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"homepage": "https://github.com/rhalff/dot-object", | ||
@@ -31,0 +31,0 @@ "moduleType": [ |
# ChangeLog | ||
## 2019-07-18 Version 1.8.1 | ||
* allows allow to set root level property using dot.str | ||
## 2019-07-18 Version 1.8.0 | ||
@@ -4,0 +7,0 @@ * [[`cdc691424b`](https://github.com/rhalff/dot-object/commit/cdc691424b)] - Options to remove array elements and reindex the array. (Fixed by MechJosh0 #36) |
@@ -168,3 +168,3 @@ (function(global, exportName) { | ||
this._fill(path.split(this.separator), obj, v, mod) | ||
} else if (!hasOwnProperty.call(obj, path) || this.override) { | ||
} else { | ||
obj[path] = _process(v, mod) | ||
@@ -171,0 +171,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t){"use strict";function s(t,r){var e,i;if("function"==typeof r)void 0!==(i=r(t))&&(t=i);else if(Array.isArray(r))for(e=0;e<r.length;e++)void 0!==(i=r[e](t))&&(t=i);return t}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function o(t){return Object(t)===t}function c(t){return 0===Object.keys(t).length}function u(t,r){return 0<=t.indexOf("[")&&(t=t.replace(/\[/g,".").replace(/]/g,"")),t.split(r)}var a=Object.prototype.hasOwnProperty;function i(t,r,e){if(!(this instanceof i))return new i(t,r,e);void 0===r&&(r=!1),void 0===e&&(e=!0),this.separator=t||".",this.override=r,this.useArray=e,this.keepArray=!1,this.cleanup=[]}var e=new i(".",!1,!0);function r(t){return function(){return e[t].apply(e,arguments)}}i.prototype._fill=function(t,r,e,i){var n=t.shift();if(0<t.length){if(r[n]=r[n]||(this.useArray&&function(t){return/^\d+$/.test(t)}(t[0])?[]:{}),!o(r[n])){if(!this.override){if(!o(e)||!c(e))throw new Error("Trying to redefine `"+n+"` which is a "+typeof r[n]);return}r[n]={}}this._fill(t,r[n],e,i)}else{if(!this.override&&o(r[n])&&!c(r[n])){if(!o(e)||!c(e))throw new Error("Trying to redefine non-empty obj['"+n+"']");return}r[n]=s(e,i)}},i.prototype.object=function(i,n){var o=this;return Object.keys(i).forEach(function(t){var r=void 0===n?null:n[t],e=u(t,o.separator).join(o.separator);-1!==e.indexOf(o.separator)?(o._fill(e.split(o.separator),i,i[t],r),delete i[t]):o.override&&(i[t]=s(i[t],r))}),i},i.prototype.str=function(t,r,e,i){return-1!==t.indexOf(this.separator)?this._fill(t.split(this.separator),e,r,i):a.call(e,t)&&!this.override||(e[t]=s(r,i)),e},i.prototype.pick=function(t,r,e,i){var n,o,s,c,f,p,a;for(o=u(t,this.separator),n=0;n<o.length;n++){if(p=o[n],a=r,c="-"===p[0]&&Array.isArray(a)&&/^-\d+$/.test(p)?a.length+parseInt(p,10):p,!(r&&"object"==typeof r&&c in r))return;if(n===o.length-1)return e?(s=r[c],i&&Array.isArray(r)?r.splice(c,1):delete r[c],Array.isArray(r)&&(f=o.slice(0,-1).join("."),-1===this.cleanup.indexOf(f)&&this.cleanup.push(f)),s):r[c];r=r[c]}return e&&Array.isArray(r)&&(r=r.filter(function(t){return void 0!==t})),r},i.prototype.delete=function(t,r){return this.remove(t,r,!0)},i.prototype.remove=function(t,r,e){var i;if(this.cleanup=[],Array.isArray(t)){for(i=0;i<t.length;i++)this.pick(t[i],r,!0,e);return e||this._cleanup(r),r}return this.pick(t,r,!0,e)},i.prototype._cleanup=function(t){var r,e,i,n;if(this.cleanup.length){for(e=0;e<this.cleanup.length;e++)r=(r=(n=(i=this.cleanup[e].split(".")).splice(0,-1).join("."))?this.pick(n,t):t)[i[0]].filter(function(t){return void 0!==t}),this.set(this.cleanup[e],r,t);this.cleanup=[]}},i.prototype.del=i.prototype.remove,i.prototype.move=function(t,r,e,i,n){return"function"==typeof i||Array.isArray(i)?this.set(r,s(this.pick(t,e,!0),i),e,n):(n=i,this.set(r,this.pick(t,e,!0),e,n)),e},i.prototype.transfer=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(this.pick(t,e,!0),n),i,o):(o=n,this.set(r,this.pick(t,e,!0),i,o)),i},i.prototype.copy=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(JSON.parse(JSON.stringify(this.pick(t,e,!1))),n),i,o):(o=n,this.set(r,this.pick(t,e,!1),i,o)),i},i.prototype.set=function(t,r,e,i){var n,o,s,c;if(void 0===r)return e;for(s=u(t,this.separator),n=0;n<s.length;n++){if(c=s[n],n===s.length-1)if(i&&p(r)&&p(e[c]))for(o in r)a.call(r,o)&&(e[c][o]=r[o]);else if(i&&Array.isArray(e[c])&&Array.isArray(r))for(var f=0;f<r.length;f++)e[s[n]].push(r[f]);else e[c]=r;else a.call(e,c)&&(p(e[c])||Array.isArray(e[c]))||(/^\d+$/.test(s[n+1])?e[c]=[]:e[c]={});e=e[c]}return e},i.prototype.transform=function(r,e,i){return e=e||{},i=i||{},Object.keys(r).forEach(function(t){this.set(r[t],this.pick(t,e),i)}.bind(this)),i},i.prototype.dot=function(r,e,i){return e=e||{},i=i||[],Object.keys(r).forEach(function(t){if(o(r[t])&&(p(r[t])&&!c(r[t])||Array.isArray(r[t])&&!this.keepArray&&0!==r[t].length))return this.dot(r[t],e,i.concat(t));e[i.concat(t).join(this.separator)]=r[t]}.bind(this)),e},i.pick=r("pick"),i.move=r("move"),i.transfer=r("transfer"),i.transform=r("transform"),i.copy=r("copy"),i.object=r("object"),i.str=r("str"),i.set=r("set"),i.del=i.remove=r("remove"),i.dot=r("dot"),["override","overwrite"].forEach(function(t){Object.defineProperty(i,t,{get:function(){return e.override},set:function(t){e.override=!!t}})}),["useArray","keepArray"].forEach(function(r){Object.defineProperty(i,r,{get:function(){return e[r]},set:function(t){e[r]=t}})}),i._process=s,"function"==typeof define&&define.amd?define(function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:t.DotObject=i}(this); | ||
!function(t){"use strict";function s(t,r){var e,i;if("function"==typeof r)void 0!==(i=r(t))&&(t=i);else if(Array.isArray(r))for(e=0;e<r.length;e++)void 0!==(i=r[e](t))&&(t=i);return t}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function o(t){return Object(t)===t}function f(t){return 0===Object.keys(t).length}function u(t,r){return 0<=t.indexOf("[")&&(t=t.replace(/\[/g,".").replace(/]/g,"")),t.split(r)}var a=Object.prototype.hasOwnProperty;function i(t,r,e){if(!(this instanceof i))return new i(t,r,e);void 0===r&&(r=!1),void 0===e&&(e=!0),this.separator=t||".",this.override=r,this.useArray=e,this.keepArray=!1,this.cleanup=[]}var e=new i(".",!1,!0);function r(t){return function(){return e[t].apply(e,arguments)}}i.prototype._fill=function(t,r,e,i){var n=t.shift();if(0<t.length){if(r[n]=r[n]||(this.useArray&&function(t){return/^\d+$/.test(t)}(t[0])?[]:{}),!o(r[n])){if(!this.override){if(!o(e)||!f(e))throw new Error("Trying to redefine `"+n+"` which is a "+typeof r[n]);return}r[n]={}}this._fill(t,r[n],e,i)}else{if(!this.override&&o(r[n])&&!f(r[n])){if(!o(e)||!f(e))throw new Error("Trying to redefine non-empty obj['"+n+"']");return}r[n]=s(e,i)}},i.prototype.object=function(i,n){var o=this;return Object.keys(i).forEach(function(t){var r=void 0===n?null:n[t],e=u(t,o.separator).join(o.separator);-1!==e.indexOf(o.separator)?(o._fill(e.split(o.separator),i,i[t],r),delete i[t]):o.override&&(i[t]=s(i[t],r))}),i},i.prototype.str=function(t,r,e,i){return-1!==t.indexOf(this.separator)?this._fill(t.split(this.separator),e,r,i):e[t]=s(r,i),e},i.prototype.pick=function(t,r,e,i){var n,o,s,f,c,p,a;for(o=u(t,this.separator),n=0;n<o.length;n++){if(p=o[n],a=r,f="-"===p[0]&&Array.isArray(a)&&/^-\d+$/.test(p)?a.length+parseInt(p,10):p,!(r&&"object"==typeof r&&f in r))return;if(n===o.length-1)return e?(s=r[f],i&&Array.isArray(r)?r.splice(f,1):delete r[f],Array.isArray(r)&&(c=o.slice(0,-1).join("."),-1===this.cleanup.indexOf(c)&&this.cleanup.push(c)),s):r[f];r=r[f]}return e&&Array.isArray(r)&&(r=r.filter(function(t){return void 0!==t})),r},i.prototype.delete=function(t,r){return this.remove(t,r,!0)},i.prototype.remove=function(t,r,e){var i;if(this.cleanup=[],Array.isArray(t)){for(i=0;i<t.length;i++)this.pick(t[i],r,!0,e);return e||this._cleanup(r),r}return this.pick(t,r,!0,e)},i.prototype._cleanup=function(t){var r,e,i,n;if(this.cleanup.length){for(e=0;e<this.cleanup.length;e++)r=(r=(n=(i=this.cleanup[e].split(".")).splice(0,-1).join("."))?this.pick(n,t):t)[i[0]].filter(function(t){return void 0!==t}),this.set(this.cleanup[e],r,t);this.cleanup=[]}},i.prototype.del=i.prototype.remove,i.prototype.move=function(t,r,e,i,n){return"function"==typeof i||Array.isArray(i)?this.set(r,s(this.pick(t,e,!0),i),e,n):(n=i,this.set(r,this.pick(t,e,!0),e,n)),e},i.prototype.transfer=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(this.pick(t,e,!0),n),i,o):(o=n,this.set(r,this.pick(t,e,!0),i,o)),i},i.prototype.copy=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(JSON.parse(JSON.stringify(this.pick(t,e,!1))),n),i,o):(o=n,this.set(r,this.pick(t,e,!1),i,o)),i},i.prototype.set=function(t,r,e,i){var n,o,s,f;if(void 0===r)return e;for(s=u(t,this.separator),n=0;n<s.length;n++){if(f=s[n],n===s.length-1)if(i&&p(r)&&p(e[f]))for(o in r)a.call(r,o)&&(e[f][o]=r[o]);else if(i&&Array.isArray(e[f])&&Array.isArray(r))for(var c=0;c<r.length;c++)e[s[n]].push(r[c]);else e[f]=r;else a.call(e,f)&&(p(e[f])||Array.isArray(e[f]))||(/^\d+$/.test(s[n+1])?e[f]=[]:e[f]={});e=e[f]}return e},i.prototype.transform=function(r,e,i){return e=e||{},i=i||{},Object.keys(r).forEach(function(t){this.set(r[t],this.pick(t,e),i)}.bind(this)),i},i.prototype.dot=function(r,e,i){return e=e||{},i=i||[],Object.keys(r).forEach(function(t){if(o(r[t])&&(p(r[t])&&!f(r[t])||Array.isArray(r[t])&&!this.keepArray&&0!==r[t].length))return this.dot(r[t],e,i.concat(t));e[i.concat(t).join(this.separator)]=r[t]}.bind(this)),e},i.pick=r("pick"),i.move=r("move"),i.transfer=r("transfer"),i.transform=r("transform"),i.copy=r("copy"),i.object=r("object"),i.str=r("str"),i.set=r("set"),i.del=i.remove=r("remove"),i.dot=r("dot"),["override","overwrite"].forEach(function(t){Object.defineProperty(i,t,{get:function(){return e.override},set:function(t){e.override=!!t}})}),["useArray","keepArray"].forEach(function(r){Object.defineProperty(i,r,{get:function(){return e[r]},set:function(t){e[r]=t}})}),i._process=s,"function"==typeof define&&define.amd?define(function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:t.DotObject=i}(this); |
@@ -166,3 +166,3 @@ 'use strict' | ||
this._fill(path.split(this.separator), obj, v, mod) | ||
} else if (!hasOwnProperty.call(obj, path) || this.override) { | ||
} else { | ||
obj[path] = _process(v, mod) | ||
@@ -169,0 +169,0 @@ } |
{ | ||
"name": "dot-object", | ||
"description": "dot-object makes it possible to transform and read (JSON) objects using dot notation.", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"author": { | ||
@@ -33,5 +33,7 @@ "name": "Rob Halff", | ||
"eslint": "^6.0.1", | ||
"eslint-config-standard": "^13.0.1", | ||
"eslint-plugin-import": "^2.18.0", | ||
"eslint-plugin-node": "^9.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"gulp": "^4.0.2", | ||
@@ -38,0 +40,0 @@ "gulp-beautify": "^3.0.0", |
@@ -166,3 +166,3 @@ 'use strict' | ||
this._fill(path.split(this.separator), obj, v, mod) | ||
} else if (!hasOwnProperty.call(obj, path) || this.override) { | ||
} else { | ||
obj[path] = _process(v, mod) | ||
@@ -169,0 +169,0 @@ } |
@@ -26,2 +26,10 @@ 'use strict' | ||
}) | ||
it('can set root level property regardless whether override is set', function () { | ||
Dot.str('a', 'b', { | ||
a: 1 | ||
}).should.deepEqual({ | ||
a: 'b' | ||
}) | ||
}) | ||
}) |
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
100761
3082
17