aboutsummaryrefslogtreecommitdiff
path: root/node_modules/dot-prop
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/dot-prop
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
downloadwallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/dot-prop')
-rw-r--r--node_modules/dot-prop/index.js120
-rw-r--r--node_modules/dot-prop/license21
-rw-r--r--node_modules/dot-prop/package.json48
-rw-r--r--node_modules/dot-prop/readme.md97
4 files changed, 286 insertions, 0 deletions
diff --git a/node_modules/dot-prop/index.js b/node_modules/dot-prop/index.js
new file mode 100644
index 000000000..59a0e2264
--- /dev/null
+++ b/node_modules/dot-prop/index.js
@@ -0,0 +1,120 @@
+'use strict';
+const isObj = require('is-obj');
+
+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);
+ }
+
+ return parts;
+}
+
+module.exports = {
+ get(obj, path, value) {
+ if (!isObj(obj) || typeof path !== 'string') {
+ return value === undefined ? obj : value;
+ }
+
+ const pathArr = getPathSegments(path);
+
+ 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;
+ }
+
+ const pathArr = getPathSegments(path);
+
+ 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];
+ }
+ },
+
+ 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;
+ }
+};
diff --git a/node_modules/dot-prop/license b/node_modules/dot-prop/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/dot-prop/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+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.
diff --git a/node_modules/dot-prop/package.json b/node_modules/dot-prop/package.json
new file mode 100644
index 000000000..56242185b
--- /dev/null
+++ b/node_modules/dot-prop/package.json
@@ -0,0 +1,48 @@
+{
+ "name": "dot-prop",
+ "version": "4.1.1",
+ "description": "Get, set, or delete a property from a nested object using a dot path",
+ "license": "MIT",
+ "repository": "sindresorhus/dot-prop",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava",
+ "bench": "matcha bench.js"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "obj",
+ "object",
+ "prop",
+ "property",
+ "dot",
+ "path",
+ "get",
+ "set",
+ "delete",
+ "del",
+ "access",
+ "notation",
+ "dotty"
+ ],
+ "dependencies": {
+ "is-obj": "^1.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "matcha": "^0.7.0",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/node_modules/dot-prop/readme.md b/node_modules/dot-prop/readme.md
new file mode 100644
index 000000000..f612c47f7
--- /dev/null
+++ b/node_modules/dot-prop/readme.md
@@ -0,0 +1,97 @@
+# dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop)
+
+> Get, set, or delete a property from a nested object using a dot path
+
+
+## Install
+
+```
+$ npm install --save dot-prop
+```
+
+
+## Usage
+
+```js
+const dotProp = require('dot-prop');
+
+// getter
+dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar');
+//=> 'unicorn'
+
+dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
+//=> undefined
+
+dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
+//=> 'default value'
+
+dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
+//=> 'unicorn'
+
+// setter
+const obj = {foo: {bar: 'a'}};
+dotProp.set(obj, 'foo.bar', 'b');
+console.log(obj);
+//=> {foo: {bar: 'b'}}
+
+dotProp.set(obj, 'foo.baz', 'x');
+console.log(obj);
+//=> {foo: {bar: 'b', baz: 'x'}}
+
+// has
+dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
+//=> true
+
+// deleter
+const obj = {foo: {bar: 'a'}};
+dotProp.delete(obj, 'foo.bar');
+console.log(obj);
+//=> {foo: {}}
+
+obj.foo.bar = {x: 'y', y: 'x'};
+dotProp.delete(obj, 'foo.bar.x');
+console.log(obj);
+//=> {foo: {bar: {y: 'x'}}}
+```
+
+
+## API
+
+### get(obj, path, [defaultValue])
+
+### set(obj, path, value)
+
+### has(obj, path)
+
+### delete(obj, path)
+
+#### obj
+
+Type: `Object`
+
+Object to get, set, or delete the `path` value.
+
+#### path
+
+Type: `string`
+
+Path of the property in the object, using `.` to separate each nested key.
+
+Use `\\.` if you have a `.` in the key.
+
+#### value
+
+Type: `any`
+
+Value to set at `path`.
+
+#### defaultValue
+
+Type: `any`
+
+Default value.
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)