Socket
Socket
Sign inDemoInstall

doc-path

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doc-path - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

2

dist/path.js

@@ -6,2 +6,2 @@ /**

*/
"use strict";function evaluatePath(t,r){if(!t)return null;let{dotIndex:e,key:a,remaining:i}=state(r);return e>=0&&!t[r]?Array.isArray(t[a])?t[a].map(t=>evaluatePath(t,i)):evaluatePath(t[a],i):Array.isArray(t)?t.map(t=>evaluatePath(t,r)):t[r]}function setPath(t,r,e){if(!t)throw new Error("No object was provided.");if(!r)throw new Error("No keyPath was provided.");return _sp(t,r,e)}function _sp(t,r,e){let{dotIndex:a,key:i,remaining:n}=state(r);if(r.startsWith("__proto__")||r.startsWith("constructor")||r.startsWith("prototype"))return t;if(a>=0){if(!t[i]&&Array.isArray(t))return t.forEach(t=>_sp(t,r,e));t[i]||(t[i]={}),_sp(t[i],n,e)}else{if(Array.isArray(t))return t.forEach(t=>_sp(t,n,e));t[r]=e}return t}function state(t){let r=t.indexOf(".");return{dotIndex:r,key:t.slice(0,r>=0?r:void 0),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: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};

@@ -5,3 +5,3 @@ {

"description": "A document path library for Node",
"version": "2.3.0",
"version": "3.0.0",
"homepage": "https://mrodrig.github.io/doc-path",

@@ -47,5 +47,5 @@ "repository": {

"engines": {
"node": ">=10"
"node": ">=12"
},
"license": "MIT"
}

@@ -33,2 +33,3 @@ # A Document Path Library for Node

* `key` - `String` - A path to the existing key whose value will be returned.
* Note: If your key has a dot in it (eg. `a.b`) then be sure to escape the dot with a blackslash (eg. `a\\.b`).

@@ -85,2 +86,3 @@ If the key does not exist, `undefined` is returned.

* `key` - `String` - A path to the existing key whose value will be set.
* Note: If your key has a dot in it (eg. `a.b`) then be sure to escape the dot with a blackslash (eg. `a\\.b`).
* `value` - `*` - The value that will be set at the given key.

@@ -171,4 +173,5 @@

- Supports keys with escaped `.` characters (as of v3.0.0)
- Supports nested paths
- Including keys of objects inside arrays! (as of v2.0.0)
- Same common path specification as other programs such as MongoDB
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc