diff options
author | 2020-11-18 23:26:45 +0100 | |
---|---|---|
committer | 2020-11-18 23:26:45 +0100 | |
commit | 81ddf9b700bc48a1f8e472209f080f9c1d9a9b09 (patch) | |
tree | 8b959d50c5a614cbf9fcb346ed556140374d4b6d /node_modules/dot-prop/index.js | |
parent | 1870f3fdf43707a15fda0f609a021f516f45eb63 (diff) | |
download | website_creator-81ddf9b700bc48a1f8e472209f080f9c1d9a9b09.tar.gz website_creator-81ddf9b700bc48a1f8e472209f080f9c1d9a9b09.tar.bz2 website_creator-81ddf9b700bc48a1f8e472209f080f9c1d9a9b09.zip |
rm node_modules
Diffstat (limited to 'node_modules/dot-prop/index.js')
-rw-r--r-- | node_modules/dot-prop/index.js | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/node_modules/dot-prop/index.js b/node_modules/dot-prop/index.js deleted file mode 100644 index 189831c..0000000 --- a/node_modules/dot-prop/index.js +++ /dev/null @@ -1,141 +0,0 @@ -'use strict'; -const isObj = require('is-obj'); - -const disallowedKeys = [ - '__proto__', - 'prototype', - 'constructor' -]; - -const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment)); - -function getPathSegments(path) { - const pathArr = path.split('.'); - const parts = []; - - for (let i = 0; i < pathArr.length; i++) { - let p = pathArr[i]; - - while (p[p.length - 1] === '\\' && pathArr[i + 1] !== undefined) { - p = p.slice(0, -1) + '.'; - p += pathArr[++i]; - } - - parts.push(p); - } - - if (!isValidPath(parts)) { - return []; - } - - return parts; -} - -module.exports = { - get(obj, path, value) { - if (!isObj(obj) || typeof path !== 'string') { - return value === undefined ? obj : value; - } - - const pathArr = getPathSegments(path); - if (pathArr.length === 0) { - return; - } - - for (let i = 0; i < pathArr.length; i++) { - if (!Object.prototype.propertyIsEnumerable.call(obj, pathArr[i])) { - return value; - } - - obj = obj[pathArr[i]]; - - if (obj === undefined || obj === null) { - // `obj` is either `undefined` or `null` so we want to stop the loop, and - // if this is not the last bit of the path, and - // if it did't return `undefined` - // it would return `null` if `obj` is `null` - // but we want `get({foo: null}, 'foo.bar')` to equal `undefined`, or the supplied value, not `null` - if (i !== pathArr.length - 1) { - return value; - } - - break; - } - } - - return obj; - }, - - set(obj, path, value) { - if (!isObj(obj) || typeof path !== 'string') { - return obj; - } - - const root = obj; - const pathArr = getPathSegments(path); - if (pathArr.length === 0) { - return; - } - - for (let i = 0; i < pathArr.length; i++) { - const p = pathArr[i]; - - if (!isObj(obj[p])) { - obj[p] = {}; - } - - if (i === pathArr.length - 1) { - obj[p] = value; - } - - obj = obj[p]; - } - - return root; - }, - - delete(obj, path) { - if (!isObj(obj) || typeof path !== 'string') { - return; - } - - const pathArr = getPathSegments(path); - - for (let i = 0; i < pathArr.length; i++) { - const p = pathArr[i]; - - if (i === pathArr.length - 1) { - delete obj[p]; - return; - } - - obj = obj[p]; - - if (!isObj(obj)) { - return; - } - } - }, - - has(obj, path) { - if (!isObj(obj) || typeof path !== 'string') { - return false; - } - - const pathArr = getPathSegments(path); - - for (let i = 0; i < pathArr.length; i++) { - if (isObj(obj)) { - if (!(pathArr[i] in obj)) { - return false; - } - - obj = obj[pathArr[i]]; - } else { - return false; - } - } - - return true; - } -}; |