fix
This commit is contained in:
7
book/node_modules/object-path/.travis.yml
generated
vendored
Executable file
7
book/node_modules/object-path/.travis.yml
generated
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
- "12"
|
||||
- "14"
|
||||
after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
|
||||
21
book/node_modules/object-path/LICENSE
generated
vendored
Normal file
21
book/node_modules/object-path/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Mario Casciaro
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
193
book/node_modules/object-path/README.md
generated
vendored
Normal file
193
book/node_modules/object-path/README.md
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
|
||||
|
||||
object-path
|
||||
===========
|
||||
|
||||
Access deep properties using a path
|
||||
|
||||
[](http://badge.fury.io/js/object-path)
|
||||
[](https://travis-ci.org/mariocasciaro/object-path)
|
||||
[](https://coveralls.io/r/mariocasciaro/object-path)
|
||||
[](https://david-dm.org/mariocasciaro/object-path#info=devDependencies)
|
||||

|
||||
|
||||
## Changelog
|
||||
|
||||
### 0.11.8
|
||||
|
||||
* **SECURITY FIX**. Fix a prototype pollution vulnerability in the `del()`, `empty()`, `push()`, `insert()` functions when using the "inherited props" mode (e.g. when a new `object-path` instance is created with the `includeInheritedProps` option set to `true` or when using the `withInheritedProps` default instance. To help with preventing this type of vulnerability in the client code, also the `get()` function will now throw an exception if an object's magic properties are accessed. The vulnerability does not exist in the default instance exposed by object path (e.g `objectPath.del()`) if using version >= `0.11.0`.
|
||||
|
||||
### 0.11.6
|
||||
|
||||
* **SECURITY FIX**. Fix a circumvention of the security fix released in 0.11.5 when non-string/non-numeric values are used in the path (e.g. `op.withInheritedProps.set({}, [['__proto__'], 'polluted'], true)`)
|
||||
|
||||
### 0.11.5
|
||||
|
||||
* **SECURITY FIX**. Fix a prototype pollution vulnerability in the `set()` function when using the "inherited props" mode (e.g. when a new `object-path` instance is created with the `includeInheritedProps` option set to `true` or when using the `withInheritedProps` default instance. The vulnerability does not exist in the default instance exposed by object path (e.g `objectPath.set()`) if using version >= `0.11.0`.
|
||||
|
||||
### 0.11.0
|
||||
|
||||
* Introduce ability to specify options and create new instances of `object-path`
|
||||
* Introduce option to control the way `object-path` deals with inherited properties (`includeInheritedProps`)
|
||||
* New default `object-path` instance already configured to handle not-own object properties (`withInheritedProps`)
|
||||
|
||||
### 0.10.0
|
||||
|
||||
* Improved performance of `get`, `set`, and `push` by 2x-3x
|
||||
* Introduced a benchmarking test suite
|
||||
* **BREAKING CHANGE**: `del`, `empty`, `set` will not affect not-own object's properties (made them consistent with the other methods)
|
||||
|
||||
## Install
|
||||
|
||||
### Node.js
|
||||
|
||||
```
|
||||
npm install object-path --save
|
||||
```
|
||||
|
||||
### Bower
|
||||
|
||||
```
|
||||
bower install object-path --save
|
||||
```
|
||||
|
||||
### Typescript typings
|
||||
|
||||
```
|
||||
typings install --save dt~object-path
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
|
||||
var obj = {
|
||||
a: {
|
||||
b: "d",
|
||||
c: ["e", "f"],
|
||||
'\u1200': 'unicode key',
|
||||
'dot.dot': 'key'
|
||||
}
|
||||
};
|
||||
|
||||
var objectPath = require("object-path");
|
||||
|
||||
//get deep property
|
||||
objectPath.get(obj, "a.b"); //returns "d"
|
||||
objectPath.get(obj, ["a", "dot.dot"]); //returns "key"
|
||||
objectPath.get(obj, 'a.\u1200'); //returns "unicode key"
|
||||
|
||||
//get the first non-undefined value
|
||||
objectPath.coalesce(obj, ['a.z', 'a.d', ['a','b']], 'default');
|
||||
|
||||
//empty a given path (but do not delete it) depending on their type,so it retains reference to objects and arrays.
|
||||
//functions that are not inherited from prototype are set to null.
|
||||
//object instances are considered objects and just own property names are deleted
|
||||
objectPath.empty(obj, 'a.b'); // obj.a.b is now ''
|
||||
objectPath.empty(obj, 'a.c'); // obj.a.c is now []
|
||||
objectPath.empty(obj, 'a'); // obj.a is now {}
|
||||
|
||||
//works also with arrays
|
||||
objectPath.get(obj, "a.c.1"); //returns "f"
|
||||
objectPath.get(obj, ["a","c","1"]); //returns "f"
|
||||
|
||||
//can return a default value with get
|
||||
objectPath.get(obj, ["a.c.b"], "DEFAULT"); //returns "DEFAULT", since a.c.b path doesn't exists, if omitted, returns undefined
|
||||
|
||||
//set
|
||||
objectPath.set(obj, "a.h", "m"); // or objectPath.set(obj, ["a","h"], "m");
|
||||
objectPath.get(obj, "a.h"); //returns "m"
|
||||
|
||||
//set will create intermediate object/arrays
|
||||
objectPath.set(obj, "a.j.0.f", "m");
|
||||
|
||||
//will insert values in array
|
||||
objectPath.insert(obj, "a.c", "m", 1); // obj.a.c = ["e", "m", "f"]
|
||||
|
||||
//push into arrays (and create intermediate objects/arrays)
|
||||
objectPath.push(obj, "a.k", "o");
|
||||
|
||||
//ensure a path exists (if it doesn't, set the default value you provide)
|
||||
objectPath.ensureExists(obj, "a.k.1", "DEFAULT");
|
||||
var oldVal = objectPath.ensureExists(obj, "a.b", "DEFAULT"); // oldval === "d"
|
||||
|
||||
//deletes a path
|
||||
objectPath.del(obj, "a.b"); // obj.a.b is now undefined
|
||||
objectPath.del(obj, ["a","c",0]); // obj.a.c is now ['f']
|
||||
|
||||
//tests path existence
|
||||
objectPath.has(obj, "a.b"); // true
|
||||
objectPath.has(obj, ["a","d"]); // false
|
||||
|
||||
//bind object
|
||||
var model = objectPath({
|
||||
a: {
|
||||
b: "d",
|
||||
c: ["e", "f"]
|
||||
}
|
||||
});
|
||||
|
||||
//now any method from above is supported directly w/o passing an object
|
||||
model.get("a.b"); //returns "d"
|
||||
model.get(["a.c.b"], "DEFAULT"); //returns "DEFAULT"
|
||||
model.del("a.b"); // obj.a.b is now undefined
|
||||
model.has("a.b"); // false
|
||||
|
||||
```
|
||||
### How `object-path` deals with inherited properties
|
||||
|
||||
By default `object-path` will only access an object's own properties. Look at the following example:
|
||||
|
||||
```javascript
|
||||
var proto = {
|
||||
notOwn: {prop: 'a'}
|
||||
}
|
||||
var obj = Object.create(proto);
|
||||
|
||||
//This will return undefined (or the default value you specified), because notOwn is
|
||||
//an inherited property
|
||||
objectPath.get(obj, 'notOwn.prop');
|
||||
|
||||
//This will set the property on the obj instance and not the prototype.
|
||||
//In other words proto.notOwn.prop === 'a' and obj.notOwn.prop === 'b'
|
||||
objectPath.set(obj, 'notOwn.prop', 'b');
|
||||
```
|
||||
To configure `object-path` to also deal with inherited properties, you need to create a new instance and specify
|
||||
the `includeInheritedProps = true` in the options object:
|
||||
|
||||
```javascript
|
||||
var objectPath = require("object-path");
|
||||
var objectPathWithInheritedProps = objectPath.create({includeInheritedProps: true})
|
||||
```
|
||||
|
||||
Alternatively, `object-path` exposes an instance already configured to handle inherited properties (`objectPath.withInheritedProps`):
|
||||
```javascript
|
||||
var objectPath = require("object-path");
|
||||
var objectPathWithInheritedProps = objectPath.withInheritedProps
|
||||
```
|
||||
|
||||
Once you have the new instance, you can access inherited properties as you access other properties:
|
||||
```javascript
|
||||
var proto = {
|
||||
notOwn: {prop: 'a'}
|
||||
}
|
||||
var obj = Object.create(proto);
|
||||
|
||||
//This will return 'a'
|
||||
objectPath.withInheritedProps.get(obj, 'notOwn.prop');
|
||||
|
||||
//This will set proto.notOwn.prop to 'b'
|
||||
objectPath.set(obj, 'notOwn.prop', 'b');
|
||||
```
|
||||
|
||||
**NOTE**: For security reasons `object-path` will throw an exception when trying to access an object's magic properties (e.g. `__proto__`, `constructor`) when in "inherited props" mode.
|
||||
|
||||
### Immutability
|
||||
|
||||
If you are looking for an *immutable* alternative of this library, you can take a look at: [object-path-immutable](https://github.com/mariocasciaro/object-path-immutable)
|
||||
|
||||
|
||||
### Credits
|
||||
|
||||
* [Mario Casciaro](https://github.com/mariocasciaro) - Author
|
||||
* [Paulo Cesar](https://github.com/pocesar) - Major contributor
|
||||
7
book/node_modules/object-path/SECURITY.md
generated
vendored
Normal file
7
book/node_modules/object-path/SECURITY.md
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
Reporting a security issue
|
||||
===========
|
||||
|
||||
Please report any suspected security vulnerabilities responsibly to protect the users of this package. Try not share them publicly before the issue is confirmed and a fix is produced.
|
||||
|
||||
Send us an email at report @ mario.fyi to privately report any security vulnerability to us.
|
||||
52
book/node_modules/object-path/benchmark.js
generated
vendored
Normal file
52
book/node_modules/object-path/benchmark.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var Benchpress = require('@mariocasciaro/benchpress')
|
||||
var benchmark = new Benchpress()
|
||||
var op = require('./')
|
||||
|
||||
var testObj = {
|
||||
level1_a: {
|
||||
level2_a: {
|
||||
level3_a: {
|
||||
level4_a: {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testObj2
|
||||
|
||||
benchmark
|
||||
.add('get existing', {
|
||||
iterations: 100000,
|
||||
fn: function() {
|
||||
op.get(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a'])
|
||||
}
|
||||
})
|
||||
.add('get non-existing', {
|
||||
iterations: 100000,
|
||||
fn: function() {
|
||||
op.get(testObj, ['level5_a'])
|
||||
}
|
||||
})
|
||||
.add('push', {
|
||||
iterations: 100000,
|
||||
fn: function() {
|
||||
op.push(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_a'], 'val')
|
||||
}
|
||||
})
|
||||
.add('set non existing', {
|
||||
iterations: 100000,
|
||||
fn: function() {
|
||||
op.set(testObj2, ['level1_a', 'level2_b', 'level3_b', 'level4_b', 'level5_b'], 'val')
|
||||
},
|
||||
beforeEach: function() {
|
||||
testObj2 = {}
|
||||
}
|
||||
})
|
||||
.add('set existing', {
|
||||
iterations: 100000,
|
||||
fn: function() {
|
||||
op.set(testObj, ['level1_a', 'level2_a', 'level3_a', 'level4_a', 'level5_b'], 'val')
|
||||
}
|
||||
})
|
||||
.run()
|
||||
16
book/node_modules/object-path/bower.json
generated
vendored
Normal file
16
book/node_modules/object-path/bower.json
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "object-path",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"deep",
|
||||
"path",
|
||||
"access",
|
||||
"bean",
|
||||
"object"
|
||||
],
|
||||
"ignore" : [
|
||||
"test.js",
|
||||
"coverage",
|
||||
"*.yml"
|
||||
]
|
||||
}
|
||||
22
book/node_modules/object-path/component.json
generated
vendored
Normal file
22
book/node_modules/object-path/component.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "object-path",
|
||||
"description": "Access deep properties using a path",
|
||||
"version": "0.9.2",
|
||||
"author": {
|
||||
"name": "Mario Casciaro"
|
||||
},
|
||||
"homepage": "https://github.com/mariocasciaro/object-path",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mariocasciaro/object-path.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"scripts": ["index.js"],
|
||||
"keywords": [
|
||||
"deep",
|
||||
"path",
|
||||
"access",
|
||||
"bean"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
320
book/node_modules/object-path/index.js
generated
vendored
Normal file
320
book/node_modules/object-path/index.js
generated
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
(function (root, factory) {
|
||||
'use strict'
|
||||
|
||||
/*istanbul ignore next:cant test*/
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
module.exports = factory()
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory)
|
||||
} else {
|
||||
// Browser globals
|
||||
root.objectPath = factory()
|
||||
}
|
||||
})(this, function () {
|
||||
'use strict'
|
||||
|
||||
var toStr = Object.prototype.toString
|
||||
|
||||
function hasOwnProperty (obj, prop) {
|
||||
if (obj == null) {
|
||||
return false
|
||||
}
|
||||
//to handle objects with null prototypes (too edge case?)
|
||||
return Object.prototype.hasOwnProperty.call(obj, prop)
|
||||
}
|
||||
|
||||
function isEmpty (value) {
|
||||
if (!value) {
|
||||
return true
|
||||
}
|
||||
if (isArray(value) && value.length === 0) {
|
||||
return true
|
||||
} else if (typeof value !== 'string') {
|
||||
for (var i in value) {
|
||||
if (hasOwnProperty(value, i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function toString (type) {
|
||||
return toStr.call(type)
|
||||
}
|
||||
|
||||
function isObject (obj) {
|
||||
return typeof obj === 'object' && toString(obj) === '[object Object]'
|
||||
}
|
||||
|
||||
var isArray = Array.isArray || function (obj) {
|
||||
/*istanbul ignore next:cant test*/
|
||||
return toStr.call(obj) === '[object Array]'
|
||||
}
|
||||
|
||||
function isBoolean (obj) {
|
||||
return typeof obj === 'boolean' || toString(obj) === '[object Boolean]'
|
||||
}
|
||||
|
||||
function getKey (key) {
|
||||
var intKey = parseInt(key)
|
||||
if (intKey.toString() === key) {
|
||||
return intKey
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
function factory (options) {
|
||||
options = options || {}
|
||||
|
||||
var objectPath = function (obj) {
|
||||
return Object.keys(objectPath).reduce(function (proxy, prop) {
|
||||
if (prop === 'create') {
|
||||
return proxy
|
||||
}
|
||||
|
||||
/*istanbul ignore else*/
|
||||
if (typeof objectPath[prop] === 'function') {
|
||||
proxy[prop] = objectPath[prop].bind(objectPath, obj)
|
||||
}
|
||||
|
||||
return proxy
|
||||
}, {})
|
||||
}
|
||||
|
||||
var hasShallowProperty
|
||||
if (options.includeInheritedProps) {
|
||||
hasShallowProperty = function () {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
hasShallowProperty = function (obj, prop) {
|
||||
return (typeof prop === 'number' && Array.isArray(obj)) || hasOwnProperty(obj, prop)
|
||||
}
|
||||
}
|
||||
|
||||
function getShallowProperty (obj, prop) {
|
||||
if (hasShallowProperty(obj, prop)) {
|
||||
return obj[prop]
|
||||
}
|
||||
}
|
||||
|
||||
var getShallowPropertySafely
|
||||
if (options.includeInheritedProps) {
|
||||
getShallowPropertySafely = function (obj, currentPath) {
|
||||
if (typeof currentPath !== 'string' && typeof currentPath !== 'number') {
|
||||
currentPath = String(currentPath)
|
||||
}
|
||||
var currentValue = getShallowProperty(obj, currentPath)
|
||||
if (currentPath === '__proto__' || currentPath === 'prototype' ||
|
||||
(currentPath === 'constructor' && typeof currentValue === 'function')) {
|
||||
throw new Error('For security reasons, object\'s magic properties cannot be set')
|
||||
}
|
||||
return currentValue
|
||||
}
|
||||
} else {
|
||||
getShallowPropertySafely = function (obj, currentPath) {
|
||||
return getShallowProperty(obj, currentPath)
|
||||
}
|
||||
}
|
||||
|
||||
function set (obj, path, value, doNotReplace) {
|
||||
if (typeof path === 'number') {
|
||||
path = [path]
|
||||
}
|
||||
if (!path || path.length === 0) {
|
||||
return obj
|
||||
}
|
||||
if (typeof path === 'string') {
|
||||
return set(obj, path.split('.').map(getKey), value, doNotReplace)
|
||||
}
|
||||
var currentPath = path[0]
|
||||
var currentValue = getShallowPropertySafely(obj, currentPath)
|
||||
if (path.length === 1) {
|
||||
if (currentValue === void 0 || !doNotReplace) {
|
||||
obj[currentPath] = value
|
||||
}
|
||||
return currentValue
|
||||
}
|
||||
|
||||
if (currentValue === void 0) {
|
||||
//check if we assume an array
|
||||
if (typeof path[1] === 'number') {
|
||||
obj[currentPath] = []
|
||||
} else {
|
||||
obj[currentPath] = {}
|
||||
}
|
||||
}
|
||||
|
||||
return set(obj[currentPath], path.slice(1), value, doNotReplace)
|
||||
}
|
||||
|
||||
objectPath.has = function (obj, path) {
|
||||
if (typeof path === 'number') {
|
||||
path = [path]
|
||||
} else if (typeof path === 'string') {
|
||||
path = path.split('.')
|
||||
}
|
||||
|
||||
if (!path || path.length === 0) {
|
||||
return !!obj
|
||||
}
|
||||
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
var j = getKey(path[i])
|
||||
|
||||
if ((typeof j === 'number' && isArray(obj) && j < obj.length) ||
|
||||
(options.includeInheritedProps ? (j in Object(obj)) : hasOwnProperty(obj, j))) {
|
||||
obj = obj[j]
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
objectPath.ensureExists = function (obj, path, value) {
|
||||
return set(obj, path, value, true)
|
||||
}
|
||||
|
||||
objectPath.set = function (obj, path, value, doNotReplace) {
|
||||
return set(obj, path, value, doNotReplace)
|
||||
}
|
||||
|
||||
objectPath.insert = function (obj, path, value, at) {
|
||||
var arr = objectPath.get(obj, path)
|
||||
at = ~~at
|
||||
if (!isArray(arr)) {
|
||||
arr = []
|
||||
objectPath.set(obj, path, arr)
|
||||
}
|
||||
arr.splice(at, 0, value)
|
||||
}
|
||||
|
||||
objectPath.empty = function (obj, path) {
|
||||
if (isEmpty(path)) {
|
||||
return void 0
|
||||
}
|
||||
if (obj == null) {
|
||||
return void 0
|
||||
}
|
||||
|
||||
var value, i
|
||||
if (!(value = objectPath.get(obj, path))) {
|
||||
return void 0
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return objectPath.set(obj, path, '')
|
||||
} else if (isBoolean(value)) {
|
||||
return objectPath.set(obj, path, false)
|
||||
} else if (typeof value === 'number') {
|
||||
return objectPath.set(obj, path, 0)
|
||||
} else if (isArray(value)) {
|
||||
value.length = 0
|
||||
} else if (isObject(value)) {
|
||||
for (i in value) {
|
||||
if (hasShallowProperty(value, i)) {
|
||||
delete value[i]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return objectPath.set(obj, path, null)
|
||||
}
|
||||
}
|
||||
|
||||
objectPath.push = function (obj, path /*, values */) {
|
||||
var arr = objectPath.get(obj, path)
|
||||
if (!isArray(arr)) {
|
||||
arr = []
|
||||
objectPath.set(obj, path, arr)
|
||||
}
|
||||
|
||||
arr.push.apply(arr, Array.prototype.slice.call(arguments, 2))
|
||||
}
|
||||
|
||||
objectPath.coalesce = function (obj, paths, defaultValue) {
|
||||
var value
|
||||
|
||||
for (var i = 0, len = paths.length; i < len; i++) {
|
||||
if ((value = objectPath.get(obj, paths[i])) !== void 0) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
objectPath.get = function (obj, path, defaultValue) {
|
||||
if (typeof path === 'number') {
|
||||
path = [path]
|
||||
}
|
||||
if (!path || path.length === 0) {
|
||||
return obj
|
||||
}
|
||||
if (obj == null) {
|
||||
return defaultValue
|
||||
}
|
||||
if (typeof path === 'string') {
|
||||
return objectPath.get(obj, path.split('.'), defaultValue)
|
||||
}
|
||||
|
||||
var currentPath = getKey(path[0])
|
||||
var nextObj = getShallowPropertySafely(obj, currentPath)
|
||||
if (nextObj === void 0) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
if (path.length === 1) {
|
||||
return nextObj
|
||||
}
|
||||
|
||||
return objectPath.get(obj[currentPath], path.slice(1), defaultValue)
|
||||
}
|
||||
|
||||
objectPath.del = function del (obj, path) {
|
||||
if (typeof path === 'number') {
|
||||
path = [path]
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return obj
|
||||
}
|
||||
|
||||
if (isEmpty(path)) {
|
||||
return obj
|
||||
}
|
||||
if (typeof path === 'string') {
|
||||
return objectPath.del(obj, path.split('.'))
|
||||
}
|
||||
|
||||
var currentPath = getKey(path[0])
|
||||
getShallowPropertySafely(obj, currentPath)
|
||||
if (!hasShallowProperty(obj, currentPath)) {
|
||||
return obj
|
||||
}
|
||||
|
||||
if (path.length === 1) {
|
||||
if (isArray(obj)) {
|
||||
obj.splice(currentPath, 1)
|
||||
} else {
|
||||
delete obj[currentPath]
|
||||
}
|
||||
} else {
|
||||
return objectPath.del(obj[currentPath], path.slice(1))
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
return objectPath
|
||||
}
|
||||
|
||||
var mod = factory()
|
||||
mod.create = factory
|
||||
mod.withInheritedProps = factory({includeInheritedProps: true})
|
||||
return mod
|
||||
})
|
||||
48
book/node_modules/object-path/package.json
generated
vendored
Normal file
48
book/node_modules/object-path/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "object-path",
|
||||
"description": "Access deep object properties using a path",
|
||||
"version": "0.11.8",
|
||||
"author": {
|
||||
"name": "Mario Casciaro"
|
||||
},
|
||||
"homepage": "https://github.com/mariocasciaro/object-path",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mariocasciaro/object-path.git"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mariocasciaro/benchpress": "^0.1.3",
|
||||
"chai": "^4.3.4",
|
||||
"coveralls": "^3.1.1",
|
||||
"mocha": "^9.1.0",
|
||||
"mocha-lcov-reporter": "^1.3.0",
|
||||
"nyc": "^15.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test.js",
|
||||
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
||||
"coverage": "nyc npm test",
|
||||
"benchmark": "node benchmark.js"
|
||||
},
|
||||
"keywords": [
|
||||
"deep",
|
||||
"path",
|
||||
"access",
|
||||
"bean",
|
||||
"get",
|
||||
"property",
|
||||
"dot",
|
||||
"prop",
|
||||
"object",
|
||||
"obj",
|
||||
"notation",
|
||||
"segment",
|
||||
"value",
|
||||
"nested",
|
||||
"key"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
1268
book/node_modules/object-path/test.js
generated
vendored
Normal file
1268
book/node_modules/object-path/test.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user