Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaudiahdz <cghr1990@gmail.com>2020-02-19 00:38:25 +0300
committerisaacs <i@izs.me>2020-05-08 04:11:51 +0300
commit09dac89c1bc20eb2c1f1f272c9e07fc1a579d75a (patch)
tree64335e20df7d982ec16b9c4e57a86182de0583af /node_modules/just-diff
parentd594d8e55241a7a8abf7a61c97fc41c75fc9267f (diff)
@npmcli/arborist@0.0.0-pre.7
Diffstat (limited to 'node_modules/just-diff')
-rw-r--r--node_modules/just-diff/LICENSE21
-rw-r--r--node_modules/just-diff/README.md76
-rw-r--r--node_modules/just-diff/index.js152
-rw-r--r--node_modules/just-diff/package.json53
4 files changed, 302 insertions, 0 deletions
diff --git a/node_modules/just-diff/LICENSE b/node_modules/just-diff/LICENSE
new file mode 100644
index 000000000..5d2c6e577
--- /dev/null
+++ b/node_modules/just-diff/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 angus croll
+
+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/just-diff/README.md b/node_modules/just-diff/README.md
new file mode 100644
index 000000000..836868fe9
--- /dev/null
+++ b/node_modules/just-diff/README.md
@@ -0,0 +1,76 @@
+## just-diff
+
+Part of a [library](../../../../) of zero-dependency npm modules that do just do one thing.
+Guilt-free utilities for every occasion.
+
+[Try it now](http://anguscroll.com/just/just-diff)
+
+Return an object representing the difference between two other objects
+Pass converter to format as http://jsonpatch.com
+
+```js
+import {diff} from 'just-diff';
+
+const obj1 = {a: 4, b: 5};
+const obj2 = {a: 3, b: 5};
+const obj3 = {a: 4, c: 5};
+
+diff(obj1, obj2);
+[
+ { "op": "replace", "path": ['a'], "value": 3 }
+]
+
+diff(obj2, obj3);
+[
+ { "op": "remove", "path": ['b'] },
+ { "op": "replace", "path": ['a'], "value": 4 }
+ { "op": "add", "path": ['c'], "value": 5 }
+]
+
+// using converter to generate jsPatch standard paths
+import {diff, jsonPatchPathConverter} from 'just-diff'
+diff(obj1, obj2, jsonPatchPathConverter);
+[
+ { "op": "replace", "path": '/a', "value": 3 }
+]
+
+diff(obj2, obj3, jsonPatchPathConverter);
+[
+ { "op": "remove", "path": '/b' },
+ { "op": "replace", "path": '/a', "value": 4 }
+ { "op": "add", "path": '/c', "value": 5 }
+]
+
+// arrays
+const obj4 = {a: 4, b: [1, 2, 3]};
+const obj5 = {a: 3, b: [1, 2, 4]};
+const obj6 = {a: 3, b: [1, 2, 4, 5]};
+
+diff(obj4, obj5);
+[
+ { "op": "replace", "path": ['a'], "value": 3 }
+ { "op": "replace", "path": ['b', 2], "value": 4 }
+]
+
+diff(obj5, obj6);
+[
+ { "op": "add", "path": ['b', 3], "value": 5 }
+]
+
+// nested paths
+const obj7 = {a: 4, b: {c: 3}};
+const obj8 = {a: 4, b: {c: 4}};
+const obj9 = {a: 5, b: {d: 4}};
+
+diff(obj7, obj8);
+[
+ { "op": "replace", "path": ['b', 'c'], "value": 4 }
+]
+
+diff(obj8, obj9);
+[
+ { "op": "replace", "path": ['a'], "value": 5 }
+ { "op": "remove", "path": ['b', 'c']}
+ { "op": "add", "path": ['b', 'd'], "value": 4 }
+]
+```
diff --git a/node_modules/just-diff/index.js b/node_modules/just-diff/index.js
new file mode 100644
index 000000000..b49bed146
--- /dev/null
+++ b/node_modules/just-diff/index.js
@@ -0,0 +1,152 @@
+module.exports = {
+ diff: diff,
+ jsonPatchPathConverter: jsonPatchPathConverter,
+};
+
+/*
+ const obj1 = {a: 4, b: 5};
+ const obj2 = {a: 3, b: 5};
+ const obj3 = {a: 4, c: 5};
+
+ diff(obj1, obj2);
+ [
+ { "op": "replace", "path": ['a'], "value": 3 }
+ ]
+
+ diff(obj2, obj3);
+ [
+ { "op": "remove", "path": ['b'] },
+ { "op": "replace", "path": ['a'], "value": 4 }
+ { "op": "add", "path": ['c'], "value": 5 }
+ ]
+
+ // using converter to generate jsPatch standard paths
+ // see http://jsonpatch.com
+ import {diff, jsonPatchPathConverter} from 'just-diff'
+ diff(obj1, obj2, jsonPatchPathConverter);
+ [
+ { "op": "replace", "path": '/a', "value": 3 }
+ ]
+
+ diff(obj2, obj3, jsonPatchPathConverter);
+ [
+ { "op": "remove", "path": '/b' },
+ { "op": "replace", "path": '/a', "value": 4 }
+ { "op": "add", "path": '/c', "value": 5 }
+ ]
+
+ // arrays
+ const obj4 = {a: 4, b: [1, 2, 3]};
+ const obj5 = {a: 3, b: [1, 2, 4]};
+ const obj6 = {a: 3, b: [1, 2, 4, 5]};
+
+ diff(obj4, obj5);
+ [
+ { "op": "replace", "path": ['a'], "value": 3 }
+ { "op": "replace", "path": ['b', 2], "value": 4 }
+ ]
+
+ diff(obj5, obj6);
+ [
+ { "op": "add", "path": ['b', 3], "value": 5 }
+ ]
+
+ // nested paths
+ const obj7 = {a: 4, b: {c: 3}};
+ const obj8 = {a: 4, b: {c: 4}};
+ const obj9 = {a: 5, b: {d: 4}};
+
+ diff(obj7, obj8);
+ [
+ { "op": "replace", "path": ['b', 'c'], "value": 4 }
+ ]
+
+ diff(obj8, obj9);
+ [
+ { "op": "replace", "path": ['a'], "value": 5 }
+ { "op": "remove", "path": ['b', 'c']}
+ { "op": "add", "path": ['b', 'd'], "value": 4 }
+ ]
+*/
+
+function diff(obj1, obj2, pathConverter) {
+ if (!obj1 || typeof obj1 != 'object' || !obj2 || typeof obj2 != 'object') {
+ throw new Error('both arguments must be objects or arrays');
+ }
+
+ pathConverter ||
+ (pathConverter = function(arr) {
+ return arr;
+ });
+
+ function getDiff(obj1, obj2, basePath, diffs) {
+ var obj1Keys = Object.keys(obj1);
+ var obj1KeysLength = obj1Keys.length;
+ var obj2Keys = Object.keys(obj2);
+ var obj2KeysLength = obj2Keys.length;
+ var path;
+
+ for (var i = 0; i < obj1KeysLength; i++) {
+ var key = Array.isArray(obj1) ? Number(obj1Keys[i]) : obj1Keys[i];
+ if (!(key in obj2)) {
+ path = basePath.concat(key);
+ diffs.remove.push({
+ op: 'remove',
+ path: pathConverter(path),
+ });
+ }
+ }
+
+ for (var i = 0; i < obj2KeysLength; i++) {
+ var key = Array.isArray(obj2) ? Number(obj2Keys[i]) : obj2Keys[i];
+ var obj1AtKey = obj1[key];
+ var obj2AtKey = obj2[key];
+ if (!(key in obj1)) {
+ path = basePath.concat(key);
+ var obj2Value = obj2[key];
+ diffs.add.push({
+ op: 'add',
+ path: pathConverter(path),
+ value: obj2Value,
+ });
+ } else if (obj1AtKey !== obj2AtKey) {
+ if (
+ Object(obj1AtKey) !== obj1AtKey ||
+ Object(obj2AtKey) !== obj2AtKey
+ ) {
+ path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
+ } else {
+ if (
+ !Object.keys(obj1AtKey).length &&
+ !Object.keys(obj2AtKey).length &&
+ String(obj1AtKey) != String(obj2AtKey)
+ ) {
+ path = pushReplace(path, basePath, key, diffs, pathConverter, obj2);
+ } else {
+ getDiff(obj1[key], obj2[key], basePath.concat(key), diffs);
+ }
+ }
+ }
+ }
+
+ return diffs.remove
+ .reverse()
+ .concat(diffs.replace)
+ .concat(diffs.add);
+ }
+ return getDiff(obj1, obj2, [], {remove: [], replace: [], add: []});
+}
+
+function pushReplace(path, basePath, key, diffs, pathConverter, obj2) {
+ path = basePath.concat(key);
+ diffs.replace.push({
+ op: 'replace',
+ path: pathConverter(path),
+ value: obj2[key],
+ });
+ return path;
+}
+
+function jsonPatchPathConverter(arrayPath) {
+ return [''].concat(arrayPath).join('/');
+}
diff --git a/node_modules/just-diff/package.json b/node_modules/just-diff/package.json
new file mode 100644
index 000000000..b9c522087
--- /dev/null
+++ b/node_modules/just-diff/package.json
@@ -0,0 +1,53 @@
+{
+ "_from": "just-diff@^3.0.1",
+ "_id": "just-diff@3.0.2",
+ "_inBundle": false,
+ "_integrity": "sha512-+EiNvacECnZbszZa5IMjzrJ3dy2HKMXyGaNYWBnXy+iWW+437jIvQUrWaM9M+XI/6gOH8EjqvhGUOSh7ETekyg==",
+ "_location": "/just-diff",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "just-diff@^3.0.1",
+ "name": "just-diff",
+ "escapedName": "just-diff",
+ "rawSpec": "^3.0.1",
+ "saveSpec": null,
+ "fetchSpec": "^3.0.1"
+ },
+ "_requiredBy": [
+ "/parse-conflict-json"
+ ],
+ "_resolved": "https://registry.npmjs.org/just-diff/-/just-diff-3.0.2.tgz",
+ "_shasum": "65f4914e4d7500b364d12b7b3f03bcbacdac743b",
+ "_spec": "just-diff@^3.0.1",
+ "_where": "/Users/claudiahdz/npm/cli/node_modules/parse-conflict-json",
+ "author": {
+ "name": "Angus Croll"
+ },
+ "bugs": {
+ "url": "https://github.com/angus-c/just/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "Return an object representing the diffs between two objects. Supports jsonPatch protocol",
+ "homepage": "https://github.com/angus-c/just#readme",
+ "keywords": [
+ "object",
+ "diff",
+ "jsonPatch",
+ "no-dependencies",
+ "just"
+ ],
+ "license": "MIT",
+ "main": "index.js",
+ "name": "just-diff",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/angus-c/just.git"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "version": "3.0.2"
+}