summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-10-21 13:18:53 -0300
committerFelipe Sateler <fsateler@debian.org>2018-10-21 13:18:53 -0300
commit637da7f9cf40a26313b6d18eb8156e2537e7cf10 (patch)
tree4a4affdb7d9cfbfb36c56a450b1962b941bf8712
parentbcda5f13205748e2020fb23529a64de6a68c5d61 (diff)
bundle curlydiff module
FTP masters would reject node-curlydiff on the account of it being too small, so we bundle the module here. Forwarded: not-needed Gbp-Pq: Name 2030-bundle-curlydiff-module.patch
-rw-r--r--node_modules/curlydiff/index.js62
-rw-r--r--node_modules/curlydiff/package.json46
2 files changed, 108 insertions, 0 deletions
diff --git a/node_modules/curlydiff/index.js b/node_modules/curlydiff/index.js
new file mode 100644
index 0000000..d9d97de
--- /dev/null
+++ b/node_modules/curlydiff/index.js
@@ -0,0 +1,62 @@
+module.exports.diff = diff;
+module.exports.apply = apply;
+module.exports.isObject = isObject;
+
+function diff(from, to) {
+ if (!isObject(from) || !isObject(to)) {
+ // not both objects
+ if (from === to) return undefined;
+ if (from instanceof Date && to instanceof Date && from.getTime() === to.getTime()) return undefined;
+ // there's a difference
+ return to;
+ }
+ // both are objects
+ var result = {};
+ var anythingChanged = false;
+ for (var key in from) {
+ var childDiff;
+ if (key in to) {
+ childDiff = diff(from[key], to[key]);
+ if (childDiff === undefined) continue;
+ } else {
+ // deleted
+ childDiff = null;
+ }
+ // there's a difference
+ result[key] = childDiff;
+ anythingChanged = true;
+ }
+ for (var key in to) {
+ if (key in from) continue; // handled above
+ result[key] = to[key];
+ anythingChanged = true;
+ }
+ if (anythingChanged) return result;
+ // no change
+ return undefined;
+}
+
+function apply(object, patch) {
+ if (patch === undefined) return object;
+ if (!isObject(object) || !isObject(patch)) return patch;
+ // both are objects
+ for (var key in patch) {
+ var patchChild = patch[key];
+ if (patchChild == null) {
+ // removed
+ delete object[key];
+ } else {
+ // either this assignment or this function call will have side effects
+ object[key] = apply(object[key], patchChild);
+ }
+ }
+ return object;
+}
+
+function isObject(object) {
+ if (object == null) return false;
+ if (typeof object !== "object") return false;
+ if (Array.isArray(object)) return false;
+ if (object instanceof Date) return false;
+ return true;
+}
diff --git a/node_modules/curlydiff/package.json b/node_modules/curlydiff/package.json
new file mode 100644
index 0000000..8bf18ac
--- /dev/null
+++ b/node_modules/curlydiff/package.json
@@ -0,0 +1,46 @@
+{
+ "name": "curlydiff",
+ "version": "2.0.1",
+ "description": "diff nested JavaScript objects",
+ "main": "index.js",
+ "scripts": {
+ "test": "node test/test.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/thejoshwolfe/curlydiff.git"
+ },
+ "author": {
+ "name": "Josh Wolfe",
+ "email": "thejoshwolfe@gmail.com"
+ },
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/thejoshwolfe/curlydiff/issues"
+ },
+ "devDependencies": {
+ "whynoteq": "~1.0.2"
+ },
+ "gitHead": "b8f52b5906ec3e93873447e072c2d370c02cf869",
+ "homepage": "https://github.com/thejoshwolfe/curlydiff",
+ "_id": "curlydiff@2.0.1",
+ "_shasum": "6ac4b754ea5b63af2632022d03a152306f7eac0b",
+ "_from": "curlydiff@~2.0.1",
+ "_npmVersion": "1.4.28",
+ "_npmUser": {
+ "name": "thejoshwolfe",
+ "email": "thejoshwolfe@gmail.com"
+ },
+ "maintainers": [
+ {
+ "name": "thejoshwolfe",
+ "email": "thejoshwolfe@gmail.com"
+ }
+ ],
+ "dist": {
+ "shasum": "6ac4b754ea5b63af2632022d03a152306f7eac0b",
+ "tarball": "http://registry.npmjs.org/curlydiff/-/curlydiff-2.0.1.tgz"
+ },
+ "directories": {},
+ "_resolved": "https://registry.npmjs.org/curlydiff/-/curlydiff-2.0.1.tgz"
+}