Comparing version 3.0.0 to 3.0.1
@@ -6,2 +6,2 @@ /** | ||
*/ | ||
"use strict";function evaluatePath(t,e){if(!t)return null;let{dotIndex:r,key:a,remaining:i}=state(e);return r>=0&&!t[e]?Array.isArray(t[a])?t[a].map(t=>evaluatePath(t,i)):evaluatePath(t[a],i):Array.isArray(t)?t.map(t=>evaluatePath(t,e)):r>=0&&e!==a&&t[a]?evaluatePath(t[a],i):-1===r&&t[a]&&!t[e]?t[a]:t[e]}function setPath(t,e,r){if(!t)throw new Error("No object was provided.");if(!e)throw new Error("No keyPath was provided.");return _sp(t,e,r)}function _sp(t,e,r){let{dotIndex:a,key:i,remaining:n}=state(e);if(e.startsWith("__proto__")||e.startsWith("constructor")||e.startsWith("prototype"))return t;if(a>=0){if(!t[i]&&Array.isArray(t))return t.forEach(t=>_sp(t,e,r));t[i]||(t[i]={}),_sp(t[i],n,r)}else{if(Array.isArray(t))return t.forEach(t=>_sp(t,n,r));t[i]=r}return t}function state(t){let e=/(?<!\\)\./.exec(t),r=e?e.index:-1;return{dotIndex:r,key:t.slice(0,r>=0?r:void 0).replace(/\\./g,"."),remaining:t.slice(r+1)}}module.exports={evaluatePath:evaluatePath,setPath:setPath}; | ||
"use strict";function evaluatePath(t,e){if(!t)return null;let{dotIndex:r,key:a,remaining:n}=state(e);return r>=0&&!t[e]?Array.isArray(t[a])?t[a].map(t=>evaluatePath(t,n)):evaluatePath(t[a],n):Array.isArray(t)?t.map(t=>evaluatePath(t,e)):r>=0&&e!==a&&t[a]?evaluatePath(t[a],n):-1===r&&t[a]&&!t[e]?t[a]:t[e]}function setPath(t,e,r){if(!t)throw new Error("No object was provided.");if(!e)throw new Error("No keyPath was provided.");return _sp(t,e,r)}function _sp(t,e,r){let{dotIndex:a,key:n,remaining:i}=state(e);if(e.startsWith("__proto__")||e.startsWith("constructor")||e.startsWith("prototype"))return t;if(a>=0){if(!t[n]&&Array.isArray(t))return t.forEach(t=>_sp(t,e,r));t[n]||(t[n]={}),_sp(t[n],i,r)}else{if(Array.isArray(t))return t.forEach(t=>_sp(t,i,r));t[n]=r}return t}function state(t){let e=findFirstNonEscapedDotIndex(t);return{dotIndex:e,key:t.slice(0,e>=0?e:void 0).replace(/\\./g,"."),remaining:t.slice(e+1)}}function findFirstNonEscapedDotIndex(t){for(let e=0;e<t.length;e++){const r=e>0?t[e-1]:"";if("."===t[e]&&"\\"!==r)return e}return-1}module.exports={evaluatePath:evaluatePath,setPath:setPath}; |
@@ -5,3 +5,3 @@ { | ||
"description": "A document path library for Node", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"homepage": "https://mrodrig.github.io/doc-path", | ||
@@ -8,0 +8,0 @@ "repository": { |
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
6797