From ca08a6c56ab8d4ed4819193377bf679ef09d95d0 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 12:42:12 +1300 Subject: [PATCH 01/36] chore(editorconfig): declare the charset --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 6244e1b..aaac325 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,5 +3,6 @@ root = true [*] indent_style = tab end_of_line = lf +charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true From 09c3e67b53566ee32c21ef002c25d89ad9fea8b6 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 12:31:59 +1300 Subject: [PATCH 02/36] chore(editorconfig): have package.json and its lockfile keep their default indenting style --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index aaac325..878dc60 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[{package.json,package-lock.json}] +indent_style = space +indent_size = 2 From 9e6c637abf7fcc525e6a3dbce49f921443aa0cd9 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 12:32:30 +1300 Subject: [PATCH 03/36] chore(editorconfig): have markdown files keep there trailing whitespace It can have actual meaning. --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 878dc60..59ca67f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,9 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +[*.md] +trim_trailing_whitespace = false + [{package.json,package-lock.json}] indent_style = space indent_size = 2 From 21e5999014ac3f3253213ea8eda13e3c2d541ade Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 12:21:29 +1300 Subject: [PATCH 04/36] chore(editorconfig): use space instead of tabs for markdown files This is to help ensure that markdown files are rendered similarly by different renders. --- .editorconfig | 2 + readme.md | 134 +++++++++++++++++++++++++------------------------- 2 files changed, 69 insertions(+), 67 deletions(-) diff --git a/.editorconfig b/.editorconfig index 59ca67f..6b9a3da 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,8 @@ trim_trailing_whitespace = true insert_final_newline = true [*.md] +indent_style = space +indent_size = 2 trim_trailing_whitespace = false [{package.json,package-lock.json}] diff --git a/readme.md b/readme.md index 90dfc51..a129984 100644 --- a/readme.md +++ b/readme.md @@ -13,39 +13,39 @@ const merge = require('./') ```js const x = { - foo: { bar: 3 }, - array: [{ - does: 'work', - too: [ 1, 2, 3 ] - }] + foo: { bar: 3 }, + array: [{ + does: 'work', + too: [ 1, 2, 3 ] + }] } const y = { - foo: { baz: 4 }, - quux: 5, - array: [{ - does: 'work', - too: [ 4, 5, 6 ] - }, { - really: 'yes' - }] + foo: { baz: 4 }, + quux: 5, + array: [{ + does: 'work', + too: [ 4, 5, 6 ] + }, { + really: 'yes' + }] } const output = { - foo: { - bar: 3, - baz: 4 - }, - array: [{ - does: 'work', - too: [ 1, 2, 3 ] - }, { - does: 'work', - too: [ 4, 5, 6 ] - }, { - really: 'yes' - }], - quux: 5 + foo: { + bar: 3, + baz: 4 + }, + array: [{ + does: 'work', + too: [ 1, 2, 3 ] + }, { + does: 'work', + too: [ 4, 5, 6 ] + }, { + really: 'yes' + }], + quux: 5 } merge(x, y) // => output @@ -120,9 +120,9 @@ Overwrites the existing array values completely rather than concatenating them: const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray merge( - [1, 2, 3], - [3, 2, 1], - { arrayMerge: overwriteMerge } + [1, 2, 3], + [3, 2, 1], + { arrayMerge: overwriteMerge } ) // => [3, 2, 1] ``` @@ -134,24 +134,24 @@ This was the default array merging algorithm pre-version-2.0.0. ```js const combineMerge = (target, source, options) => { - const destination = target.slice() - - source.forEach((item, index) => { - if (typeof destination[index] === 'undefined') { - destination[index] = options.cloneUnlessOtherwiseSpecified(item, options) - } else if (options.isMergeable(item)) { - destination[index] = merge(target[index], item, options) - } else if (target.indexOf(item) === -1) { - destination.push(item) - } - }) - return destination + const destination = target.slice() + + source.forEach((item, index) => { + if (typeof destination[index] === 'undefined') { + destination[index] = options.cloneUnlessOtherwiseSpecified(item, options) + } else if (options.isMergeable(item)) { + destination[index] = merge(target[index], item, options) + } else if (target.indexOf(item) === -1) { + destination.push(item) + } + }) + return destination } merge( - [{ a: true }], - [{ b: true }, 'ah yup'], - { arrayMerge: combineMerge } + [{ a: true }], + [{ b: true }, 'ah yup'], + { arrayMerge: combineMerge } ) // => [{ a: true, b: true }, 'ah yup'] ``` @@ -169,23 +169,23 @@ To get the pre-version-5.0.0 behavior, you probably want to drop in [`is-mergeab ```js function mergeEverything(value) { - return value !== null && typeof value === 'object' + return value !== null && typeof value === 'object' } function SuperSpecial() { - this.special = 'oh yeah man totally' + this.special = 'oh yeah man totally' } const instantiatedSpecialObject = new SuperSpecial() const target = { - someProperty: { - cool: 'oh for sure' - } + someProperty: { + cool: 'oh for sure' + } } const source = { - someProperty: instantiatedSpecialObject + someProperty: instantiatedSpecialObject } const defaultOutput = merge(target, source) @@ -195,7 +195,7 @@ defaultOutput.someProperty.special // => 'oh yeah man totally' defaultOutput.someProperty instanceof SuperSpecial // => true const customMergeOutput = merge(target, source, { - isMergeable: mergeEverything + isMergeable: mergeEverything }) customMergeOutput.someProperty.cool // => 'oh for sure' @@ -213,29 +213,29 @@ It may also return undefined, in which case the default merge behaviour will be ```js const alex = { - name: { - first: 'Alex', - last: 'Alexson' - }, - pets: ['Cat', 'Parrot'] + name: { + first: 'Alex', + last: 'Alexson' + }, + pets: ['Cat', 'Parrot'] } const tony = { - name: { - first: 'Tony', - last: 'Tonison' - }, - pets: ['Dog'] + name: { + first: 'Tony', + last: 'Tonison' + }, + pets: ['Dog'] } const mergeNames = (nameA, nameB) => `${nameA.first} and ${nameB.first}` const options = { - customMerge: (key) => { - if (key === 'name') { - return mergeNames - } - } + customMerge: (key) => { + if (key === 'name') { + return mergeNames + } + } } const result = merge(alex, tony, options) From dc8df6b95306dd355cae35ec8916e0021db0fcae Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 17 Nov 2020 13:49:34 +1300 Subject: [PATCH 05/36] chore(editorconfig): use space instead of tabs for yaml files --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 6b9a3da..d6ed4f3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,6 +12,10 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = false +[*.yml] +indent_style = space +indent_size = 2 + [{package.json,package-lock.json}] indent_style = space indent_size = 2 From 29b862b59c69c241a1ff0d2dbeb8c7e569075989 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 11 Nov 2020 15:03:18 +1300 Subject: [PATCH 06/36] chore: use files field in package.json instead of .npmignore --- .npmignore | 3 --- package.json | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 8dfabbd..0000000 --- a/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -test/ -.gitignore -.travis.yml diff --git a/package.json b/package.json index 18aa588..23dca3d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,13 @@ "type": "git", "url": "git://github.com/TehShrike/deepmerge.git" }, + "files": [ + "dist", + "index.d.ts", + "changelog.md", + "license.txt", + "readme.md" + ], "main": "dist/cjs.js", "engines": { "node": ">=0.10.0" From c32dfd4c53c147843953736320a2676e9e4326ae Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 11:46:22 +1300 Subject: [PATCH 07/36] chore: sort package.json fields --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 23dca3d..3628a8d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "deepmerge", + "version": "4.2.2", "description": "A library for deep (recursive) merging of Javascript objects", "keywords": [ "merge", @@ -9,12 +10,13 @@ "clone", "recursive" ], - "version": "4.2.2", "homepage": "https://github.com/TehShrike/deepmerge", "repository": { "type": "git", "url": "git://github.com/TehShrike/deepmerge.git" }, + "license": "MIT", + "main": "dist/cjs.js", "files": [ "dist", "index.d.ts", @@ -22,16 +24,13 @@ "license.txt", "readme.md" ], - "main": "dist/cjs.js", - "engines": { - "node": ">=0.10.0" - }, "scripts": { "build": "rollup -c", + "size": "npm run build && uglifyjs --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", "test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript", - "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts", - "size": "npm run build && uglifyjs --compress --mangle -- ./dist/umd.js | gzip -c | wc -c" + "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts" }, + "dependencies": {}, "devDependencies": { "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", @@ -45,6 +44,7 @@ "typescript": "=2.2.2", "uglify-js": "^3.6.1" }, - "license": "MIT", - "dependencies": {} + "engines": { + "node": ">=0.10.0" + } } From b62e6e1215d81f24f638797581a3ad8461b55a53 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 15:07:55 +1300 Subject: [PATCH 08/36] refactor: move src file to src/ --- rollup.config.js | 2 +- index.js => src/index.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename index.js => src/index.js (100%) diff --git a/rollup.config.js b/rollup.config.js index 8323ab2..686f5f9 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs' import pkg from './package.json' export default { - input: `index.js`, + input: `src/index.js`, plugins: [ commonjs(), resolve(), diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js From 48a6eaf85c498fee8d175bb1d027948cd68aa174 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 15:10:08 +1300 Subject: [PATCH 09/36] refactor: move typedefs to types/ --- package.json | 3 ++- index.d.ts => types/index.d.ts | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename index.d.ts => types/index.d.ts (100%) diff --git a/package.json b/package.json index 3628a8d..bebcba7 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,10 @@ }, "license": "MIT", "main": "dist/cjs.js", + "types": "types/index.d.ts", "files": [ "dist", - "index.d.ts", + "types", "changelog.md", "license.txt", "readme.md" diff --git a/index.d.ts b/types/index.d.ts similarity index 100% rename from index.d.ts rename to types/index.d.ts From e246c6105ac0758e2681c812d1333acb8dd6d6af Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 12:11:39 +1300 Subject: [PATCH 10/36] chore(devdeps): update rollup to v2.33.1 update rollup plugins as well --- package-lock.json | 246 +++++++++++++++++++++++++++++----------------- package.json | 6 +- rollup.config.js | 6 +- 3 files changed, 164 insertions(+), 94 deletions(-) diff --git a/package-lock.json b/package-lock.json index 236e80c..81bd500 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,125 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@rollup/plugin-commonjs": { + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-16.0.0.tgz", + "integrity": "sha512-LuNyypCP3msCGVQJ7ki8PqYdpjfEkE/xtFa5DqlF+7IBD0JsfMZ87C58heSwIMint58sAUZbt3ITqOmdQv/dXw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "commondir": "^1.0.1", + "estree-walker": "^2.0.1", + "glob": "^7.1.6", + "is-reference": "^1.2.1", + "magic-string": "^0.25.7", + "resolve": "^1.17.0" + }, + "dependencies": { + "estree-walker": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.1.tgz", + "integrity": "sha512-tF0hv+Yi2Ot1cwj9eYHtxC0jB9bmjacjQs6ZBTj82H8JwUywFuc+7E83NWfNMwHXZc11mjfFcVXPe9gEP4B8dg==", + "dev": true + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, + "magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, + "resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "requires": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + } + } + } + }, + "@rollup/plugin-node-resolve": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-10.0.0.tgz", + "integrity": "sha512-sNijGta8fqzwA1VwUEtTvWCx2E7qC70NMsDh4ZG13byAXYigBNZMxALhKUSycBks5gupJdq0lFrKumFrRZ8H3A==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "@types/resolve": "1.17.1", + "builtin-modules": "^3.1.0", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.17.0" + }, + "dependencies": { + "@types/resolve": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", + "integrity": "sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "requires": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + } + } + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", @@ -16,21 +135,6 @@ "integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg==", "dev": true }, - "@types/resolve": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", - "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, - "acorn": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", - "integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==", - "dev": true - }, "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", @@ -71,6 +175,12 @@ "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", "dev": true }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -89,6 +199,12 @@ "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "deepmerge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", + "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", + "dev": true + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -166,12 +282,6 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, - "estree-walker": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", - "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", - "dev": true - }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -199,6 +309,13 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -256,6 +373,15 @@ "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", "dev": true }, + "is-core-module": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.1.0.tgz", + "integrity": "sha512-YcV7BgVMRFRua2FqQzKtTDMz8iCuLEyGKjr70q8Zm1yy2qKcurbFEd79PAdHV77oL3NrAaOVQIbMmiHQCHB7ZA==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "is-date-object": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", @@ -280,15 +406,6 @@ "integrity": "sha512-EYisGhpgSCwspmIuRHGjROWTon2Xp8Z7U03Wubk/bTL5TTRC5R1rGVgyjzBrk9+ULdH6cRD06KRcw/xfqhVYKQ==", "dev": true }, - "is-reference": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", - "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", - "dev": true, - "requires": { - "@types/estree": "0.0.39" - } - }, "is-regex": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", @@ -330,15 +447,6 @@ "type-check": "~0.3.2" } }, - "magic-string": { - "version": "0.25.4", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.4.tgz", - "integrity": "sha512-oycWO9nEVAP2RVPbIoDoA4Y7LFIJ3xRYov93gAyJhZkET1tNuB0u7uWkZS2LpBWTJUWnmau/To8ECWRC+jKNfw==", - "dev": true, - "requires": { - "sourcemap-codec": "^1.4.4" - } - }, "make-error": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", @@ -430,21 +538,18 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "picomatch": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", + "dev": true + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, - "resolve": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", - "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - }, "resumer": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", @@ -455,49 +560,12 @@ } }, "rollup": { - "version": "1.23.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.23.1.tgz", - "integrity": "sha512-95C1GZQpr/NIA0kMUQmSjuMDQ45oZfPgDBcN0yZwBG7Kee//m7H68vgIyg+SPuyrTZ5PrXfyLK80OzXeKG5dAA==", - "dev": true, - "requires": { - "@types/estree": "*", - "@types/node": "*", - "acorn": "^7.1.0" - } - }, - "rollup-plugin-commonjs": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz", - "integrity": "sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q==", - "dev": true, - "requires": { - "estree-walker": "^0.6.1", - "is-reference": "^1.1.2", - "magic-string": "^0.25.2", - "resolve": "^1.11.0", - "rollup-pluginutils": "^2.8.1" - } - }, - "rollup-plugin-node-resolve": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", - "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", - "dev": true, - "requires": { - "@types/resolve": "0.0.8", - "builtin-modules": "^3.1.0", - "is-module": "^1.0.0", - "resolve": "^1.11.1", - "rollup-pluginutils": "^2.8.1" - } - }, - "rollup-pluginutils": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", - "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "version": "2.33.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.33.1.tgz", + "integrity": "sha512-uY4O/IoL9oNW8MMcbA5hcOaz6tZTMIh7qJHx/tzIJm+n1wLoY38BLn6fuy7DhR57oNFLMbDQtDeJoFURt5933w==", "dev": true, "requires": { - "estree-walker": "^0.6.1" + "fsevents": "~2.1.2" } }, "source-map": { diff --git a/package.json b/package.json index bebcba7..2761fa3 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,13 @@ }, "dependencies": {}, "devDependencies": { + "@rollup/plugin-commonjs": "^16.0.0", + "@rollup/plugin-node-resolve": "^10.0.0", "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", "is-plain-obj": "^2.0.0", "jsmd": "^1.0.2", - "rollup": "^1.23.1", - "rollup-plugin-commonjs": "^10.1.0", - "rollup-plugin-node-resolve": "^5.2.0", + "rollup": "^2.33.1", "tape": "^4.11.0", "ts-node": "7.0.1", "typescript": "=2.2.2", diff --git a/rollup.config.js b/rollup.config.js index 686f5f9..cd5527c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,7 @@ -import resolve from 'rollup-plugin-node-resolve' -import commonjs from 'rollup-plugin-commonjs' +// @ts-check + +import resolve from '@rollup/plugin-node-resolve' +import commonjs from '@rollup/plugin-commonjs' import pkg from './package.json' export default { From 6f2930b93bb461e31a71afba509219eb2bcb02dc Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 15:16:49 +1300 Subject: [PATCH 11/36] chore(devdeps): update is-plain-obj to v3.0.0 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 81bd500..b0ea70c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -401,9 +401,9 @@ "dev": true }, "is-plain-obj": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.0.0.tgz", - "integrity": "sha512-EYisGhpgSCwspmIuRHGjROWTon2Xp8Z7U03Wubk/bTL5TTRC5R1rGVgyjzBrk9+ULdH6cRD06KRcw/xfqhVYKQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-3.0.0.tgz", + "integrity": "sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==", "dev": true }, "is-regex": { diff --git a/package.json b/package.json index 2761fa3..2a60b37 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@rollup/plugin-node-resolve": "^10.0.0", "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", - "is-plain-obj": "^2.0.0", + "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", "rollup": "^2.33.1", "tape": "^4.11.0", From 1a82cba34afe8d0e7c048fa66650f1025b4f2ae8 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 15:21:54 +1300 Subject: [PATCH 12/36] chore(devdeps): update tape to v5.0.1 --- package-lock.json | 481 ++++++++++++++++++++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 400 insertions(+), 83 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0ea70c..61ad3b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -135,12 +135,27 @@ "integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg==", "dev": true }, + "array-filter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz", + "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=", + "dev": true + }, "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, + "available-typed-arrays": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz", + "integrity": "sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ==", + "dev": true, + "requires": { + "array-filter": "^1.0.0" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -169,6 +184,16 @@ "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", "dev": true }, + "call-bind": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz", + "integrity": "sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.0" + } + }, "commander": { "version": "2.20.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", @@ -188,10 +213,26 @@ "dev": true }, "deep-equal": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", - "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", - "dev": true + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.0.4.tgz", + "integrity": "sha512-BUfaXrVoCfgkOQY/b09QdO9L3XNoF2XH0A3aY9IQwQL/ZjLOe8FQgCNVl1wiolhsFo8kFdO9zdPViCPbmaJA5w==", + "dev": true, + "requires": { + "es-abstract": "^1.18.0-next.1", + "es-get-iterator": "^1.1.0", + "is-arguments": "^1.0.4", + "is-date-object": "^1.0.2", + "is-regex": "^1.1.1", + "isarray": "^2.0.5", + "object-is": "^1.1.3", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "regexp.prototype.flags": "^1.3.0", + "side-channel": "^1.0.3", + "which-boxed-primitive": "^1.0.1", + "which-collection": "^1.0.1", + "which-typed-array": "^1.1.2" + } }, "deep-is": { "version": "0.1.3", @@ -220,28 +261,55 @@ "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", "dev": true }, + "dotignore": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz", + "integrity": "sha512-UGGGWfSauusaVJC+8fgV+NVvBXkCTmVv7sk6nojDZZvuOUNGUy0Zk4UpHQD6EDjS0jpBwcACvH4eofvyzBcRDw==", + "dev": true, + "requires": { + "minimatch": "^3.0.4" + } + }, "es-abstract": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.15.0.tgz", - "integrity": "sha512-bhkEqWJ2t2lMeaJDuk7okMkJWI/yqgH/EoGwpcvv0XW9RWQsRspI4wt6xuyuvMvvQE3gg/D9HXppgk21w78GyQ==", + "version": "1.18.0-next.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", + "integrity": "sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA==", "dev": true, "requires": { - "es-to-primitive": "^1.2.0", + "es-to-primitive": "^1.2.1", "function-bind": "^1.1.1", "has": "^1.0.3", - "has-symbols": "^1.0.0", - "is-callable": "^1.1.4", - "is-regex": "^1.0.4", - "object-inspect": "^1.6.0", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-negative-zero": "^2.0.0", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", "object-keys": "^1.1.1", - "string.prototype.trimleft": "^2.1.0", - "string.prototype.trimright": "^2.1.0" + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + }, + "es-get-iterator": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.1.tgz", + "integrity": "sha512-qorBw8Y7B15DVLaJWy6WdEV/ZkieBcu6QCq/xzWzGOKJqgG1j754vXRfZ3NY7HSShneqU43mPB4OkQBTkvHhFw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.1", + "has-symbols": "^1.0.1", + "is-arguments": "^1.0.4", + "is-map": "^2.0.1", + "is-set": "^2.0.1", + "is-string": "^1.0.5", + "isarray": "^2.0.5" } }, "es-to-primitive": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", - "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", "dev": true, "requires": { "is-callable": "^1.1.4", @@ -303,6 +371,12 @@ "is-callable": "^1.1.3" } }, + "foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", + "dev": true + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -322,10 +396,21 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "get-intrinsic": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.0.1.tgz", + "integrity": "sha512-ZnWP+AmS1VUaLgTRy47+zKtjTxz+0xMpx3I52i+aalBK1QP19ggLF3Db89KJX7kjfOfP2eoa01qc++GwPgufPg==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + } + }, "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", "dev": true, "requires": { "fs.realpath": "^1.0.0", @@ -346,9 +431,9 @@ } }, "has-symbols": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", - "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", "dev": true }, "inflight": { @@ -367,10 +452,28 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "is-arguments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==", + "dev": true + }, + "is-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.0.tgz", + "integrity": "sha512-t5mGUXC/xRheCK431ylNiSkGGpBp8bHENBcENTkDT6ppwPzEVxNGZRvgvmOEfbWkFhA7D2GEuE2mmQTr78sl2g==", + "dev": true + }, + "is-boolean-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.0.1.tgz", + "integrity": "sha512-TqZuVwa/sppcrhUCAYkGBk7w0yxfQQnxq28fjkO53tnK9FQXmdwz2JS5+GjsWQ6RByES1K40nI+yDic5c9/aAQ==", + "dev": true + }, "is-callable": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", - "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz", + "integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA==", "dev": true }, "is-core-module": { @@ -383,9 +486,15 @@ } }, "is-date-object": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", - "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", + "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", + "dev": true + }, + "is-map": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.1.tgz", + "integrity": "sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw==", "dev": true }, "is-mergeable-object": { @@ -400,6 +509,18 @@ "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", "dev": true }, + "is-negative-zero": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.0.tgz", + "integrity": "sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE=", + "dev": true + }, + "is-number-object": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.4.tgz", + "integrity": "sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw==", + "dev": true + }, "is-plain-obj": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-3.0.0.tgz", @@ -407,23 +528,86 @@ "dev": true }, "is-regex": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", - "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", + "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", "dev": true, "requires": { - "has": "^1.0.1" + "has-symbols": "^1.0.1" } }, + "is-set": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.1.tgz", + "integrity": "sha512-eJEzOtVyenDs1TMzSQ3kU3K+E0GUS9sno+F0OBT97xsgcJsF9nXMBtkT9/kut5JEpM7oL7X/0qxR17K3mcwIAA==", + "dev": true + }, + "is-string": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz", + "integrity": "sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ==", + "dev": true + }, "is-symbol": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", - "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", + "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "dev": true, + "requires": { + "has-symbols": "^1.0.1" + } + }, + "is-typed-array": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.3.tgz", + "integrity": "sha512-BSYUBOK/HJibQ30wWkWold5txYwMUXQct9YHAQJr8fSwvZoiglcqB0pd7vEN23+Tsi9IUEjztdOSzl4qLVYGTQ==", "dev": true, "requires": { - "has-symbols": "^1.0.0" + "available-typed-arrays": "^1.0.0", + "es-abstract": "^1.17.4", + "foreach": "^2.0.5", + "has-symbols": "^1.0.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.7.tgz", + "integrity": "sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + } } }, + "is-weakmap": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.1.tgz", + "integrity": "sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA==", + "dev": true + }, + "is-weakset": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.1.tgz", + "integrity": "sha512-pi4vhbhVHGLxohUw7PhGsueT4vRGFoXhP7+RGN0jKIv9+8PWYCQTqtADngrxOm2g46hoH0+g8uZZBzMrvVGDmw==", + "dev": true + }, + "isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true + }, "jsmd": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/jsmd/-/jsmd-1.0.2.tgz", @@ -492,17 +676,39 @@ } }, "object-inspect": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", - "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", + "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==", "dev": true }, + "object-is": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.3.tgz", + "integrity": "sha512-teyqLvFWzLkq5B9ki8FVWA902UER2qkxmdA4nLf+wjOLAWgxzCWZNCxpDq9MvE8MmhWNr+I8w3BN49Vx36Y6Xg==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.1" + } + }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -550,6 +756,47 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "regexp.prototype.flags": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz", + "integrity": "sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ==", + "dev": true, + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.7.tgz", + "integrity": "sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + } + } + }, + "resolve": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", + "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==", + "dev": true, + "requires": { + "is-core-module": "^2.1.0", + "path-parse": "^1.0.6" + } + }, "resumer": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", @@ -568,6 +815,16 @@ "fsevents": "~2.1.2" } }, + "side-channel": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.3.tgz", + "integrity": "sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g==", + "dev": true, + "requires": { + "es-abstract": "^1.18.0-next.0", + "object-inspect": "^1.8.0" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -599,65 +856,65 @@ "dev": true }, "string.prototype.trim": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz", - "integrity": "sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo=", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.2.tgz", + "integrity": "sha512-b5yrbl3BXIjHau9Prk7U0RRYcUYdN4wGSVaqoBQS50CCE3KBuYU0TYRNPFCP7aVoNMX87HKThdMRVIP3giclKg==", "dev": true, "requires": { - "define-properties": "^1.1.2", - "es-abstract": "^1.5.0", - "function-bind": "^1.0.2" + "define-properties": "^1.1.3", + "es-abstract": "^1.18.0-next.0" } }, - "string.prototype.trimleft": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.0.tgz", - "integrity": "sha512-FJ6b7EgdKxxbDxc79cOlok6Afd++TTs5szo+zJTUyow3ycrRfJVE2pq3vcN53XexvKZu/DJMDfeI/qMiZTrjTw==", + "string.prototype.trimend": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.2.tgz", + "integrity": "sha512-8oAG/hi14Z4nOVP0z6mdiVZ/wqjDtWSLygMigTzAb+7aPEDTleeFf+WrF+alzecxIRkckkJVn+dTlwzJXORATw==", "dev": true, "requires": { "define-properties": "^1.1.3", - "function-bind": "^1.1.1" + "es-abstract": "^1.18.0-next.1" } }, - "string.prototype.trimright": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.0.tgz", - "integrity": "sha512-fXZTSV55dNBwv16uw+hh5jkghxSnc5oHq+5K/gXgizHwAvMetdAJlHqqoFC1FSDVPYWLkAKl2cxpUT41sV7nSg==", + "string.prototype.trimstart": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.2.tgz", + "integrity": "sha512-7F6CdBTl5zyu30BJFdzSTlSlLPwODC23Od+iLoVH8X6+3fvDPPuBVVj9iaB1GOsSTSIgVfsfm27R2FGrAPznWg==", "dev": true, "requires": { "define-properties": "^1.1.3", - "function-bind": "^1.1.1" + "es-abstract": "^1.18.0-next.1" } }, "tape": { - "version": "4.11.0", - "resolved": "https://registry.npmjs.org/tape/-/tape-4.11.0.tgz", - "integrity": "sha512-yixvDMX7q7JIs/omJSzSZrqulOV51EC9dK8dM0TzImTIkHWfe2/kFyL5v+d9C+SrCMaICk59ujsqFAVidDqDaA==", - "dev": true, - "requires": { - "deep-equal": "~1.0.1", - "defined": "~1.0.0", - "for-each": "~0.3.3", - "function-bind": "~1.1.1", - "glob": "~7.1.4", - "has": "~1.0.3", - "inherits": "~2.0.4", - "minimist": "~1.2.0", - "object-inspect": "~1.6.0", - "resolve": "~1.11.1", - "resumer": "~0.0.0", - "string.prototype.trim": "~1.1.2", - "through": "~2.3.8" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/tape/-/tape-5.0.1.tgz", + "integrity": "sha512-wVsOl2shKPcjdJdc8a+PwacvrOdJZJ57cLUXlxW4TQ2R6aihXwG0m0bKm4mA4wjtQNTaLMCrYNEb4f9fjHKUYQ==", + "dev": true, + "requires": { + "deep-equal": "^2.0.3", + "defined": "^1.0.0", + "dotignore": "^0.1.2", + "for-each": "^0.3.3", + "function-bind": "^1.1.1", + "glob": "^7.1.6", + "has": "^1.0.3", + "inherits": "^2.0.4", + "is-regex": "^1.0.5", + "minimist": "^1.2.5", + "object-inspect": "^1.7.0", + "object-is": "^1.1.2", + "object.assign": "^4.1.0", + "resolve": "^1.17.0", + "resumer": "^0.0.0", + "string.prototype.trim": "^1.2.1", + "through": "^2.3.8" }, "dependencies": { - "resolve": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", - "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true } } }, @@ -721,6 +978,66 @@ "from": "github:jkroso/v8-argv#1.1.1", "dev": true }, + "which-boxed-primitive": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz", + "integrity": "sha512-7BT4TwISdDGBgaemWU0N0OU7FeAEJ9Oo2P1PHRm/FCWoEi2VLWC9b6xvxAA3C/NMpxg3HXVgi0sMmGbNUbNepQ==", + "dev": true, + "requires": { + "is-bigint": "^1.0.0", + "is-boolean-object": "^1.0.0", + "is-number-object": "^1.0.3", + "is-string": "^1.0.4", + "is-symbol": "^1.0.2" + } + }, + "which-collection": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.1.tgz", + "integrity": "sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A==", + "dev": true, + "requires": { + "is-map": "^2.0.1", + "is-set": "^2.0.1", + "is-weakmap": "^2.0.1", + "is-weakset": "^2.0.1" + } + }, + "which-typed-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.2.tgz", + "integrity": "sha512-KT6okrd1tE6JdZAy3o2VhMoYPh3+J6EMZLyrxBQsZflI1QCZIxMrIYLkosd8Twf+YfknVIHmYQPgJt238p8dnQ==", + "dev": true, + "requires": { + "available-typed-arrays": "^1.0.2", + "es-abstract": "^1.17.5", + "foreach": "^2.0.5", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.1", + "is-typed-array": "^1.1.3" + }, + "dependencies": { + "es-abstract": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.7.tgz", + "integrity": "sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.2.2", + "is-regex": "^1.1.1", + "object-inspect": "^1.8.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.1", + "string.prototype.trimend": "^1.0.1", + "string.prototype.trimstart": "^1.0.1" + } + } + } + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", diff --git a/package.json b/package.json index 2a60b37..591f964 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", "rollup": "^2.33.1", - "tape": "^4.11.0", + "tape": "^5.0.1", "ts-node": "7.0.1", "typescript": "=2.2.2", "uglify-js": "^3.6.1" From a27988f84d5cd6c10e3b43b3c3461b980b7e162a Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 15:29:45 +1300 Subject: [PATCH 13/36] chore(devdeps): replace uglify-js with more modern terser --- package-lock.json | 35 ++++++++++++++++++++++------------- package.json | 7 +++---- readme.md | 2 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61ad3b0..d766d7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -195,9 +195,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, "commondir": { @@ -918,6 +918,25 @@ } } }, + "terser": { + "version": "5.3.8", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.3.8.tgz", + "integrity": "sha512-zVotuHoIfnYjtlurOouTazciEfL7V38QMAOhGqpXDEg6yT13cF4+fEP9b0rrCEQTn+tT46uxgFsTZzhygk+CzQ==", + "dev": true, + "requires": { + "commander": "^2.20.0", + "source-map": "~0.7.2", + "source-map-support": "~0.5.19" + }, + "dependencies": { + "source-map": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", + "dev": true + } + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -963,16 +982,6 @@ "integrity": "sha1-YGAiUIR5tV/6NotY/uljoD39eww=", "dev": true }, - "uglify-js": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz", - "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==", - "dev": true, - "requires": { - "commander": "2.20.0", - "source-map": "~0.6.1" - } - }, "v8-argv": { "version": "github:jkroso/v8-argv#284f84379e292eb956a5e7b66fb953ec4974385e", "from": "github:jkroso/v8-argv#1.1.1", diff --git a/package.json b/package.json index 591f964..26c9e2f 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ ], "scripts": { "build": "rollup -c", - "size": "npm run build && uglifyjs --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", + "size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", "test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript", "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts" }, @@ -41,9 +41,8 @@ "jsmd": "^1.0.2", "rollup": "^2.33.1", "tape": "^5.0.1", - "ts-node": "7.0.1", - "typescript": "=2.2.2", - "uglify-js": "^3.6.1" + "terser": "^5.3.8", + "typescript": "=2.2.2" }, "engines": { "node": ">=0.10.0" diff --git a/readme.md b/readme.md index a129984..5d4268b 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ Merges the enumerable properties of two or more objects deeply. -> UMD bundle is 723B minified+gzipped +> UMD bundle is 716B minified+gzipped ## Getting Started From 4e74235f75e886a8fc773552320559f9c4ca326f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 12 Nov 2020 16:16:48 +1300 Subject: [PATCH 14/36] build(typescript): add typescript and setup the build to build with typescript --- .gitignore | 1 + package-lock.json | 122 +++++++++-------------------- package.json | 9 ++- rollup.config.js | 6 +- src/{index.js => index.ts} | 9 +-- test/custom-array-merge.js | 2 +- test/custom-is-mergeable-object.js | 2 +- test/merge-all.js | 20 ++--- test/merge-plain-objects.js | 68 ++++++++-------- test/merge.js | 2 +- test/prototype-poisoning.js | 2 +- test/typescript.ts | 12 +-- tsconfig.json | 21 +++++ tsconfig.typedef.json | 10 +++ types/index.d.ts | 16 ---- 15 files changed, 137 insertions(+), 165 deletions(-) rename src/{index.js => index.ts} (94%) create mode 100644 tsconfig.json create mode 100644 tsconfig.typedef.json delete mode 100644 types/index.d.ts diff --git a/.gitignore b/.gitignore index b0fb09f..73a7d5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist/* +types/* diff --git a/package-lock.json b/package-lock.json index d766d7c..4065bef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -104,6 +104,16 @@ } } }, + "@rollup/plugin-typescript": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-6.1.0.tgz", + "integrity": "sha512-hJxaiE6WyNOsK+fZpbFh9CUijZYqPQuAOWO5khaGTUkM8DYNNyA2TDlgamecE+qLOG1G1+CwbWMAx3rbqpp6xQ==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.1.0", + "resolve": "^1.17.0" + } + }, "@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", @@ -141,12 +151,6 @@ "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=", "dev": true }, - "arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", - "dev": true - }, "available-typed-arrays": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz", @@ -631,12 +635,6 @@ "type-check": "~0.3.2" } }, - "make-error": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", - "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", - "dev": true - }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", @@ -652,29 +650,6 @@ "brace-expansion": "^1.1.7" } }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } - } - }, "object-inspect": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", @@ -829,25 +804,8 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - }, - "source-map-support": { - "version": "0.5.9", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.9.tgz", - "integrity": "sha512-gR6Rw4MvUlYy83vP0vxoVNzM6t8MUXqNuRsuBmBHQDu1Fh6X015FrLdgoDKcNdkwGubozq0P4N0Q37UyFVr1EA==", "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } + "optional": true }, "sourcemap-codec": { "version": "1.4.6", @@ -934,6 +892,24 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } } } }, @@ -943,29 +919,11 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, - "ts-node": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", - "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", - "dev": true, - "requires": { - "arrify": "^1.0.0", - "buffer-from": "^1.1.0", - "diff": "^3.1.0", - "make-error": "^1.1.1", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "source-map-support": "^0.5.6", - "yn": "^2.0.0" - }, - "dependencies": { - "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", - "dev": true - } - } + "tslib": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz", + "integrity": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==", + "dev": true }, "type-check": { "version": "0.3.2", @@ -977,9 +935,9 @@ } }, "typescript": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.2.2.tgz", - "integrity": "sha1-YGAiUIR5tV/6NotY/uljoD39eww=", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", + "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", "dev": true }, "v8-argv": { @@ -1058,12 +1016,6 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true - }, - "yn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", - "dev": true } } } diff --git a/package.json b/package.json index 26c9e2f..bc0094c 100644 --- a/package.json +++ b/package.json @@ -26,15 +26,17 @@ "readme.md" ], "scripts": { - "build": "rollup -c", + "build": "rollup -c && npm run typedef", "size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", "test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript", - "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts" + "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts", + "typedef": "tsc -p tsconfig.typedef.json" }, "dependencies": {}, "devDependencies": { "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-node-resolve": "^10.0.0", + "@rollup/plugin-typescript": "^6.1.0", "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", "is-plain-obj": "^3.0.0", @@ -42,7 +44,8 @@ "rollup": "^2.33.1", "tape": "^5.0.1", "terser": "^5.3.8", - "typescript": "=2.2.2" + "tslib": "^2.0.3", + "typescript": "^4.1.2" }, "engines": { "node": ">=0.10.0" diff --git a/rollup.config.js b/rollup.config.js index cd5527c..ec2c616 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,13 +2,15 @@ import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' +import typescript from '@rollup/plugin-typescript'; import pkg from './package.json' export default { - input: `src/index.js`, + input: `src/index.ts`, plugins: [ - commonjs(), resolve(), + commonjs(), + typescript() ], output: [ { diff --git a/src/index.js b/src/index.ts similarity index 94% rename from src/index.js rename to src/index.ts index 6ca53ce..285bf47 100644 --- a/src/index.js +++ b/src/index.ts @@ -1,4 +1,5 @@ -var isPlainObj = require('is-plain-obj') +import isPlainObj from 'is-plain-obj'; + function defaultIsMergeable(value) { return Array.isArray(value) || isPlainObj(value) } @@ -75,7 +76,7 @@ function mergeObject(target, source, options) { return destination } -function deepmerge(target, source, options) { +export default function deepmerge(target, source, options) { options = Object.assign({ arrayMerge: defaultArrayMerge, isMergeable: defaultIsMergeable @@ -96,7 +97,7 @@ function deepmerge(target, source, options) { } } -deepmerge.all = function deepmergeAll(array, options) { +export function deepmergeAll(array, options) { if (!Array.isArray(array)) { throw new Error('first argument should be an array') } @@ -105,5 +106,3 @@ deepmerge.all = function deepmergeAll(array, options) { return deepmerge(prev, next, options) }, {}) } - -module.exports = deepmerge diff --git a/test/custom-array-merge.js b/test/custom-array-merge.js index 0a81100..4931369 100644 --- a/test/custom-array-merge.js +++ b/test/custom-array-merge.js @@ -1,4 +1,4 @@ -var merge = require('../') +var merge = require('../').default var test = require('tape') test('custom merge array', function(t) { diff --git a/test/custom-is-mergeable-object.js b/test/custom-is-mergeable-object.js index b3654f4..44cde16 100644 --- a/test/custom-is-mergeable-object.js +++ b/test/custom-is-mergeable-object.js @@ -1,4 +1,4 @@ -var merge = require('../') +var merge = require('../').default var test = require('tape') test('isMergeable function copying object over object', function(t) { diff --git a/test/merge-all.js b/test/merge-all.js index 4627e77..005a852 100644 --- a/test/merge-all.js +++ b/test/merge-all.js @@ -1,18 +1,18 @@ -var merge = require('../') +var mergeAll = require('../').deepmergeAll var test = require('tape') test('throw error if first argument is not an array', function(t) { - t.throws(merge.all.bind(null, { example: true }, { another: '2' }), Error) + t.throws(mergeAll.bind(null, { example: true }, { another: '2' }), Error) t.end() }) test('return an empty object if first argument is an array with no elements', function(t) { - t.deepEqual(merge.all([]), {}) + t.deepEqual(mergeAll([]), {}) t.end() }) test('Work just fine if first argument is an array with least than two elements', function(t) { - var actual = merge.all([{ example: true }]) + var actual = mergeAll([{ example: true }]) var expected = { example: true } t.deepEqual(actual, expected) t.end() @@ -20,13 +20,13 @@ test('Work just fine if first argument is an array with least than two elements' test('execute correctly if options object were not passed', function(t) { var arrayToMerge = [{ example: true }, { another: '123' }] - t.doesNotThrow(merge.all.bind(null, arrayToMerge)) + t.doesNotThrow(mergeAll.bind(null, arrayToMerge)) t.end() }) test('execute correctly if options object were passed', function(t) { var arrayToMerge = [{ example: true }, { another: '123' }] - t.doesNotThrow(merge.all.bind(null, arrayToMerge, { clone: true })) + t.doesNotThrow(mergeAll.bind(null, arrayToMerge, { clone: true })) t.end() }) @@ -36,7 +36,7 @@ test('invoke merge on every item in array should result with all props', functio var thirdObject = { third: 123 } var fourthObject = { fourth: 'some string' } - var mergedObject = merge.all([ firstObject, secondObject, thirdObject, fourthObject ]) + var mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) t.ok(mergedObject.first === true) t.ok(mergedObject.second === false) @@ -50,7 +50,7 @@ test('invoke merge on every item in array with clone should clone all elements', var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithClone = merge.all([ firstObject, secondObject, thirdObject ], { clone: true }) + var mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithClone.a, firstObject.a) t.notEqual(mergedWithClone.b, secondObject.b) @@ -64,7 +64,7 @@ test('invoke merge on every item in array clone=false should not clone all eleme var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithoutClone = merge.all([ firstObject, secondObject, thirdObject ], { clone: false }) + var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) t.equal(mergedWithoutClone.a, firstObject.a) t.equal(mergedWithoutClone.b, secondObject.b) @@ -79,7 +79,7 @@ test('invoke merge on every item in array without clone should clone all element var secondObject = { b: { e: true } } var thirdObject = { c: { f: 'string' } } - var mergedWithoutClone = merge.all([ firstObject, secondObject, thirdObject ]) + var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge-plain-objects.js b/test/merge-plain-objects.js index a112a81..2f16574 100644 --- a/test/merge-plain-objects.js +++ b/test/merge-plain-objects.js @@ -1,34 +1,34 @@ -var merge = require('../') -var test = require('tape') - -test('plain objects are merged by default', function(t) { - const input = { - newObject: new Object(), - objectLiteral: { a: 123 } - } - const output = merge({}, input) - - t.deepEqual(output.newObject, input.newObject) - t.notEqual(output.newObject, input.newObject) - t.deepEqual(output.objectLiteral, input.objectLiteral) - t.notEqual(output.objectLiteral, input.objectLiteral) - - t.end() -}) - -test('instantiated objects are copied by reference', function(t) { - const input = { - date: new Date(), - error: new Error(), - regex: /regex/ - } - const output = merge({}, input) - - t.equal(output.date, input.date) - t.equal(output.error, input.error) - t.equal(output.regex, input.regex) - - t.end() -}) - - +var merge = require('../').default +var test = require('tape') + +test('plain objects are merged by default', function(t) { + const input = { + newObject: new Object(), + objectLiteral: { a: 123 } + } + const output = merge({}, input) + + t.deepEqual(output.newObject, input.newObject) + t.notEqual(output.newObject, input.newObject) + t.deepEqual(output.objectLiteral, input.objectLiteral) + t.notEqual(output.objectLiteral, input.objectLiteral) + + t.end() +}) + +test('instantiated objects are copied by reference', function(t) { + const input = { + date: new Date(), + error: new Error(), + regex: /regex/ + } + const output = merge({}, input) + + t.equal(output.date, input.date) + t.equal(output.error, input.error) + t.equal(output.regex, input.regex) + + t.end() +}) + + diff --git a/test/merge.js b/test/merge.js index 1a99b28..c3e9e65 100644 --- a/test/merge.js +++ b/test/merge.js @@ -1,4 +1,4 @@ -var merge = require('../') +var merge = require('../').default var test = require('tape') test('add keys in target that do not exist at the root', function(t) { diff --git a/test/prototype-poisoning.js b/test/prototype-poisoning.js index 744e54c..34322ed 100644 --- a/test/prototype-poisoning.js +++ b/test/prototype-poisoning.js @@ -1,4 +1,4 @@ -var merge = require('../') +var merge = require('../').default var test = require('tape') var isMergeableObject = require('is-mergeable-object') diff --git a/test/typescript.ts b/test/typescript.ts index f562095..e474cd8 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -1,4 +1,4 @@ -import * as merge from '../'; +import merge, { deepmergeAll, Options } from '../'; const x = { foo: 'abc', @@ -20,7 +20,7 @@ const z = { let merged1 = merge(x, y); let merged2 = merge(x, z); -let merged3 = merge.all<{wat: number}>([ x, y, z ]); +let merged3 = deepmergeAll([ x, y, z ]); merged1.foo; merged1.bar; @@ -29,14 +29,14 @@ merged2.baz; merged3.wat; -const options1: merge.Options = { +const options1: Options = { clone: true, isMergeable (obj) { return false; }, }; -const options2: merge.Options = { +const options2: Options = { arrayMerge (target, source, options) { target.length; source.length; @@ -50,7 +50,7 @@ const options2: merge.Options = { }, }; -const options3: merge.Options = { +const options3: Options = { customMerge: (key) => { if (key === 'foo') { return (target, source) => target + source; @@ -60,6 +60,6 @@ const options3: merge.Options = { merged1 = merge(x, y, options1); merged2 = merge(x, z, options2); -merged3 = merge.all<{wat: number}>([x, y, z], options1); +merged3 = deepmergeAll([x, y, z], options1); const merged4 = merge(x, y, options3); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a4ec8c4 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "ES2020", + "lib": [ + "ES2020" + ], + "moduleResolution": "node", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "removeComments": true, + "baseUrl": ".", + "paths": { + "deepmerge": [ + "src/" + ] + } + } +} diff --git a/tsconfig.typedef.json b/tsconfig.typedef.json new file mode 100644 index 0000000..8cd68ed --- /dev/null +++ b/tsconfig.typedef.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationDir": "types/", + "emitDeclarationOnly": true, + "removeComments": false + }, + "include": ["./src"] +} diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index 20f645a..0000000 --- a/types/index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -declare function deepmerge(x: Partial, y: Partial, options?: deepmerge.Options): T; -declare function deepmerge(x: Partial, y: Partial, options?: deepmerge.Options): T1 & T2; - -declare namespace deepmerge { - export interface Options { - arrayMerge?(target: any[], source: any[], options?: Options): any[]; - clone?: boolean; - customMerge?: (key: string, options?: Options) => ((x: any, y: any) => any) | undefined; - isMergeable?(value: object): boolean; - } - - export function all (objects: object[], options?: Options): object; - export function all (objects: Partial[], options?: Options): T; -} - -export = deepmerge; From 2fb71c277b1efb0f02bf53e44fe7c5021ec20e97 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 15:29:09 +1300 Subject: [PATCH 15/36] refactor: move implementation out of index file --- src/deepmerge.ts | 108 ++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 109 +---------------------------------------------- 2 files changed, 109 insertions(+), 108 deletions(-) create mode 100644 src/deepmerge.ts diff --git a/src/deepmerge.ts b/src/deepmerge.ts new file mode 100644 index 0000000..1db49d1 --- /dev/null +++ b/src/deepmerge.ts @@ -0,0 +1,108 @@ +import isPlainObj from 'is-plain-obj'; + +function defaultIsMergeable(value) { + return Array.isArray(value) || isPlainObj(value) +} + +function emptyTarget(val) { + return Array.isArray(val) ? [] : {} +} + +function cloneUnlessOtherwiseSpecified(value, options) { + return (options.clone !== false && options.isMergeable(value)) + ? deepmerge(emptyTarget(value), value, options) + : value +} + +function defaultArrayMerge(target, source, options) { + return target.concat(source).map(function(element) { + return cloneUnlessOtherwiseSpecified(element, options) + }) +} + +function getMergeFunction(key, options) { + if (!options.customMerge) { + return deepmerge + } + var customMerge = options.customMerge(key) + return typeof customMerge === 'function' ? customMerge : deepmerge +} + +function getEnumerableOwnPropertySymbols(target) { + return Object.getOwnPropertySymbols + ? Object.getOwnPropertySymbols(target).filter(function(symbol) { + return target.propertyIsEnumerable(symbol) + }) + : [] +} + +function getKeys(target) { + return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) +} + +function propertyIsOnObject(object, property) { + try { + return property in object + } catch(_) { + return false + } +} + +// Protects from prototype poisoning and unexpected merging up the prototype chain. +function propertyIsUnsafe(target, key) { + return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, + && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, + && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. +} + +function mergeObject(target, source, options) { + var destination = {} + if (options.isMergeable(target)) { + getKeys(target).forEach(function(key) { + destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) + }) + } + getKeys(source).forEach(function(key) { + if (propertyIsUnsafe(target, key)) { + return + } + + if (!options.isMergeable(source[key]) || !propertyIsOnObject(target, key)) { + destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) + } else { + destination[key] = getMergeFunction(key, options)(target[key], source[key], options) + } + }) + return destination +} + +export default function deepmerge(target, source, options) { + options = Object.assign({ + arrayMerge: defaultArrayMerge, + isMergeable: defaultIsMergeable + }, options, { + cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified + }) + + var sourceIsArray = Array.isArray(source) + var targetIsArray = Array.isArray(target) + var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray + + if (!sourceAndTargetTypesMatch) { + return cloneUnlessOtherwiseSpecified(source, options) + } else if (sourceIsArray) { + return options.arrayMerge(target, source, options) + } else { + return mergeObject(target, source, options) + } +} + +export function deepmergeAll(array, options) { + if (!Array.isArray(array)) { + throw new Error('first argument should be an array') + } + + return array.reduce(function(prev, next) { + return deepmerge(prev, next, options) + }, {}) +} diff --git a/src/index.ts b/src/index.ts index 285bf47..8146336 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,108 +1 @@ -import isPlainObj from 'is-plain-obj'; - -function defaultIsMergeable(value) { - return Array.isArray(value) || isPlainObj(value) -} - -function emptyTarget(val) { - return Array.isArray(val) ? [] : {} -} - -function cloneUnlessOtherwiseSpecified(value, options) { - return (options.clone !== false && options.isMergeable(value)) - ? deepmerge(emptyTarget(value), value, options) - : value -} - -function defaultArrayMerge(target, source, options) { - return target.concat(source).map(function(element) { - return cloneUnlessOtherwiseSpecified(element, options) - }) -} - -function getMergeFunction(key, options) { - if (!options.customMerge) { - return deepmerge - } - var customMerge = options.customMerge(key) - return typeof customMerge === 'function' ? customMerge : deepmerge -} - -function getEnumerableOwnPropertySymbols(target) { - return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter(function(symbol) { - return target.propertyIsEnumerable(symbol) - }) - : [] -} - -function getKeys(target) { - return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) -} - -function propertyIsOnObject(object, property) { - try { - return property in object - } catch(_) { - return false - } -} - -// Protects from prototype poisoning and unexpected merging up the prototype chain. -function propertyIsUnsafe(target, key) { - return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, - && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, - && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. -} - -function mergeObject(target, source, options) { - var destination = {} - if (options.isMergeable(target)) { - getKeys(target).forEach(function(key) { - destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) - }) - } - getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { - return - } - - if (propertyIsOnObject(target, key) && options.isMergeable(source[key])) { - destination[key] = getMergeFunction(key, options)(target[key], source[key], options) - } else { - destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) - } - }) - return destination -} - -export default function deepmerge(target, source, options) { - options = Object.assign({ - arrayMerge: defaultArrayMerge, - isMergeable: defaultIsMergeable - }, options, { - cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified - }) - - var sourceIsArray = Array.isArray(source) - var targetIsArray = Array.isArray(target) - var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray - - if (!sourceAndTargetTypesMatch) { - return cloneUnlessOtherwiseSpecified(source, options) - } else if (sourceIsArray) { - return options.arrayMerge(target, source, options) - } else { - return mergeObject(target, source, options) - } -} - -export function deepmergeAll(array, options) { - if (!Array.isArray(array)) { - throw new Error('first argument should be an array') - } - - return array.reduce(function(prev, next) { - return deepmerge(prev, next, options) - }, {}) -} +export { default, deepmergeAll } from "./deepmerge" From 5646fd68c4c7e0a719bb17f3393bfdbe1c38c6a6 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 15:38:55 +1300 Subject: [PATCH 16/36] refactor: upgrade code --- src/deepmerge.ts | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/deepmerge.ts b/src/deepmerge.ts index 1db49d1..dc2ae31 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -1,4 +1,4 @@ -import isPlainObj from 'is-plain-obj'; +import isPlainObj from 'is-plain-obj' function defaultIsMergeable(value) { return Array.isArray(value) || isPlainObj(value) @@ -15,24 +15,24 @@ function cloneUnlessOtherwiseSpecified(value, options) { } function defaultArrayMerge(target, source, options) { - return target.concat(source).map(function(element) { - return cloneUnlessOtherwiseSpecified(element, options) - }) + return target.concat(source).map((element) => + cloneUnlessOtherwiseSpecified(element, options) + ) } function getMergeFunction(key, options) { if (!options.customMerge) { return deepmerge } - var customMerge = options.customMerge(key) + const customMerge = options.customMerge(key) return typeof customMerge === 'function' ? customMerge : deepmerge } function getEnumerableOwnPropertySymbols(target) { return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter(function(symbol) { - return target.propertyIsEnumerable(symbol) - }) + ? Object.getOwnPropertySymbols(target).filter((symbol) => + target.propertyIsEnumerable(symbol) + ) : [] } @@ -56,13 +56,13 @@ function propertyIsUnsafe(target, key) { } function mergeObject(target, source, options) { - var destination = {} + const destination = {} if (options.isMergeable(target)) { - getKeys(target).forEach(function(key) { + getKeys(target).forEach((key) => { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) }) } - getKeys(source).forEach(function(key) { + getKeys(source).forEach((key) => { if (propertyIsUnsafe(target, key)) { return } @@ -77,16 +77,16 @@ function mergeObject(target, source, options) { } export default function deepmerge(target, source, options) { - options = Object.assign({ + options = { arrayMerge: defaultArrayMerge, - isMergeable: defaultIsMergeable - }, options, { + isMergeable: defaultIsMergeable, + ...options, cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified - }) + } - var sourceIsArray = Array.isArray(source) - var targetIsArray = Array.isArray(target) - var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray + const sourceIsArray = Array.isArray(source) + const targetIsArray = Array.isArray(target) + const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options) @@ -102,7 +102,5 @@ export function deepmergeAll(array, options) { throw new Error('first argument should be an array') } - return array.reduce(function(prev, next) { - return deepmerge(prev, next, options) - }, {}) + return array.reduce((prev, next) => deepmerge(prev, next, options), {}) } From 7b894d13c2c2a30a957c40b5385cd54ece838ca3 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 15:44:46 +1300 Subject: [PATCH 17/36] perf: only compute the full options on the top level call --- src/deepmerge.ts | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/deepmerge.ts b/src/deepmerge.ts index dc2ae31..cfb6afb 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -10,7 +10,7 @@ function emptyTarget(val) { function cloneUnlessOtherwiseSpecified(value, options) { return (options.clone !== false && options.isMergeable(value)) - ? deepmerge(emptyTarget(value), value, options) + ? deepmergeImpl(emptyTarget(value), value, options) : value } @@ -22,10 +22,10 @@ function defaultArrayMerge(target, source, options) { function getMergeFunction(key, options) { if (!options.customMerge) { - return deepmerge + return deepmergeImpl } const customMerge = options.customMerge(key) - return typeof customMerge === 'function' ? customMerge : deepmerge + return typeof customMerge === 'function' ? customMerge : deepmergeImpl } function getEnumerableOwnPropertySymbols(target) { @@ -76,14 +76,7 @@ function mergeObject(target, source, options) { return destination } -export default function deepmerge(target, source, options) { - options = { - arrayMerge: defaultArrayMerge, - isMergeable: defaultIsMergeable, - ...options, - cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified - } - +function deepmergeImpl(target, source, options) { const sourceIsArray = Array.isArray(source) const targetIsArray = Array.isArray(target) const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray @@ -97,10 +90,34 @@ export default function deepmerge(target, source, options) { } } +function getFullOptions(options) { + const overrides = + options === undefined + ? undefined + : (Object.fromEntries( + // Filter out keys explicitly set to undefined. + Object.entries(options).filter(([key, value]) => value !== undefined) + )) + + return { + arrayMerge: defaultArrayMerge, + isMergeable: defaultIsMergeable, + clone: true, + ...overrides, + cloneUnlessOtherwiseSpecified + }; +} + +export default function deepmerge(target, source, options) { + return deepmergeImpl(target, source, getFullOptions(options)) +} + export function deepmergeAll(array, options) { if (!Array.isArray(array)) { throw new Error('first argument should be an array') } - return array.reduce((prev, next) => deepmerge(prev, next, options), {}) + return array.reduce((prev, next) => + deepmergeImpl(prev, next, getFullOptions(options)), {} + ) } From 6e5dcd3e99eb2d4315ffe93523e6ec1e96762297 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 16:01:11 +1300 Subject: [PATCH 18/36] refactor: move utility functions to a utils file --- src/deepmerge.ts | 54 +++++++----------------------------------------- src/utils.ts | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 src/utils.ts diff --git a/src/deepmerge.ts b/src/deepmerge.ts index cfb6afb..b813efd 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -1,60 +1,22 @@ import isPlainObj from 'is-plain-obj' +import { + cloneUnlessOtherwiseSpecified, + getKeys, + getMergeFunction, + propertyIsOnObject, + propertyIsUnsafe +} from './utils' function defaultIsMergeable(value) { return Array.isArray(value) || isPlainObj(value) } -function emptyTarget(val) { - return Array.isArray(val) ? [] : {} -} - -function cloneUnlessOtherwiseSpecified(value, options) { - return (options.clone !== false && options.isMergeable(value)) - ? deepmergeImpl(emptyTarget(value), value, options) - : value -} - function defaultArrayMerge(target, source, options) { return target.concat(source).map((element) => cloneUnlessOtherwiseSpecified(element, options) ) } -function getMergeFunction(key, options) { - if (!options.customMerge) { - return deepmergeImpl - } - const customMerge = options.customMerge(key) - return typeof customMerge === 'function' ? customMerge : deepmergeImpl -} - -function getEnumerableOwnPropertySymbols(target) { - return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter((symbol) => - target.propertyIsEnumerable(symbol) - ) - : [] -} - -function getKeys(target) { - return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) -} - -function propertyIsOnObject(object, property) { - try { - return property in object - } catch(_) { - return false - } -} - -// Protects from prototype poisoning and unexpected merging up the prototype chain. -function propertyIsUnsafe(target, key) { - return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, - && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, - && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. -} - function mergeObject(target, source, options) { const destination = {} if (options.isMergeable(target)) { @@ -76,7 +38,7 @@ function mergeObject(target, source, options) { return destination } -function deepmergeImpl(target, source, options) { +export function deepmergeImpl(target, source, options) { const sourceIsArray = Array.isArray(source) const targetIsArray = Array.isArray(target) const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..a040967 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,45 @@ +import { deepmergeImpl } from './deepmerge'; + +function emptyTarget(value) { + return Array.isArray(value) ? [] : {} +} + +export function cloneUnlessOtherwiseSpecified(value, options) { + return (options.clone !== false && options.isMergeable(value)) + ? deepmergeImpl(emptyTarget(value), value, options) + : value +} + +function getEnumerableOwnPropertySymbols(target) { + return Object.getOwnPropertySymbols + ? Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol) + ) + : []; +} + +export function getKeys(target) { + return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)); +} + +export function propertyIsOnObject(object, property) { + try { + return property in object; + } catch (_) { + return false; + } +} + +export function getMergeFunction(key, options) { + if (!options.customMerge) { + return deepmergeImpl + } + const customMerge = options.customMerge(key) + return typeof customMerge === 'function' ? customMerge : deepmergeImpl +} + +// Protects from prototype poisoning and unexpected merging up the prototype chain. +export function propertyIsUnsafe(target, key) { + return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, + && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, + && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. +} From 837387974ecc094a924864aeccec6967b195e9e4 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 16:06:19 +1300 Subject: [PATCH 19/36] refactor: move options stuff to its own file --- src/deepmerge.ts | 30 +----------------------------- src/options.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 src/options.ts diff --git a/src/deepmerge.ts b/src/deepmerge.ts index b813efd..c5ac725 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -1,4 +1,4 @@ -import isPlainObj from 'is-plain-obj' +import { getFullOptions } from './options' import { cloneUnlessOtherwiseSpecified, getKeys, @@ -7,16 +7,6 @@ import { propertyIsUnsafe } from './utils' -function defaultIsMergeable(value) { - return Array.isArray(value) || isPlainObj(value) -} - -function defaultArrayMerge(target, source, options) { - return target.concat(source).map((element) => - cloneUnlessOtherwiseSpecified(element, options) - ) -} - function mergeObject(target, source, options) { const destination = {} if (options.isMergeable(target)) { @@ -52,24 +42,6 @@ export function deepmergeImpl(target, source, options) { } } -function getFullOptions(options) { - const overrides = - options === undefined - ? undefined - : (Object.fromEntries( - // Filter out keys explicitly set to undefined. - Object.entries(options).filter(([key, value]) => value !== undefined) - )) - - return { - arrayMerge: defaultArrayMerge, - isMergeable: defaultIsMergeable, - clone: true, - ...overrides, - cloneUnlessOtherwiseSpecified - }; -} - export default function deepmerge(target, source, options) { return deepmergeImpl(target, source, getFullOptions(options)) } diff --git a/src/options.ts b/src/options.ts new file mode 100644 index 0000000..7712c06 --- /dev/null +++ b/src/options.ts @@ -0,0 +1,31 @@ +import isPlainObj from "is-plain-obj" + +import { cloneUnlessOtherwiseSpecified } from "./utils" + +function defaultIsMergeable(value) { + return Array.isArray(value) || isPlainObj(value) +} + +function defaultArrayMerge(target, source, options) { + return [...target, ...source].map((element) => + cloneUnlessOtherwiseSpecified(element, options) + ) +} + +export function getFullOptions(options) { + const overrides = + options === undefined + ? undefined + : (Object.fromEntries( + // Filter out keys explicitly set to undefined. + Object.entries(options).filter(([key, value]) => value !== undefined) + )) + + return { + arrayMerge: defaultArrayMerge, + isMergeable: defaultIsMergeable, + clone: true, + ...overrides, + cloneUnlessOtherwiseSpecified + }; +} From 5676ca78b9b370752525202cb8cebbedfbde9a94 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 16:30:51 +1300 Subject: [PATCH 20/36] add typedefs from #211 --- src/deepmerge.ts | 80 ++++++++++++++++----- src/index.ts | 1 + src/options.ts | 74 ++++++++++++++++--- src/types.ts | 182 +++++++++++++++++++++++++++++++++++++++++++++++ src/utils.ts | 42 ++++++----- 5 files changed, 338 insertions(+), 41 deletions(-) create mode 100644 src/types.ts diff --git a/src/deepmerge.ts b/src/deepmerge.ts index c5ac725..43db614 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -1,19 +1,27 @@ -import { getFullOptions } from './options' +import type { ExplicitOptions, FullOptions, Options } from "./options" +import { getFullOptions } from "./options" +import type { DeepMerge, DeepMergeAll, DeepMergeObjects, Property } from "./types" import { cloneUnlessOtherwiseSpecified, getKeys, getMergeFunction, propertyIsOnObject, - propertyIsUnsafe -} from './utils' + propertyIsUnsafe, +} from "./utils" + +function mergeObject< + T1 extends Record, + T2 extends Record, + O extends Options +>(target: T1, source: T2, options: FullOptions): DeepMergeObjects { + const destination: any = {} -function mergeObject(target, source, options) { - const destination = {} if (options.isMergeable(target)) { getKeys(target).forEach((key) => { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) }) } + getKeys(source).forEach((key) => { if (propertyIsUnsafe(target, key)) { return @@ -25,33 +33,73 @@ function mergeObject(target, source, options) { destination[key] = getMergeFunction(key, options)(target[key], source[key], options) } }) + return destination } -export function deepmergeImpl(target, source, options) { +export function deepmergeImpl( + target: T1, + source: T2, + options: FullOptions +): DeepMerge> { const sourceIsArray = Array.isArray(source) const targetIsArray = Array.isArray(target) const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray if (!sourceAndTargetTypesMatch) { - return cloneUnlessOtherwiseSpecified(source, options) + return cloneUnlessOtherwiseSpecified(source, options) as DeepMerge> } else if (sourceIsArray) { - return options.arrayMerge(target, source, options) + return options.arrayMerge(target as unknown[], source as unknown[], options) as DeepMerge< + T1, + T2, + ExplicitOptions + > } else { - return mergeObject(target, source, options) + return mergeObject( + target as Record, + source as Record, + options + ) as DeepMerge> } } -export default function deepmerge(target, source, options) { +/** + * Deeply merge two objects. + * + * @param target The first object. + * @param source The second object. + * @param options Deep merge options. + */ +export default function deepmerge< + T1 extends object, + T2 extends object, + O extends Options = {} +>(target: T1, source: T2, options?: O) { return deepmergeImpl(target, source, getFullOptions(options)) } -export function deepmergeAll(array, options) { - if (!Array.isArray(array)) { - throw new Error('first argument should be an array') +/** + * Deeply merge two or more objects. + * + * @param objects An tuple of the objects to merge. + * @param options Deep merge options. + */ +export function deepmergeAll< + Ts extends readonly [object, ...object[]], + O extends Options = {} +>(objects: [...Ts], options?: O): DeepMergeAll> + +/** + * Deeply merge two or more objects. + * + * @param objects An array of the objects to merge. + * @param options Deep merge options. + */ +export function deepmergeAll(objects: ReadonlyArray, options?: Options): object +export function deepmergeAll(objects: ReadonlyArray, options?: Options): object { + if (!Array.isArray(objects)) { + throw new Error(`first argument should be an array`) } - return array.reduce((prev, next) => - deepmergeImpl(prev, next, getFullOptions(options)), {} - ) + return objects.reduce((prev, next) => deepmergeImpl(prev, next, getFullOptions(options)), {}) } diff --git a/src/index.ts b/src/index.ts index 8146336..6f4835b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,2 @@ export { default, deepmergeAll } from "./deepmerge" +export type { Options } from "./options" diff --git a/src/options.ts b/src/options.ts index 7712c06..01c7022 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,31 +1,89 @@ import isPlainObj from "is-plain-obj" +import type { Property } from "./types" import { cloneUnlessOtherwiseSpecified } from "./utils" -function defaultIsMergeable(value) { +/** + * Deep merge options. + */ +export type Options = Partial<{ + arrayMerge?: ArrayMerge + clone?: boolean + customMerge?: ObjectMerge + isMergeable?: IsMergeable +}> + +/** + * Deep merge options with explicit keys. + */ +export type ExplicitOptions = { + [K in keyof Options]-?: undefined extends O[K] ? never : O[K] +} + +/** + * Deep merge options with defaults applied. + */ +export type FullOptions = { + arrayMerge: O["arrayMerge"] extends undefined + ? typeof defaultArrayMerge + : NonNullable + clone: O["clone"] extends undefined ? true : NonNullable + customMerge?: O["customMerge"] + isMergeable: O["isMergeable"] extends undefined + ? typeof defaultIsMergeable + : NonNullable + cloneUnlessOtherwiseSpecified: (value: T, options: FullOptions) => T +} + +/** + * A function that determins if a type is mergable. + */ +export type IsMergeable = (value: any) => boolean + +/** + * A function that merges any 2 arrays. + */ +export type ArrayMerge = (target: T1[], source: T2[], options: FullOptions) => any + +/** + * A function that merges any 2 non-arrays values. + */ +export type ObjectMerge = ( + key: K +) => ((target: any, source: any, options: FullOptions) => any) | undefined + +function defaultIsMergeable(value: unknown): value is Record | Array { return Array.isArray(value) || isPlainObj(value) } -function defaultArrayMerge(target, source, options) { +function defaultArrayMerge( + target: readonly T1[], + source: readonly T2[], + options: FullOptions +) { return [...target, ...source].map((element) => cloneUnlessOtherwiseSpecified(element, options) - ) + ) as T1 extends readonly [...infer E1] + ? T2 extends readonly [...infer E2] + ? [...E1, ...E2] + : never + : never } -export function getFullOptions(options) { +export function getFullOptions(options?: O) { const overrides = options === undefined ? undefined : (Object.fromEntries( // Filter out keys explicitly set to undefined. Object.entries(options).filter(([key, value]) => value !== undefined) - )) + ) as O) return { arrayMerge: defaultArrayMerge, isMergeable: defaultIsMergeable, clone: true, - ...overrides, - cloneUnlessOtherwiseSpecified - }; + ...overrides, + cloneUnlessOtherwiseSpecified, + } as FullOptions } diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..99f7e5a --- /dev/null +++ b/src/types.ts @@ -0,0 +1,182 @@ +import type { Options } from "./options" + +/** + * Deep merge 1 or more types given in an array. + */ +export type DeepMergeAll< + Ts extends readonly [any, ...any[]], + O extends Options +> = Ts extends readonly [infer T1, ...any[]] + ? Ts extends readonly [T1, infer T2, ...infer TRest] + ? TRest extends readonly never[] + ? DeepMerge + : DeepMerge, O> + : T1 + : never + +/** + * Deep merge 2 types. + */ +export type DeepMerge = IsSame extends true + ? T1 | T2 + : And, IsObjectOrArray> extends true + ? DeepMergeValues + : Leaf + +/** + * Deep merge 2 objects (they may be arrays). + */ +type DeepMergeValues = And, IsArray> extends true + ? DeepMergeArrays + : And, IsObject> extends true + ? DeepMergeObjects + : Leaf + +/** + * Deep merge 2 non-array objects. + */ +export type DeepMergeObjects = FlatternAlias< + // @see https://github.com/microsoft/TypeScript/issues/41448 + { + -readonly [K in keyof T1]: DeepMergeObjectProps, ValueOfKey, O> + } & + { + -readonly [K in keyof T2]: DeepMergeObjectProps, ValueOfKey, O> + } +> + +/** + * Deep merge 2 types that are known to be properties of an object being deeply + * merged. + */ +type DeepMergeObjectProps = Or< + IsUndefinedOrNever, + IsUndefinedOrNever +> extends true + ? Leaf + : IsUndefinedOrNever extends true + ? IsUndefinedOrNever extends true + ? DeepMerge + : DeepMergeObjectPropsCustom + : MaybeLeaf + +/** + * Deep merge 2 types that are known to be properties of an object being deeply + * merged and where a "customMerge" function has been provided. + */ +type DeepMergeObjectPropsCustom = ReturnType< + NonNullable +> extends undefined + ? DeepMerge + : undefined extends ReturnType> + ? Or, IsArray> extends true + ? And, IsArray> extends true + ? DeepMergeArrays + : Leaf + : DeepMerge | ReturnType>>> + : ReturnType>>> + +/** + * Deep merge 2 arrays. + * + * Cannot get return type from arrayMerge passing generics. + * TypeScript does not yet support higher order types. + * @see https://github.com/Microsoft/TypeScript/issues/1213 + */ +type DeepMergeArrays = IsUndefinedOrNever extends true + ? T1 extends readonly [...infer E1] + ? T2 extends readonly [...infer E2] + ? [...E1, ...E2] + : never + : never + : ReturnType> + +/** + * Get the leaf type from 2 types that can't be merged. + */ +type Leaf = IsNever extends true + ? T1 + : IsNever extends true + ? T2 + : IsUndefinedOrNever extends true + ? T1 + : T2 + +/** + * Get the leaf type from 2 types that might not be able to be merged. + */ +type MaybeLeaf = Or< + Or, IsUndefinedOrNever>, + Not, IsObjectOrArray>> +> extends true + ? Leaf + : // TODO: Handle case where return type of "isMergeable" is a typeguard. If it is we can do better than just "unknown". + unknown + +/** + * Flatten a complex type such as a union or intersection of objects into a + * single object. + */ +type FlatternAlias = {} & { [P in keyof T]: T[P] } + +/** + * Get the value of the given key in the given object. + */ +type ValueOfKey = K extends keyof T ? T[K] : never + +/** + * Safely test whether or not the first given types extends the second. + * + * Needed in particular for testing if a type is "never". + */ +type Is = [T1] extends [T2] ? true : false + +/** + * Safely test whether or not the given type is "never". + */ +type IsNever = Is + +/** + * Is the given type undefined or never? + */ +type IsUndefinedOrNever = Is + +/** + * Returns whether or not the give two types are the same. + */ +type IsSame = Is extends true ? Is : false + +/** + * Returns whether or not the given type an object (arrays are objects). + */ +type IsObjectOrArray = And>, T extends object ? true : false> + +/** + * Returns whether or not the given type a non-array object. + */ +type IsObject = And, Not>> + +/** + * Returns whether or not the given type an array. + */ +type IsArray = And>, T extends ReadonlyArray ? true : false> + +/** + * And operator for types. + */ +type And = T1 extends false ? false : T2 + +/** + * Or operator for types. + */ +type Or = T1 extends true ? true : T2 + +/** + * Not operator for types. + */ +type Not = T extends true ? false : true + +/** + * A property that can index an object. + */ +export type Property = string | number | symbol diff --git a/src/utils.ts b/src/utils.ts index a040967..f626e6f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,44 +1,52 @@ -import { deepmergeImpl } from './deepmerge'; +import { deepmergeImpl } from "./deepmerge" +import type { FullOptions, ObjectMerge } from "./options" +import type { Property } from "./types" -function emptyTarget(value) { +function emptyTarget(value: unknown) { return Array.isArray(value) ? [] : {} } -export function cloneUnlessOtherwiseSpecified(value, options) { - return (options.clone !== false && options.isMergeable(value)) - ? deepmergeImpl(emptyTarget(value), value, options) +export function cloneUnlessOtherwiseSpecified(value: T, options: FullOptions): T { + return options.clone !== false && options.isMergeable(value) + ? (deepmergeImpl(emptyTarget(value), value, options) as T) : value } -function getEnumerableOwnPropertySymbols(target) { +function getEnumerableOwnPropertySymbols(target: object) { return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol) - ) - : []; + ? Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol)) + : [] } -export function getKeys(target) { - return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)); +export function getKeys(target: object) { + // Symbols cannot be used to index objects yet. + // So cast to an array of strings for simplicity. + // @see https://github.com/microsoft/TypeScript/issues/1863 + // TODO: Remove cast once symbols indexing of objects is supported. + return [...Object.keys(target), ...getEnumerableOwnPropertySymbols(target)] as string[] } -export function propertyIsOnObject(object, property) { +export function propertyIsOnObject(object: object, property: Property) { try { - return property in object; + return property in object } catch (_) { - return false; + return false } } -export function getMergeFunction(key, options) { +export function getMergeFunction( + key: Property, + options: FullOptions +): NonNullable> { if (!options.customMerge) { return deepmergeImpl } const customMerge = options.customMerge(key) - return typeof customMerge === 'function' ? customMerge : deepmergeImpl + return typeof customMerge === "function" ? customMerge : deepmergeImpl } // Protects from prototype poisoning and unexpected merging up the prototype chain. -export function propertyIsUnsafe(target, key) { +export function propertyIsUnsafe(target: object, key: Property) { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. From 776fc228732dd69c362c08173129640145d104d4 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 18:53:33 +1300 Subject: [PATCH 21/36] test: tests types --- package-lock.json | 1579 ++++++++++++++++++++++++++++++++++++++ package.json | 3 +- test/types/index.d.ts | 1 + test/types/test.ts | 180 +++++ test/types/tsconfig.json | 11 + test/typescript.ts | 65 -- 6 files changed, 1773 insertions(+), 66 deletions(-) create mode 100644 test/types/index.d.ts create mode 100644 test/types/test.ts create mode 100644 test/types/tsconfig.json delete mode 100644 test/typescript.ts diff --git a/package-lock.json b/package-lock.json index 4065bef..d73f019 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,58 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@definitelytyped/header-parser": { + "version": "0.0.60", + "resolved": "https://registry.npmjs.org/@definitelytyped/header-parser/-/header-parser-0.0.60.tgz", + "integrity": "sha512-fdfR9DthV9WwUCeLsEIhAJxBjRccX0VnRJIDr9JWbqN3TloKEv/376Lq4/q2zJRUsbJTiKwDxhg6RFwqN34uuA==", + "dev": true, + "requires": { + "@definitelytyped/typescript-versions": "^0.0.60", + "@types/parsimmon": "^1.10.1", + "parsimmon": "^1.13.0" + } + }, + "@definitelytyped/typescript-versions": { + "version": "0.0.60", + "resolved": "https://registry.npmjs.org/@definitelytyped/typescript-versions/-/typescript-versions-0.0.60.tgz", + "integrity": "sha512-zu5qXL3lyhBnoi2pxT8MrG2MfNyY+NRII3JjwF8bedAsisNiGwXz5UN01NREhwAf010zfT3XEWORhTBsIzOXkQ==", + "dev": true + }, + "@definitelytyped/utils": { + "version": "0.0.60", + "resolved": "https://registry.npmjs.org/@definitelytyped/utils/-/utils-0.0.60.tgz", + "integrity": "sha512-USQJzzb3PIJbc/CObC6vEIn2Oum8DaOoXP+qhHoeBEyAwY1YQ6tbX+fBc6k8DHuMY9obdpx/7OUnGE0c8EohHw==", + "dev": true, + "requires": { + "@definitelytyped/typescript-versions": "^0.0.60", + "@types/node": "^12.12.29", + "charm": "^1.0.2", + "fs-extra": "^8.1.0", + "fstream": "^1.0.12", + "npm-registry-client": "^8.6.0", + "tar": "^2.2.2", + "tar-stream": "^2.1.4" + }, + "dependencies": { + "@types/node": { + "version": "12.19.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.4.tgz", + "integrity": "sha512-o3oj1bETk8kBwzz1WlO6JWL/AfAA3Vm6J1B3C9CsdxHYp7XgPiH7OEXPUbZTndHlRaIElrANkQfe6ZmfJb3H2w==", + "dev": true + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "@rollup/plugin-commonjs": { "version": "16.0.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-16.0.0.tgz", @@ -145,12 +197,93 @@ "integrity": "sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg==", "dev": true }, + "@types/parsimmon": { + "version": "1.10.4", + "resolved": "https://registry.npmjs.org/@types/parsimmon/-/parsimmon-1.10.4.tgz", + "integrity": "sha512-M56NfQHfaWuaj6daSgCVs7jh8fXLI3LmxjRoQxmOvYesgIkI+9HPsDLO0vd7wX7cwA0D0ZWFEJdp0VPwLdS+bQ==", + "dev": true + }, + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "aproba": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "dev": true, + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", + "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "dev": true, + "optional": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, "array-filter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-1.0.0.tgz", "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=", "dev": true }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "dev": true, + "requires": { + "safer-buffer": "~2.1.0" + } + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "dev": true + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, "available-typed-arrays": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz", @@ -160,12 +293,104 @@ "array-filter": "^1.0.0" } }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", + "dev": true + }, + "aws4": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", + "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", + "dev": true + }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "dev": true, + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + } + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true + }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "dev": true, + "requires": { + "tweetnacl": "^0.14.3" + } + }, + "bl": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", + "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "dev": true, + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, + "block-stream": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz", + "integrity": "sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo=", + "dev": true, + "requires": { + "inherits": "~2.0.0" + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -176,6 +401,16 @@ "concat-map": "0.0.1" } }, + "buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", @@ -188,6 +423,12 @@ "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", "dev": true }, + "builtins": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz", + "integrity": "sha1-y5T662HIaWRR2zZTThQi+U8K7og=", + "dev": true + }, "call-bind": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz", @@ -198,6 +439,155 @@ "get-intrinsic": "^1.0.0" } }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "dev": true + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", + "dev": true + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "charm": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/charm/-/charm-1.0.2.tgz", + "integrity": "sha1-it02cVOm2aWBMxBSxAkJkdqZXjU=", + "dev": true, + "requires": { + "inherits": "^2.0.1" + } + }, + "cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dev": true, + "requires": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + } + } + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "dev": true, + "optional": true + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", + "dev": true + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -216,6 +606,46 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "dev": true, + "optional": true + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, "deep-equal": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.0.4.tgz", @@ -265,6 +695,25 @@ "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "dev": true, + "optional": true + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, "dotignore": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz", @@ -274,6 +723,79 @@ "minimatch": "^3.0.4" } }, + "dts-critic": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/dts-critic/-/dts-critic-3.3.3.tgz", + "integrity": "sha512-Pd27sNICo8mUqZ7XBdefy/+eWG8uG02GaYgOv5DBpxiF+8hduojztVm4935dqocyDv/STdF1uh6a8WnAhBK7tQ==", + "dev": true, + "requires": { + "@definitelytyped/header-parser": "^0.0.60", + "command-exists": "^1.2.8", + "rimraf": "^3.0.2", + "semver": "^6.2.0", + "tmp": "^0.2.1", + "yargs": "^15.3.1" + }, + "dependencies": { + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, + "dtslint": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/dtslint/-/dtslint-4.0.5.tgz", + "integrity": "sha512-gEf7tEQgdMQh38h29B2aVyJBGMb8l/5koVArmc4t3XyeCe0rbElpB0HjOZ6SgUOzvsI05hTOenY66aM9ji3afA==", + "dev": true, + "requires": { + "@definitelytyped/header-parser": "^0.0.60", + "@definitelytyped/typescript-versions": "^0.0.60", + "@definitelytyped/utils": "^0.0.60", + "dts-critic": "^3.3.3", + "fs-extra": "^6.0.1", + "json-stable-stringify": "^1.0.1", + "strip-json-comments": "^2.0.1", + "tslint": "5.14.0", + "yargs": "^15.1.0" + } + }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "dev": true, + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "dev": true, + "requires": { + "once": "^1.4.0" + } + }, "es-abstract": { "version": "1.18.0-next.1", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", @@ -321,6 +843,12 @@ "is-symbol": "^1.0.2" } }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, "escodegen": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.12.0.tgz", @@ -360,12 +888,46 @@ "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", + "dev": true + }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "requires": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + } + }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -381,6 +943,40 @@ "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", "dev": true }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", + "dev": true + }, + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "dev": true + }, + "fs-extra": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-6.0.1.tgz", + "integrity": "sha512-GnyIkKhhzXZUWFCaJzvyDLEEgDkPfb4/TPvJCJVuS8MWZgoSsErf++QpiAlDnKFcqhRlm+tIOcencCjyJE6ZCA==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -394,12 +990,58 @@ "dev": true, "optional": true }, + "fstream": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", + "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "inherits": "~2.0.0", + "mkdirp": ">=0.5 0", + "rimraf": "2" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } + } + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "dev": true, + "optional": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true + }, "get-intrinsic": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.0.1.tgz", @@ -411,6 +1053,15 @@ "has-symbols": "^1.0.1" } }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0" + } + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -425,6 +1076,28 @@ "path-is-absolute": "^1.0.0" } }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", + "dev": true + }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", + "dev": true + }, + "har-validator": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", + "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", + "dev": true, + "requires": { + "ajv": "^6.12.3", + "har-schema": "^2.0.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -434,12 +1107,57 @@ "function-bind": "^1.1.1" } }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, "has-symbols": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", "dev": true }, + "has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "dev": true, + "optional": true + }, + "hosted-git-info": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", + "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "dev": true + }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" + } + }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -495,6 +1213,16 @@ "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", "dev": true }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "dev": true, + "optional": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, "is-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.1.tgz", @@ -594,6 +1322,12 @@ } } }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", + "dev": true + }, "is-weakmap": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.1.tgz", @@ -612,6 +1346,42 @@ "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", "dev": true }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", + "dev": true + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "js-yaml": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", + "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "dependencies": { + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + } + } + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "dev": true + }, "jsmd": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/jsmd/-/jsmd-1.0.2.tgz", @@ -625,6 +1395,60 @@ "v8-argv": "github:jkroso/v8-argv#1.1.1" } }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", + "dev": true + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", + "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=", + "dev": true, + "requires": { + "jsonify": "~0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", + "dev": true + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "jsonify": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", + "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", + "dev": true + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "dev": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -635,12 +1459,36 @@ "type-check": "~0.3.2" } }, + "locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "requires": { + "p-locate": "^4.1.0" + } + }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==", "dev": true }, + "mime-db": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==", + "dev": true + }, + "mime-types": { + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", + "dev": true, + "requires": { + "mime-db": "1.44.0" + } + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -650,6 +1498,98 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "dev": true + }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, + "requires": { + "minimist": "^1.2.5" + } + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "npm-package-arg": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-6.1.1.tgz", + "integrity": "sha512-qBpssaL3IOZWi5vEKUKW0cO7kzLeT+EQO9W8RsLOZf76KF9E/K9+wH0C7t06HXPpaH8WH5xF1MExLuCwbTqRUg==", + "dev": true, + "requires": { + "hosted-git-info": "^2.7.1", + "osenv": "^0.1.5", + "semver": "^5.6.0", + "validate-npm-package-name": "^3.0.0" + } + }, + "npm-registry-client": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/npm-registry-client/-/npm-registry-client-8.6.0.tgz", + "integrity": "sha512-Qs6P6nnopig+Y8gbzpeN/dkt+n7IyVd8f45NTMotGk6Qo7GfBmzwYx6jRLoOOgKiMnaQfYxsuyQlD8Mc3guBhg==", + "dev": true, + "requires": { + "concat-stream": "^1.5.2", + "graceful-fs": "^4.1.6", + "normalize-package-data": "~1.0.1 || ^2.0.0", + "npm-package-arg": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0", + "npmlog": "2 || ^3.1.0 || ^4.0.0", + "once": "^1.3.3", + "request": "^2.74.0", + "retry": "^0.10.0", + "safe-buffer": "^5.1.1", + "semver": "2 >=2.2.1 || 3.x || 4 || 5", + "slide": "^1.1.3", + "ssri": "^5.2.4" + } + }, + "npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "optional": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true, + "optional": true + }, + "oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", + "dev": true + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true, + "optional": true + }, "object-inspect": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", @@ -707,6 +1647,64 @@ "wordwrap": "~1.0.0" } }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "dev": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, + "p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "requires": { + "p-limit": "^2.2.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true + }, + "parsimmon": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.16.0.tgz", + "integrity": "sha512-tekGDz2Lny27SQ/5DzJdIK0lqsWwZ667SCLFIDCxaZM7VNgQjyKLbaL7FYPKpbjdxNAXFV/mSxkq5D2fnkW4pA==", + "dev": true + }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -719,6 +1717,12 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", + "dev": true + }, "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", @@ -731,6 +1735,59 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true + }, + "psl": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", + "dev": true + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", + "dev": true + }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + }, + "dependencies": { + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, "regexp.prototype.flags": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz", @@ -762,6 +1819,46 @@ } } }, + "request": { + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", + "dev": true, + "requires": { + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.3", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.5.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "dev": true + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", + "dev": true + }, "resolve": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz", @@ -781,6 +1878,21 @@ "through": "~2.3.4" } }, + "retry": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.10.1.tgz", + "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "rollup": { "version": "2.33.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.33.1.tgz", @@ -790,6 +1902,30 @@ "fsevents": "~2.1.2" } }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "dev": true + }, "side-channel": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.3.tgz", @@ -800,6 +1936,19 @@ "object-inspect": "^1.8.0" } }, + "signal-exit": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", + "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", + "dev": true, + "optional": true + }, + "slide": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", + "integrity": "sha1-VusCfWW00tzmyy4tMsTUr8nh1wc=", + "dev": true + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -813,6 +1962,82 @@ "integrity": "sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg==", "dev": true }, + "spdx-correct": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", + "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==", + "dev": true, + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.6.tgz", + "integrity": "sha512-+orQK83kyMva3WyPf59k1+Y525csj5JejicWut55zeTWANuN17qSiSLUXWtzHeNWORSvT7GLDJ/E/XiIWoXBTw==", + "dev": true + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "dev": true, + "requires": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + } + }, + "ssri": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-5.3.0.tgz", + "integrity": "sha512-XRSIPqLij52MtgoQavH/x/dU1qVKtWUAAZeOHsR9c2Ddi4XerFy3mc1alf+dLJKl9EUIm/Ht+EowFkTUOA6GAQ==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.1" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "dev": true, + "optional": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, "string.prototype.trim": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.2.tgz", @@ -843,6 +2068,44 @@ "es-abstract": "^1.18.0-next.1" } }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true + } + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, "tape": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/tape/-/tape-5.0.1.tgz", @@ -876,6 +2139,43 @@ } } }, + "tar": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.2.tgz", + "integrity": "sha512-FCEhQ/4rE1zYv9rYXJw/msRqsnmlje5jHP6huWeBZ704jUTy02c5AZyWujpMR1ax6mVw9NyJMfuK2CMDWVIfgA==", + "dev": true, + "requires": { + "block-stream": "*", + "fstream": "^1.0.12", + "inherits": "2" + } + }, + "tar-stream": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.4.tgz", + "integrity": "sha512-o3pS2zlG4gxr67GmFYBLlq+dM8gyRGUOvsrHclSkvtVtQbjV0s/+ZE8OpICbaj8clrX3tjeHngYGP7rweaBnuw==", + "dev": true, + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "terser": { "version": "5.3.8", "resolved": "https://registry.npmjs.org/terser/-/terser-5.3.8.tgz", @@ -919,12 +2219,98 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "requires": { + "rimraf": "^3.0.0" + } + }, + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "dev": true, + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + }, "tslib": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz", "integrity": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==", "dev": true }, + "tslint": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.14.0.tgz", + "integrity": "sha512-IUla/ieHVnB8Le7LdQFRGlVJid2T/gaJe5VkjzRVSRR6pA2ODYrnfR1hmxi+5+au9l50jBwpbBL34txgv4NnTQ==", + "dev": true, + "requires": { + "babel-code-frame": "^6.22.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^3.2.0", + "glob": "^7.1.1", + "js-yaml": "^3.7.0", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.29.0" + }, + "dependencies": { + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + } + } + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + } + } + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "dev": true, + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "dev": true + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", @@ -934,17 +2320,80 @@ "prelude-ls": "~1.1.2" } }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, "typescript": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", "dev": true }, + "universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true + }, + "uri-js": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz", + "integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "dev": true + }, "v8-argv": { "version": "github:jkroso/v8-argv#284f84379e292eb956a5e7b66fb953ec4974385e", "from": "github:jkroso/v8-argv#1.1.1", "dev": true }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "validate-npm-package-name": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz", + "integrity": "sha1-X6kS2B630MdK/BQN5zF/DKffQ34=", + "dev": true, + "requires": { + "builtins": "^1.0.3" + } + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "dev": true, + "requires": { + "assert-plus": "^1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "^1.2.0" + } + }, "which-boxed-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz", @@ -970,6 +2419,12 @@ "is-weakset": "^2.0.1" } }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "dev": true + }, "which-typed-array": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.2.tgz", @@ -1005,17 +2460,141 @@ } } }, + "wide-align": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", + "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "dev": true, + "optional": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", "dev": true }, + "wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "dev": true, + "requires": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + } + } + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "dev": true + }, + "yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dev": true, + "requires": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true + }, + "string-width": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", + "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", + "dev": true, + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.0" + } + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + } + } + }, + "yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dev": true, + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } } diff --git a/package.json b/package.json index bc0094c..c0e05af 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build": "rollup -c && npm run typedef", "size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", "test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript", - "test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts", + "test:typescript": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types", "typedef": "tsc -p tsconfig.typedef.json" }, "dependencies": {}, @@ -38,6 +38,7 @@ "@rollup/plugin-node-resolve": "^10.0.0", "@rollup/plugin-typescript": "^6.1.0", "@types/node": "^8.10.54", + "dtslint": "^4.0.5", "is-mergeable-object": "1.1.0", "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", diff --git a/test/types/index.d.ts b/test/types/index.d.ts new file mode 100644 index 0000000..e560b87 --- /dev/null +++ b/test/types/index.d.ts @@ -0,0 +1 @@ +// Minimum TypeScript Version: 4.1 diff --git a/test/types/test.ts b/test/types/test.ts new file mode 100644 index 0000000..c9b5940 --- /dev/null +++ b/test/types/test.ts @@ -0,0 +1,180 @@ +import deepmerge, { deepmergeAll } from "../../src" + +const a = { + foo: "abc", + baz: { + quuz: ["def", "ghi"], + }, + garply: 42, +}; + +const b = { + foo: "cba", + baz: { + corge: 96, + }, + grault: 42, +}; + +// $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: number; grault: number; } +deepmerge(a, b); +// $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: number; grault: number; } +deepmergeAll([a, b]); + +type T = { + readonly foo: string; + bar?: string; +} + +// TODO: Should the result really be `T`? or should it be `DeepMutable`? +// $ExpectType T +deepmerge(a as T, b as T); +// $ExpectType T +deepmergeAll([a as T, b as T]); + +type U = { + bar?: string; +} + +// $ExpectType { foo: string; bar?: string | undefined; } +deepmerge(a as T, b as U); +// $ExpectType { foo: string; bar?: string | undefined; } +deepmergeAll([a as T, b as U]); + +const c = { + bar: "123", + quux: "456", + garply: 42, +} as const; + +// $ExpectType { foo: string; baz: { quuz: string[]; }; garply: 42; bar: "123"; quux: "456"; } +deepmerge(a, c); +// $ExpectType { foo: string; baz: { quuz: string[]; }; garply: 42; bar: "123"; quux: "456"; } +deepmergeAll([a, c]); + +// $ExpectType { foo: string; baz: { corge: number; }; grault: number; bar: "123"; quux: "456"; garply: 42; } +deepmerge(b, c); +// $ExpectType { foo: string; baz: { corge: number; }; grault: number; bar: "123"; quux: "456"; garply: 42; } +deepmergeAll([b, c]); + +// $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: 42; grault: number; bar: "123"; quux: "456"; } +deepmergeAll([a, b, c]); + +// Allow abatort arrays of objects to be passes even if we can't determine anything about the result. +const abc = [a, b, c]; +// $ExpectType object +deepmergeAll(abc); + +const d = { + bar: "abc", + quux: "def", + garply: 5, +} as const; + +// $ExpectType { bar: "abc"; quux: "def"; garply: 5; } +deepmerge(c, d); +// $ExpectType { bar: "abc"; quux: "def"; garply: 5; } +deepmergeAll([c, d]); + +type E = { readonly foo: readonly number[] }; +type F = { readonly foo: readonly string[] }; + +const e = { + foo: [1, 2, 3], +} as const; + +const f = { + foo: ["a", "b", "c"], +} as const; + +// $ExpectType { foo: [1, 2, 3, "a", "b", "c"]; } +deepmerge(e, f); +// $ExpectType { foo: [1, 2, 3, "a", "b", "c"]; } +deepmergeAll([e, f]); + +// $ExpectType { foo: (string | number)[]; } +deepmerge(e as E, f as F); +// $ExpectType { foo: (string | number)[]; } +deepmergeAll([e as E, f as F]); + +const g = { + key1: "key1-val", + key2: { + key2key1: [false, "true"], + }, + key3: { + key3key1: { + key3key1key1: "key3key1key1-val", + key3key1key2: true, + key3key1key3: ["key3key1key3-val"], + }, + key3key2: ["key3key2-val"], + }, +}; + +const h = { + key1: ["key1-val"], + key2: { + key2key1: { + key2key1key1: () => "key2key1key1-val", + key2key1key2: true, + key2key1key3: ["key2key1key3-val"], + }, + }, + key3: { + key3key1: () => false, + key3key2: ["key3key2-val", true], + }, +}; + +// $ExpectType { key1: string[]; key2: { key2key1: { key2key1key1: () => string; key2key1key2: boolean; key2key1key3: string[]; }; }; key3: { key3key1: { key3key1key1: string; key3key1key2: boolean; key3key1key3: string[]; }; key3key2: (string | boolean)[]; }; } +deepmerge(g, h); +// $ExpectType { key1: string[]; key2: { key2key1: { key2key1key1: () => string; key2key1key2: boolean; key2key1key3: string[]; }; }; key3: { key3key1: { key3key1key1: string; key3key1key2: boolean; key3key1key3: string[]; }; key3key2: (string | boolean)[]; }; } +deepmergeAll([g, h]); + +// $ExpectType { foo: string; baz: unknown; garply: number; grault: number; } +deepmerge(a, b, { + isMergeable: (obj: object) => { + return false; + }, +}); +// $ExpectType { foo: string; baz: unknown; garply: number; grault: number; } +deepmergeAll([a, b], { + isMergeable: (obj: object) => { + return false; + }, +}); + +const i = { + baz: { + quuz: [5, 6], + }, +}; + +// $ExpectType { foo: string; baz: { quuz: number; }; garply: number; } +deepmerge(a, i, { + arrayMerge: (target: unknown[], source: unknown[]) => + target.length + source.length, +}); +// $ExpectType { foo: string; baz: { quuz: number; }; garply: number; } +deepmergeAll([a, i], { + arrayMerge: (target: unknown[], source: unknown[]) => + target.length + source.length, +}); + +// $ExpectType { foo: string; baz: string | { quuz: (string | number)[]; }; garply: number; } +deepmerge(a, i, { + customMerge: (key: string) => { + if (key === "bar") { + return (target: string, source: string) => target + source; + } + }, +}); +// $ExpectType { foo: string; baz: string | { quuz: (string | number)[]; }; garply: number; } +deepmergeAll([a, i], { + customMerge: (key: string) => { + if (key === "bar") { + return (target: string, source: string) => target + source; + } + }, +}); diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json new file mode 100644 index 0000000..5e26ea2 --- /dev/null +++ b/test/types/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "lib": [ + "ES2020" + ], + "strict": true, + "noEmit": true + } +} diff --git a/test/typescript.ts b/test/typescript.ts deleted file mode 100644 index e474cd8..0000000 --- a/test/typescript.ts +++ /dev/null @@ -1,65 +0,0 @@ -import merge, { deepmergeAll, Options } from '../'; - -const x = { - foo: 'abc', - bar: 'def', - wat: 42, -} - -const y = { - foo: 'cba', - bar: 'fed', - wat: 42, -} - -const z = { - baz: '123', - quux: '456', - wat: 42, -} - -let merged1 = merge(x, y); -let merged2 = merge(x, z); -let merged3 = deepmergeAll([ x, y, z ]); - -merged1.foo; -merged1.bar; -merged2.foo; -merged2.baz; -merged3.wat; - - -const options1: Options = { - clone: true, - isMergeable (obj) { - return false; - }, -}; - -const options2: Options = { - arrayMerge (target, source, options) { - target.length; - source.length; - options.isMergeable(target); - - return []; - }, - clone: true, - isMergeable (obj) { - return false; - }, -}; - -const options3: Options = { - customMerge: (key) => { - if (key === 'foo') { - return (target, source) => target + source; - } - } -} - -merged1 = merge(x, y, options1); -merged2 = merge(x, z, options2); -merged3 = deepmergeAll([x, y, z], options1); - -const merged4 = merge(x, y, options3); From a2af763371d1dcb05626b821acd38a920ba921da Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 13 Nov 2020 18:56:11 +1300 Subject: [PATCH 22/36] chore: refactor npm script commands --- package.json | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c0e05af..ac867fa 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,22 @@ "readme.md" ], "scripts": { - "build": "rollup -c && npm run typedef", - "size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", - "test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript", - "test:typescript": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types", - "typedef": "tsc -p tsconfig.typedef.json" + "build": "npm run build:js && npm run build:types", + "prebuild:js": "npm run clean:dist", + "build:js": "rollup -c", + "prebuild:types": "npm run clean:types", + "build:types": "tsc -p tsconfig.typedef.json", + "clean": "npm run clean:dist && npm run clean:types", + "clean:dist": "rimraf dist", + "clean:types": "rimraf 'types/[!legacy/]*'", + "presize": "npm run build:js", + "size": "terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", + "test": "npm run test:js && npm run test:types && npm run test:jsmd", + "pretest:js": "npm run build:js", + "test:js": "tape test/*.js", + "test:jsmd": "jsmd readme.md", + "pretest:types": "npm run build:types", + "test:types": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types" }, "dependencies": {}, "devDependencies": { @@ -42,6 +53,7 @@ "is-mergeable-object": "1.1.0", "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", + "rimraf": "^3.0.2", "rollup": "^2.33.1", "tape": "^5.0.1", "terser": "^5.3.8", From 0a2be407965326e393dc1c54ca5706836661931b Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Nov 2020 12:12:54 +1300 Subject: [PATCH 23/36] build: update package exports --- package.json | 12 ++++++++++-- rollup.config.js | 21 ++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index ac867fa..73cb1fa 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,15 @@ "url": "git://github.com/TehShrike/deepmerge.git" }, "license": "MIT", - "main": "dist/cjs.js", + "exports": { + "default": "./dist/index.umd.js", + "import": "./dist/index.mjs", + "node": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" + } + }, + "main": "./dist/index.cjs", "types": "types/index.d.ts", "files": [ "dist", @@ -35,7 +43,7 @@ "clean:dist": "rimraf dist", "clean:types": "rimraf 'types/[!legacy/]*'", "presize": "npm run build:js", - "size": "terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", + "size": "terser --compress --mangle -- ./dist/index.umd.js | gzip -c | wc -c", "test": "npm run test:js && npm run test:types && npm run test:jsmd", "pretest:js": "npm run build:js", "test:js": "tape test/*.js", diff --git a/rollup.config.js b/rollup.config.js index ec2c616..c0650ab 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,26 +1,33 @@ // @ts-check -import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' -import typescript from '@rollup/plugin-typescript'; +import resolve from '@rollup/plugin-node-resolve' +import typescript from '@rollup/plugin-typescript' + import pkg from './package.json' export default { input: `src/index.ts`, + plugins: [ resolve(), commonjs(), typescript() ], + output: [ { - file: pkg.main, - format: `cjs` + file: pkg.exports.import, + format: `esm`, + }, + { + file: pkg.exports.node.require, + format: `cjs`, }, { - name: 'deepmerge', - file: 'dist/umd.js', - format: `umd` + name: pkg.name, + file: pkg.exports.default, + format: `umd`, }, ], } From 2246372bd9704cf5bdcbfebd34cce53a00fa45f1 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 16 Nov 2020 10:34:52 +1300 Subject: [PATCH 24/36] build: add type support for older TypeScript versions --- .gitignore | 1 + package.json | 15 ++++++++++++++- types/legacy/index.d.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 types/legacy/index.d.ts diff --git a/.gitignore b/.gitignore index 73a7d5e..fae2fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist/* types/* +!types/legacy* diff --git a/package.json b/package.json index 73cb1fa..05a21f1 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,19 @@ } }, "main": "./dist/index.cjs", - "types": "types/index.d.ts", + "types": "types/legacy/index.d.ts", + "typesVersions": { + "<4.1": { + "*": [ + "types/legacy/*" + ] + }, + ">=4.1": { + "*": [ + "types/*" + ] + } + }, "files": [ "dist", "types", @@ -39,6 +51,7 @@ "build:js": "rollup -c", "prebuild:types": "npm run clean:types", "build:types": "tsc -p tsconfig.typedef.json", + "postbuild:types": "echo \"// Minimum TypeScript Version: 4.1\n\n$(cat types/index.d.ts)\" > types/index.d.ts", "clean": "npm run clean:dist && npm run clean:types", "clean:dist": "rimraf dist", "clean:types": "rimraf 'types/[!legacy/]*'", diff --git a/types/legacy/index.d.ts b/types/legacy/index.d.ts new file mode 100644 index 0000000..ff85d32 --- /dev/null +++ b/types/legacy/index.d.ts @@ -0,0 +1,30 @@ +/** + * Deeply merge two objects. + * + * @param target The first object. + * @param source The second object. + * @param options Deep merge options. + */ +export default function deepmerge(target: T1, source: T2, options?: Options): T1 & T2; + +/** + * Deeply merge two or more objects. + * + * @param objects An tuple of the objects to merge. + * @param options Deep merge options. + */ +export function deepmergeAll(objects: [T1, T2], options?: Options): T1 & T2; +export function deepmergeAll(objects: [T1, T2, T3], options?: Options): T1 & T2 & T3; +export function deepmergeAll(objects: [T1, T2, T3, T4], options?: Options): T1 & T2 & T3 & T4; +export function deepmergeAll(objects: [T1, T2, T3, T4, T5], options?: Options): T1 & T2 & T3 & T4 & T5; +export function deepmergeAll(objects: ReadonlyArray, options?: Options): T; + +/** + * Deep merge options. + */ +export type Options = { + arrayMerge?: (target: object[], source: object[], options: Options) => any; + clone?: boolean; + customMerge?: (key: string) => ((target: object, source: object, options: Options) => any) | undefined; + isMergeable?: (value: object) => boolean; +} From 8c562f54047014fc8299b4b275e840d823ffe0e8 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 17 Nov 2020 12:50:50 +1300 Subject: [PATCH 25/36] build(lint): add eslint --- .eslintrc.json | 202 ++++++++++ package-lock.json | 959 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 + 3 files changed, 1166 insertions(+) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..77effbc --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,202 @@ +{ + "root": true, + "parserOptions": { + "ecmaVersion": 10, + "ecmaFeatures": { + "impliedStrict": true + }, + "sourceType": "module" + }, + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended" + ], + "ignorePatterns": ["dist", "types"], + "rules": { + "no-extra-boolean-cast": "error", + "array-bracket-spacing": [ + "error", + "always", + { + "objectsInArrays": false + } + ], + "block-spacing": ["error", "always"], + "brace-style": "error", + "comma-dangle": ["error", "always-multiline"], + "comma-spacing": [ + "error", + { + "before": false, + "after": true + } + ], + "comma-style": "error", + "curly": "error", + "computed-property-spacing": ["error", "never"], + "func-call-spacing": ["error", "never"], + "indent": ["error", "tab"], + "key-spacing": "error", + "keyword-spacing": "error", + "no-whitespace-before-property": "error", + "no-trailing-spaces": "error", + "object-curly-spacing": ["error", "always"], + "padded-blocks": ["error", "never"], + "semi": ["error", "never"], + "space-before-function-paren": ["error", "never"], + "space-in-parens": ["error", "never"], + "space-infix-ops": "error", + "space-unary-ops": [ + "error", + { + "words": true, + "nonwords": false + } + ], + "no-regex-spaces": "error", + "no-unsafe-negation": "error", + "dot-location": ["error", "property"], + "dot-notation": "error", + "no-extra-label": "error", + "no-multi-spaces": [ + "error", + { + "exceptions": { + "Property": false + } + } + ], + "no-useless-return": "error", + "eol-last": ["error", "always"], + "linebreak-style": "error", + "no-lonely-if": "error", + "no-unneeded-ternary": "error", + "object-curly-newline": [ + "error", + { + "consistent": true + } + ], + "operator-linebreak": ["error", "before"], + "quote-props": ["error", "as-needed"], + "quotes": ["error", "backtick"], + "space-before-blocks": ["error", "always"], + "spaced-comment": ["error", "always"], + "template-tag-spacing": "error", + "unicode-bom": "error", + "arrow-body-style": ["error", "as-needed"], + "arrow-parens": ["error", "always"], + "arrow-spacing": "error", + "generator-star-spacing": "error", + "no-useless-computed-key": "error", + "no-useless-rename": "error", + "no-var": "error", + "object-shorthand": "error", + "prefer-arrow-callback": [ + "error", + { + "allowNamedFunctions": true + } + ], + "prefer-const": "error", + "prefer-numeric-literals": "error", + "prefer-spread": "error", + "rest-spread-spacing": "error", + "template-curly-spacing": ["error", "always"], + + "no-bitwise": "error", + "no-console": "off", + "no-debugger": "off", + "no-empty": "error", + "no-inner-declarations": "off", + "no-undef": "error", + "no-unused-vars": "warn" + }, + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": [ + "./tsconfig.json", + "./test/types/tsconfig.json" + ] + }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "types": { + "Object": { + "message": "Use object instead", + "fixWith": "object" + }, + "object": false + }, + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-imports": "error", + "@typescript-eslint/prefer-interface": "off", + "@typescript-eslint/no-require-imports": "error", + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-unused-vars-experimental": [ + "warn", + { + "ignoredNamesRegex": "^_", + "ignoreArgsIfArgsAfterAreUsed": true + } + ], + "@typescript-eslint/no-use-before-define": [ + "error", + { + "functions": false, + "variables": true + } + ], + + "@typescript-eslint/prefer-for-of": "warn", + "@typescript-eslint/prefer-includes": "warn", + "@typescript-eslint/prefer-nullish-coalescing": "warn", + "@typescript-eslint/prefer-optional-chain": "warn", + "@typescript-eslint/prefer-string-starts-ends-with": "warn", + "@typescript-eslint/prefer-ts-expect-error": "warn", + "@typescript-eslint/switch-exhaustiveness-check": "warn", + "@typescript-eslint/unified-signatures": "warn", + + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-unsafe-return": "off" + } + }, + { + "files": [ + "**/test/**/*", + "**/*test.ts" + ], + "rules": { + "no-unused-vars": "off" + } + } + ] +} diff --git a/package-lock.json b/package-lock.json index d73f019..114b1db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,40 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", + "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", + "dev": true, + "requires": { + "@babel/highlight": "^7.10.4" + } + }, + "@babel/helper-validator-identifier": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", + "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", + "dev": true + }, + "@babel/highlight": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", + "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", + "dev": true, + "requires": { + "@babel/helper-validator-identifier": "^7.10.4", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + }, + "dependencies": { + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + } + } + }, "@definitelytyped/header-parser": { "version": "0.0.60", "resolved": "https://registry.npmjs.org/@definitelytyped/header-parser/-/header-parser-0.0.60.tgz", @@ -56,6 +90,58 @@ } } }, + "@eslint/eslintrc": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.1.tgz", + "integrity": "sha512-XRUeBZ5zBWLYgSANMpThFddrZZkEbGHgUdt5UJjZfnlN9BGCiUBrf+nvbRupSjMvqzwnQN0qwCmOxITt1cfywA==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.1.1", + "espree": "^7.3.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.2.1", + "js-yaml": "^3.13.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + } + } + }, + "@nodelib/fs.scandir": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz", + "integrity": "sha512-eGmwYQn3gxo4r7jdQnkrrN6bY478C3P+a/y72IJukF8LjB6ZHeB3c+Ehacj3sYeSmUXGlnA67/PmbM9CVwL7Dw==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.3", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", + "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.4.tgz", + "integrity": "sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.3", + "fastq": "^1.6.0" + } + }, "@rollup/plugin-commonjs": { "version": "16.0.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-16.0.0.tgz", @@ -191,6 +277,12 @@ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, + "@types/json-schema": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz", + "integrity": "sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==", + "dev": true + }, "@types/node": { "version": "8.10.54", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz", @@ -203,6 +295,147 @@ "integrity": "sha512-M56NfQHfaWuaj6daSgCVs7jh8fXLI3LmxjRoQxmOvYesgIkI+9HPsDLO0vd7wX7cwA0D0ZWFEJdp0VPwLdS+bQ==", "dev": true }, + "@typescript-eslint/eslint-plugin": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.8.0.tgz", + "integrity": "sha512-nm80Yy5D7Ot00bomzBYodnGmGhNdePHS3iaxJ3Th0wxRWEI/6KCgbmL8PR78fF7MtT1VDcYNtY5y+YYyGlRhBg==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "4.8.0", + "@typescript-eslint/scope-manager": "4.8.0", + "debug": "^4.1.1", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^3.0.0", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.8.0.tgz", + "integrity": "sha512-1yOvI++HMdA9lpaAkXXQlVUwJjruNz7Z9K3lgpcU+JU/Szvsv42H6G6DECalAuz2Dd0KFU/MeUrPC0jXnuAvlA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/scope-manager": "4.8.0", + "@typescript-eslint/types": "4.8.0", + "@typescript-eslint/typescript-estree": "4.8.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/parser": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.8.0.tgz", + "integrity": "sha512-15sp9BIoZalx4wRgkebfau8KizVe6w0eTjPMnuST9kbIeOaloDy1xKkg7eJfFvE/MdCtKlEWZFLoJB8C0SEOaw==", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "4.8.0", + "@typescript-eslint/types": "4.8.0", + "@typescript-eslint/typescript-estree": "4.8.0", + "debug": "^4.1.1" + } + }, + "@typescript-eslint/scope-manager": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.8.0.tgz", + "integrity": "sha512-eJ+SV6w5WcyFusQ/Ru4A/c7E65HMGzWWGPJAqSuM/1EKEE6wOw9LUQTqAvLa6v2oIcaDo9F+/EyOPZgoD/BcLA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.8.0", + "@typescript-eslint/visitor-keys": "4.8.0" + } + }, + "@typescript-eslint/types": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.8.0.tgz", + "integrity": "sha512-2/mGmXxr3sTxCvCT1mhR2b9rbfpMEBK41tiu0lMnMtZEbpphcUyrmgt2ogDFWNvsvyyeUxO1159eDrgFb7zV4Q==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.0.tgz", + "integrity": "sha512-jEdeERN8DIs7S8PlTdI7Sdy63Caxg2VtR21/RV7Z1Dtixiq/QEFSPrDXggMXKNOPPlrtMS+eCz7d7NV0HWLFVg==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.8.0", + "@typescript-eslint/visitor-keys": "4.8.0", + "debug": "^4.1.1", + "globby": "^11.0.1", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + } + } + }, + "@typescript-eslint/visitor-keys": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.0.tgz", + "integrity": "sha512-JluNZLvnkRUr0h3L6MnQVLuy2rw9DpD0OyMC21FVbgcezr0LQkbBjDp9kyKZhuZrLrtq4mwPiIkpfRb8IRqneA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.8.0", + "eslint-visitor-keys": "^2.0.0" + } + }, + "acorn": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "dev": true + }, + "acorn-jsx": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", + "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", + "dev": true + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -215,6 +448,12 @@ "uri-js": "^4.2.2" } }, + "ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true + }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -263,6 +502,12 @@ "integrity": "sha1-uveeYubvTCpMC4MSMtr/7CUfnYM=", "dev": true }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, "asn1": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", @@ -278,6 +523,12 @@ "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", "dev": true }, + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -401,6 +652,15 @@ "concat-map": "0.0.1" } }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, "buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -439,6 +699,12 @@ "get-intrinsic": "^1.0.0" } }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -631,6 +897,17 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -640,6 +917,15 @@ "assert-plus": "^1.0.0" } }, + "debug": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", + "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -714,6 +1000,24 @@ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "dotignore": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz", @@ -796,6 +1100,15 @@ "once": "^1.4.0" } }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + } + }, "es-abstract": { "version": "1.18.0-next.1", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.1.tgz", @@ -870,12 +1183,236 @@ } } }, + "eslint": { + "version": "7.13.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.13.0.tgz", + "integrity": "sha512-uCORMuOO8tUzJmsdRtrvcGq5qposf7Rw0LwkTJkoDbOycVQtQjmnhZSuLQnozLE4TmAzlMVV45eCHmQ1OpDKUQ==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@eslint/eslintrc": "^0.2.1", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "eslint-scope": "^5.1.1", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^2.0.0", + "espree": "^7.3.0", + "esquery": "^1.2.0", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^5.0.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.1.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.0", + "strip-json-comments": "^3.1.0", + "table": "^5.2.3", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "strip-ansi": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", + "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.0" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + } + } + }, + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } + } + }, + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true + }, + "espree": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.0.tgz", + "integrity": "sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==", + "dev": true, + "requires": { + "acorn": "^7.4.0", + "acorn-jsx": "^5.2.0", + "eslint-visitor-keys": "^1.3.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "dev": true + } + } + }, "esprima": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=", "dev": true }, + "esquery": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz", + "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==", + "dev": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", + "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", + "dev": true + } + } + }, "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", @@ -906,6 +1443,20 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-glob": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.4.tgz", + "integrity": "sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.0", + "merge2": "^1.3.0", + "micromatch": "^4.0.2", + "picomatch": "^2.2.1" + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -918,6 +1469,33 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fastq": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.9.0.tgz", + "integrity": "sha512-i7FVWL8HhVY+CTkwFxkN2mk3h+787ixS5S63eb78diVRc1MCssarHq3W5cj0av7YDSwmaV928RNag+U1etRQ7w==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -928,6 +1506,34 @@ "path-exists": "^4.0.0" } }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + }, + "dependencies": { + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } + } + }, + "flatted": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", + "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "dev": true + }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -1019,6 +1625,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "gauge": { "version": "2.7.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", @@ -1076,6 +1688,46 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz", + "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "globals": { + "version": "12.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", + "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "dev": true, + "requires": { + "type-fest": "^0.8.1" + } + }, + "globby": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.1.tgz", + "integrity": "sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.1.1", + "ignore": "^5.1.4", + "merge2": "^1.3.0", + "slash": "^3.0.0" + }, + "dependencies": { + "ignore": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", + "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", + "dev": true + } + } + }, "graceful-fs": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", @@ -1158,6 +1810,28 @@ "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", "dev": true }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "import-fresh": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.2.tgz", + "integrity": "sha512-cTPNrlvJT6twpYy+YmKUKrTSjWFs3bjYjAhCwm+z4EOCubZxAuO+hHpRN64TqjEaYSHs7tJAE0w1CKMGmsG/lw==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -1213,6 +1887,12 @@ "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", "dev": true }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -1223,6 +1903,15 @@ "number-is-nan": "^1.0.0" } }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, "is-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.1.tgz", @@ -1247,6 +1936,12 @@ "integrity": "sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE=", "dev": true }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, "is-number-object": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.4.tgz", @@ -1346,6 +2041,12 @@ "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", "dev": true }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -1416,6 +2117,12 @@ "jsonify": "~0.0.0" } }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -1468,12 +2175,34 @@ "p-locate": "^4.1.0" } }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", + "dev": true + }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", "integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==", "dev": true }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, + "micromatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", + "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.0.5" + } + }, "mime-db": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", @@ -1513,6 +2242,18 @@ "minimist": "^1.2.5" } }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -1693,6 +2434,15 @@ "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, "parsimmon": { "version": "1.16.0", "resolved": "https://registry.npmjs.org/parsimmon/-/parsimmon-1.16.0.tgz", @@ -1711,12 +2461,24 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -1741,6 +2503,12 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -1819,6 +2587,12 @@ } } }, + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, "request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -1869,6 +2643,12 @@ "path-parse": "^1.0.6" } }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, "resumer": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", @@ -1884,6 +2664,12 @@ "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=", "dev": true }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -1902,6 +2688,12 @@ "fsevents": "~2.1.2" } }, + "run-parallel": { + "version": "1.1.10", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.10.tgz", + "integrity": "sha512-zb/1OuZ6flOlH6tQyMPUrE3x3Ulxjlo9WIVXR4yVYi4H9UXQaeIsPbLn2R3O3vQCnDKkAl2qHiuocKKX4Tz/Sw==", + "dev": true + }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1926,6 +2718,21 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, "side-channel": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.3.tgz", @@ -1943,6 +2750,55 @@ "dev": true, "optional": true }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + } + } + }, "slide": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz", @@ -2106,6 +2962,58 @@ "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "dev": true }, + "table": { + "version": "5.4.6", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", + "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", + "dev": true, + "requires": { + "ajv": "^6.10.2", + "lodash": "^4.17.14", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, "tape": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/tape/-/tape-5.0.1.tgz", @@ -2213,6 +3121,12 @@ } } }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -2228,6 +3142,15 @@ "rimraf": "^3.0.0" } }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -2320,6 +3243,12 @@ "prelude-ls": "~1.1.2" } }, + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", @@ -2364,6 +3293,12 @@ "from": "github:jkroso/v8-argv#1.1.1", "dev": true }, + "v8-compile-cache": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz", + "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==", + "dev": true + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -2394,6 +3329,15 @@ "extsprintf": "^1.2.0" } }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, "which-boxed-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz", @@ -2470,6 +3414,12 @@ "string-width": "^1.0.2 || 2" } }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", @@ -2527,6 +3477,15 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", diff --git a/package.json b/package.json index 05a21f1..7b75bb7 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,8 @@ "clean": "npm run clean:dist && npm run clean:types", "clean:dist": "rimraf dist", "clean:types": "rimraf 'types/[!legacy/]*'", + "lint": "npm run lint:js", + "lint:js": "eslint .", "presize": "npm run build:js", "size": "terser --compress --mangle -- ./dist/index.umd.js | gzip -c | wc -c", "test": "npm run test:js && npm run test:types && npm run test:jsmd", @@ -70,7 +72,10 @@ "@rollup/plugin-node-resolve": "^10.0.0", "@rollup/plugin-typescript": "^6.1.0", "@types/node": "^8.10.54", + "@typescript-eslint/eslint-plugin": "^4.8.0", + "@typescript-eslint/parser": "^4.8.0", "dtslint": "^4.0.5", + "eslint": "^7.13.0", "is-mergeable-object": "1.1.0", "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", From e0b302f69a925e5fba1aeb1b8759694cd478f1c7 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 17 Nov 2020 12:53:49 +1300 Subject: [PATCH 26/36] style(lint): apply linting fixes --- rollup.config.js | 2 +- src/deepmerge.ts | 28 +- src/options.ts | 36 +- src/types.ts | 25 +- src/utils.ts | 16 +- test/custom-array-merge.js | 44 +- test/custom-is-mergeable-object.js | 36 +- test/merge-all.js | 68 +-- test/merge-plain-objects.js | 12 +- test/merge.js | 695 ++++++++++++++--------------- test/prototype-poisoning.js | 86 ++-- test/types/test.ts | 140 +++--- 12 files changed, 590 insertions(+), 598 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index c0650ab..1c2d5a8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -12,7 +12,7 @@ export default { plugins: [ resolve(), commonjs(), - typescript() + typescript(), ], output: [ diff --git a/src/deepmerge.ts b/src/deepmerge.ts index 43db614..36bfd88 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -40,7 +40,7 @@ function mergeObject< export function deepmergeImpl( target: T1, source: T2, - options: FullOptions + options: FullOptions, ): DeepMerge> { const sourceIsArray = Array.isArray(source) const targetIsArray = Array.isArray(target) @@ -49,16 +49,16 @@ export function deepmergeImpl if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options) as DeepMerge> } else if (sourceIsArray) { - return options.arrayMerge(target as unknown[], source as unknown[], options) as DeepMerge< - T1, - T2, - ExplicitOptions - > + return options.arrayMerge( + target as Array, + source as Array, + options, + ) as DeepMerge> } else { return mergeObject( target as Record, source as Record, - options + options, ) as DeepMerge> } } @@ -70,11 +70,11 @@ export function deepmergeImpl * @param source The second object. * @param options Deep merge options. */ -export default function deepmerge< - T1 extends object, - T2 extends object, - O extends Options = {} ->(target: T1, source: T2, options?: O) { +export default function deepmerge( + target: T1, + source: T2, + options?: O, +): DeepMerge> { return deepmergeImpl(target, source, getFullOptions(options)) } @@ -85,8 +85,8 @@ export default function deepmerge< * @param options Deep merge options. */ export function deepmergeAll< - Ts extends readonly [object, ...object[]], - O extends Options = {} + Ts extends readonly [object, ...Array], + O extends Options = object >(objects: [...Ts], options?: O): DeepMergeAll> /** diff --git a/src/options.ts b/src/options.ts index 01c7022..ae62860 100644 --- a/src/options.ts +++ b/src/options.ts @@ -24,14 +24,14 @@ export type ExplicitOptions = { * Deep merge options with defaults applied. */ export type FullOptions = { - arrayMerge: O["arrayMerge"] extends undefined + arrayMerge: O[`arrayMerge`] extends undefined ? typeof defaultArrayMerge - : NonNullable - clone: O["clone"] extends undefined ? true : NonNullable - customMerge?: O["customMerge"] - isMergeable: O["isMergeable"] extends undefined + : NonNullable + clone: O[`clone`] extends undefined ? true : NonNullable + customMerge?: O[`customMerge`] + isMergeable: O[`isMergeable`] extends undefined ? typeof defaultIsMergeable - : NonNullable + : NonNullable cloneUnlessOtherwiseSpecified: (value: T, options: FullOptions) => T } @@ -43,7 +43,7 @@ export type IsMergeable = (value: any) => boolean /** * A function that merges any 2 arrays. */ -export type ArrayMerge = (target: T1[], source: T2[], options: FullOptions) => any +export type ArrayMerge = (target: Array, source: Array, options: FullOptions) => any /** * A function that merges any 2 non-arrays values. @@ -57,12 +57,12 @@ function defaultIsMergeable(value: unknown): value is Record } function defaultArrayMerge( - target: readonly T1[], - source: readonly T2[], - options: FullOptions + target: ReadonlyArray, + source: ReadonlyArray, + options: FullOptions, ) { - return [...target, ...source].map((element) => - cloneUnlessOtherwiseSpecified(element, options) + return [ ...target, ...source ].map((element) => + cloneUnlessOtherwiseSpecified(element, options), ) as T1 extends readonly [...infer E1] ? T2 extends readonly [...infer E2] ? [...E1, ...E2] @@ -70,14 +70,14 @@ function defaultArrayMerge( : never } -export function getFullOptions(options?: O) { - const overrides = - options === undefined +export function getFullOptions(options?: O): FullOptions { + const overrides + = options === undefined ? undefined : (Object.fromEntries( - // Filter out keys explicitly set to undefined. - Object.entries(options).filter(([key, value]) => value !== undefined) - ) as O) + // Filter out keys explicitly set to undefined. + Object.entries(options).filter(([ _key, value ]) => value !== undefined), + ) as O) return { arrayMerge: defaultArrayMerge, diff --git a/src/types.ts b/src/types.ts index 99f7e5a..f298a09 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,11 +4,11 @@ import type { Options } from "./options" * Deep merge 1 or more types given in an array. */ export type DeepMergeAll< - Ts extends readonly [any, ...any[]], + Ts extends readonly [any, ...Array], O extends Options -> = Ts extends readonly [infer T1, ...any[]] +> = Ts extends readonly [infer T1, ...Array] ? Ts extends readonly [T1, infer T2, ...infer TRest] - ? TRest extends readonly never[] + ? TRest extends ReadonlyArray ? DeepMerge : DeepMerge, O> : T1 @@ -54,8 +54,8 @@ type DeepMergeObjectProps = Or< IsUndefinedOrNever > extends true ? Leaf - : IsUndefinedOrNever extends true - ? IsUndefinedOrNever extends true + : IsUndefinedOrNever extends true + ? IsUndefinedOrNever extends true ? DeepMerge : DeepMergeObjectPropsCustom : MaybeLeaf @@ -65,16 +65,16 @@ type DeepMergeObjectProps = Or< * merged and where a "customMerge" function has been provided. */ type DeepMergeObjectPropsCustom = ReturnType< - NonNullable + NonNullable > extends undefined ? DeepMerge - : undefined extends ReturnType> + : undefined extends ReturnType> ? Or, IsArray> extends true ? And, IsArray> extends true ? DeepMergeArrays : Leaf - : DeepMerge | ReturnType>>> - : ReturnType>>> + : DeepMerge | ReturnType>>> + : ReturnType>>> /** * Deep merge 2 arrays. @@ -83,13 +83,13 @@ type DeepMergeObjectPropsCustom = ReturnType< * TypeScript does not yet support higher order types. * @see https://github.com/Microsoft/TypeScript/issues/1213 */ -type DeepMergeArrays = IsUndefinedOrNever extends true +type DeepMergeArrays = IsUndefinedOrNever extends true ? T1 extends readonly [...infer E1] ? T2 extends readonly [...infer E2] ? [...E1, ...E2] : never : never - : ReturnType> + : ReturnType> /** * Get the leaf type from 2 types that can't be merged. @@ -111,12 +111,13 @@ type MaybeLeaf = Or< > extends true ? Leaf : // TODO: Handle case where return type of "isMergeable" is a typeguard. If it is we can do better than just "unknown". - unknown + unknown /** * Flatten a complex type such as a union or intersection of objects into a * single object. */ +// eslint-disable-next-line @typescript-eslint/ban-types type FlatternAlias = {} & { [P in keyof T]: T[P] } /** diff --git a/src/utils.ts b/src/utils.ts index f626e6f..51b90b6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -14,19 +14,21 @@ export function cloneUnlessOtherwiseSpecified(value: T, options: FullOptions) function getEnumerableOwnPropertySymbols(target: object) { return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter((symbol) => target.propertyIsEnumerable(symbol)) + ? Object.getOwnPropertySymbols(target).filter((symbol) => + Object.prototype.propertyIsEnumerable.call(target, symbol), + ) : [] } -export function getKeys(target: object) { +export function getKeys(target: object): Array { // Symbols cannot be used to index objects yet. // So cast to an array of strings for simplicity. // @see https://github.com/microsoft/TypeScript/issues/1863 // TODO: Remove cast once symbols indexing of objects is supported. - return [...Object.keys(target), ...getEnumerableOwnPropertySymbols(target)] as string[] + return [ ...Object.keys(target), ...getEnumerableOwnPropertySymbols(target) ] as Array } -export function propertyIsOnObject(object: object, property: Property) { +export function propertyIsOnObject(object: object, property: Property): boolean { try { return property in object } catch (_) { @@ -36,17 +38,17 @@ export function propertyIsOnObject(object: object, property: Property) { export function getMergeFunction( key: Property, - options: FullOptions + options: FullOptions, ): NonNullable> { if (!options.customMerge) { return deepmergeImpl } const customMerge = options.customMerge(key) - return typeof customMerge === "function" ? customMerge : deepmergeImpl + return typeof customMerge === `function` ? customMerge : deepmergeImpl } // Protects from prototype poisoning and unexpected merging up the prototype chain. -export function propertyIsUnsafe(target: object, key: Property) { +export function propertyIsUnsafe(target: object, key: Property): boolean { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. diff --git a/test/custom-array-merge.js b/test/custom-array-merge.js index 4931369..86c7299 100644 --- a/test/custom-array-merge.js +++ b/test/custom-array-merge.js @@ -1,8 +1,8 @@ -var merge = require('../').default -var test = require('tape') +const merge = require(`../`).default +const test = require(`tape`) -test('custom merge array', function(t) { - var mergeFunctionCalled = false +test(`custom merge array`, (t) => { + let mergeFunctionCalled = false function overwriteMerge(target, source, options) { mergeFunctionCalled = true t.equal(options.arrayMerge, overwriteMerge) @@ -11,7 +11,7 @@ test('custom merge array', function(t) { } const destination = { someArray: [ 1, 2 ], - someObject: { what: 'yes' }, + someObject: { what: `yes` }, } const source = { someArray: [ 1, 2, 3 ], @@ -20,7 +20,7 @@ test('custom merge array', function(t) { const actual = merge(destination, source, { arrayMerge: overwriteMerge }) const expected = { someArray: [ 1, 2, 3 ], - someObject: { what: 'yes' }, + someObject: { what: `yes` }, } t.ok(mergeFunctionCalled) @@ -28,38 +28,36 @@ test('custom merge array', function(t) { t.end() }) -test('merge top-level arrays', function(t) { +test(`merge top-level arrays`, (t) => { function overwriteMerge(a, b) { return b } - var actual = merge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) - var expected = [ 1, 2 ] + const actual = merge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) + const expected = [ 1, 2 ] t.deepEqual(actual, expected) t.end() }) -test('cloner function is available for merge functions to use', function(t) { - var customMergeWasCalled = false +test(`cloner function is available for merge functions to use`, (t) => { + let customMergeWasCalled = false function cloneMerge(target, source, options) { customMergeWasCalled = true - t.ok(options.cloneUnlessOtherwiseSpecified, 'cloner function is available') - return target.concat(source).map(function(element) { - return options.cloneUnlessOtherwiseSpecified(element, options) - }) + t.ok(options.cloneUnlessOtherwiseSpecified, `cloner function is available`) + return target.concat(source).map((element) => options.cloneUnlessOtherwiseSpecified(element, options)) } - var src = { - key1: [ 'one', 'three' ], - key2: [ 'four' ], + const src = { + key1: [ `one`, `three` ], + key2: [ `four` ], } - var target = { - key1: [ 'one', 'two' ], + const target = { + key1: [ `one`, `two` ], } - var expected = { - key1: [ 'one', 'two', 'one', 'three' ], - key2: [ 'four' ], + const expected = { + key1: [ `one`, `two`, `one`, `three` ], + key2: [ `four` ], } t.deepEqual(merge(target, src, { arrayMerge: cloneMerge }), expected) diff --git a/test/custom-is-mergeable-object.js b/test/custom-is-mergeable-object.js index 44cde16..5025e61 100644 --- a/test/custom-is-mergeable-object.js +++ b/test/custom-is-mergeable-object.js @@ -1,36 +1,36 @@ -var merge = require('../').default -var test = require('tape') +const merge = require(`../`).default +const test = require(`tape`) -test('isMergeable function copying object over object', function(t) { - var src = { key: { isMergeable: false }, baz: 'yes' } - var target = { key: { foo: 'wat' }, baz: 'whatever' } +test(`isMergeable function copying object over object`, (t) => { + const src = { key: { isMergeable: false }, baz: `yes` } + const target = { key: { foo: `wat` }, baz: `whatever` } function customIsMergeable(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof value === `object` && object.isMergeable !== false } - var res = merge(target, src, { - isMergeable: customIsMergeable + const res = merge(target, src, { + isMergeable: customIsMergeable, }) - t.deepEqual(res, { key: { isMergeable: false }, baz: 'yes' }) - t.equal(res.key, src.key, 'Object has the same identity and was not cloned') + t.deepEqual(res, { key: { isMergeable: false }, baz: `yes` }) + t.equal(res.key, src.key, `Object has the same identity and was not cloned`) t.end() }) -test('isMergeable function copying object over nothing', function(t) { - var src = { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' } - var target = { baz: 'whatever' } +test(`isMergeable function copying object over nothing`, (t) => { + const src = { key: { isMergeable: false, foo: `bar` }, baz: `yes` } + const target = { baz: `whatever` } function customIsMergeable(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof value === `object` && object.isMergeable !== false } - var res = merge(target, src, { - isMergeable: customIsMergeable + const res = merge(target, src, { + isMergeable: customIsMergeable, }) - t.deepEqual(res, { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' }) - t.equal(res.key, src.key, 'Object has the same identity and was not cloned') + t.deepEqual(res, { key: { isMergeable: false, foo: `bar` }, baz: `yes` }) + t.equal(res.key, src.key, `Object has the same identity and was not cloned`) t.end() }) diff --git a/test/merge-all.js b/test/merge-all.js index 005a852..9108874 100644 --- a/test/merge-all.js +++ b/test/merge-all.js @@ -1,56 +1,56 @@ -var mergeAll = require('../').deepmergeAll -var test = require('tape') +const mergeAll = require(`../`).deepmergeAll +const test = require(`tape`) -test('throw error if first argument is not an array', function(t) { - t.throws(mergeAll.bind(null, { example: true }, { another: '2' }), Error) +test(`throw error if first argument is not an array`, (t) => { + t.throws(mergeAll.bind(null, { example: true }, { another: `2` }), Error) t.end() }) -test('return an empty object if first argument is an array with no elements', function(t) { +test(`return an empty object if first argument is an array with no elements`, (t) => { t.deepEqual(mergeAll([]), {}) t.end() }) -test('Work just fine if first argument is an array with least than two elements', function(t) { - var actual = mergeAll([{ example: true }]) - var expected = { example: true } +test(`Work just fine if first argument is an array with least than two elements`, (t) => { + const actual = mergeAll([{ example: true }]) + const expected = { example: true } t.deepEqual(actual, expected) t.end() }) -test('execute correctly if options object were not passed', function(t) { - var arrayToMerge = [{ example: true }, { another: '123' }] +test(`execute correctly if options object were not passed`, (t) => { + const arrayToMerge = [{ example: true }, { another: `123` }] t.doesNotThrow(mergeAll.bind(null, arrayToMerge)) t.end() }) -test('execute correctly if options object were passed', function(t) { - var arrayToMerge = [{ example: true }, { another: '123' }] +test(`execute correctly if options object were passed`, (t) => { + const arrayToMerge = [{ example: true }, { another: `123` }] t.doesNotThrow(mergeAll.bind(null, arrayToMerge, { clone: true })) t.end() }) -test('invoke merge on every item in array should result with all props', function(t) { - var firstObject = { first: true } - var secondObject = { second: false } - var thirdObject = { third: 123 } - var fourthObject = { fourth: 'some string' } +test(`invoke merge on every item in array should result with all props`, (t) => { + const firstObject = { first: true } + const secondObject = { second: false } + const thirdObject = { third: 123 } + const fourthObject = { fourth: `some string` } - var mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) + const mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) t.ok(mergedObject.first === true) t.ok(mergedObject.second === false) t.ok(mergedObject.third === 123) - t.ok(mergedObject.fourth === 'some string') + t.ok(mergedObject.fourth === `some string`) t.end() }) -test('invoke merge on every item in array with clone should clone all elements', function(t) { - var firstObject = { a: { d: 123 } } - var secondObject = { b: { e: true } } - var thirdObject = { c: { f: 'string' } } +test(`invoke merge on every item in array with clone should clone all elements`, (t) => { + const firstObject = { a: { d: 123 } } + const secondObject = { b: { e: true } } + const thirdObject = { c: { f: `string` } } - var mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) + const mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithClone.a, firstObject.a) t.notEqual(mergedWithClone.b, secondObject.b) @@ -59,12 +59,12 @@ test('invoke merge on every item in array with clone should clone all elements', t.end() }) -test('invoke merge on every item in array clone=false should not clone all elements', function(t) { - var firstObject = { a: { d: 123 } } - var secondObject = { b: { e: true } } - var thirdObject = { c: { f: 'string' } } +test(`invoke merge on every item in array clone=false should not clone all elements`, (t) => { + const firstObject = { a: { d: 123 } } + const secondObject = { b: { e: true } } + const thirdObject = { c: { f: `string` } } - var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) + const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) t.equal(mergedWithoutClone.a, firstObject.a) t.equal(mergedWithoutClone.b, secondObject.b) @@ -74,12 +74,12 @@ test('invoke merge on every item in array clone=false should not clone all eleme }) -test('invoke merge on every item in array without clone should clone all elements', function(t) { - var firstObject = { a: { d: 123 } } - var secondObject = { b: { e: true } } - var thirdObject = { c: { f: 'string' } } +test(`invoke merge on every item in array without clone should clone all elements`, (t) => { + const firstObject = { a: { d: 123 } } + const secondObject = { b: { e: true } } + const thirdObject = { c: { f: `string` } } - var mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) + const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge-plain-objects.js b/test/merge-plain-objects.js index 2f16574..29dcca3 100644 --- a/test/merge-plain-objects.js +++ b/test/merge-plain-objects.js @@ -1,10 +1,10 @@ -var merge = require('../').default -var test = require('tape') +const merge = require(`../`).default +const test = require(`tape`) -test('plain objects are merged by default', function(t) { +test(`plain objects are merged by default`, (t) => { const input = { newObject: new Object(), - objectLiteral: { a: 123 } + objectLiteral: { a: 123 }, } const output = merge({}, input) @@ -16,11 +16,11 @@ test('plain objects are merged by default', function(t) { t.end() }) -test('instantiated objects are copied by reference', function(t) { +test(`instantiated objects are copied by reference`, (t) => { const input = { date: new Date(), error: new Error(), - regex: /regex/ + regex: /regex/, } const output = merge({}, input) diff --git a/test/merge.js b/test/merge.js index c3e9e65..92f381f 100644 --- a/test/merge.js +++ b/test/merge.js @@ -1,104 +1,104 @@ -var merge = require('../').default -var test = require('tape') +const merge = require(`../`).default +const test = require(`tape`) -test('add keys in target that do not exist at the root', function(t) { - var src = { key1: 'value1', key2: 'value2' } - var target = {} +test(`add keys in target that do not exist at the root`, (t) => { + const src = { key1: `value1`, key2: `value2` } + const target = {} - var res = merge(target, src) + const res = merge(target, src) - t.deepEqual(target, {}, 'merge should be immutable') + t.deepEqual(target, {}, `merge should be immutable`) t.deepEqual(res, src) t.end() }) -test('merge existing simple keys in target at the roots', function(t) { - var src = { key1: 'changed', key2: 'value2' } - var target = { key1: 'value1', key3: 'value3' } +test(`merge existing simple keys in target at the roots`, (t) => { + const src = { key1: `changed`, key2: `value2` } + const target = { key1: `value1`, key3: `value3` } - var expected = { - key1: 'changed', - key2: 'value2', - key3: 'value3', + const expected = { + key1: `changed`, + key2: `value2`, + key3: `value3`, } - t.deepEqual(target, { key1: 'value1', key3: 'value3' }) + t.deepEqual(target, { key1: `value1`, key3: `value3` }) t.deepEqual(merge(target, src), expected) t.end() }) -test('merge nested objects into target', function(t) { - var src = { +test(`merge nested objects into target`, (t) => { + const src = { key1: { - subkey1: 'changed', - subkey3: 'added', + subkey1: `changed`, + subkey3: `added`, }, } - var target = { + const target = { key1: { - subkey1: 'value1', - subkey2: 'value2', + subkey1: `value1`, + subkey2: `value2`, }, } - var expected = { + const expected = { key1: { - subkey1: 'changed', - subkey2: 'value2', - subkey3: 'added', + subkey1: `changed`, + subkey2: `value2`, + subkey3: `added`, }, } t.deepEqual(target, { key1: { - subkey1: 'value1', - subkey2: 'value2', + subkey1: `value1`, + subkey2: `value2`, }, }) t.deepEqual(merge(target, src), expected) t.end() }) -test('replace simple key with nested object in target', function(t) { - var src = { +test(`replace simple key with nested object in target`, (t) => { + const src = { key1: { - subkey1: 'subvalue1', - subkey2: 'subvalue2', + subkey1: `subvalue1`, + subkey2: `subvalue2`, }, } - var target = { - key1: 'value1', - key2: 'value2', + const target = { + key1: `value1`, + key2: `value2`, } - var expected = { + const expected = { key1: { - subkey1: 'subvalue1', - subkey2: 'subvalue2', + subkey1: `subvalue1`, + subkey2: `subvalue2`, }, - key2: 'value2', + key2: `value2`, } - t.deepEqual(target, { key1: 'value1', key2: 'value2' }) + t.deepEqual(target, { key1: `value1`, key2: `value2` }) t.deepEqual(merge(target, src), expected) t.end() }) -test('should add nested object in target', function(t) { - var src = { - "b": { - "c": {}, +test(`should add nested object in target`, (t) => { + const src = { + b: { + c: {}, }, } - var target = { - "a": {}, + const target = { + a: {}, } - var expected = { - "a": {}, - "b": { - "c": {}, + const expected = { + a: {}, + b: { + c: {}, }, } @@ -106,29 +106,29 @@ test('should add nested object in target', function(t) { t.end() }) -test('should clone source and target', function(t) { - var src = { - "b": { - "c": "foo", +test(`should clone source and target`, (t) => { + const src = { + b: { + c: `foo`, }, } - var target = { - "a": { - "d": "bar", + const target = { + a: { + d: `bar`, }, } - var expected = { - "a": { - "d": "bar", + const expected = { + a: { + d: `bar`, }, - "b": { - "c": "foo", + b: { + c: `foo`, }, } - var merged = merge(target, src, { clone: true }) + const merged = merge(target, src, { clone: true }) t.deepEqual(merged, expected) @@ -138,133 +138,133 @@ test('should clone source and target', function(t) { t.end() }) -test('should clone source and target', function(t) { - var src = { - "b": { - "c": "foo", +test(`should clone source and target`, (t) => { + const src = { + b: { + c: `foo`, }, } - var target = { - "a": { - "d": "bar", + const target = { + a: { + d: `bar`, }, } - var merged = merge(target, src) + const merged = merge(target, src) t.notEqual(merged.a, target.a) t.notEqual(merged.b, src.b) t.end() }) -test('should replace object with simple key in target', function(t) { - var src = { key1: 'value1' } - var target = { +test(`should replace object with simple key in target`, (t) => { + const src = { key1: `value1` } + const target = { key1: { - subkey1: 'subvalue1', - subkey2: 'subvalue2', + subkey1: `subvalue1`, + subkey2: `subvalue2`, }, - key2: 'value2', + key2: `value2`, } - var expected = { key1: 'value1', key2: 'value2' } + const expected = { key1: `value1`, key2: `value2` } t.deepEqual(target, { key1: { - subkey1: 'subvalue1', - subkey2: 'subvalue2', + subkey1: `subvalue1`, + subkey2: `subvalue2`, }, - key2: 'value2', + key2: `value2`, }) t.deepEqual(merge(target, src), expected) t.end() }) -test('should replace objects with arrays', function(t) { - var target = { key1: { subkey: 'one' } } +test(`should replace objects with arrays`, (t) => { + const target = { key1: { subkey: `one` } } - var src = { key1: [ 'subkey' ] } + const src = { key1: [ `subkey` ] } - var expected = { key1: [ 'subkey' ] } + const expected = { key1: [ `subkey` ] } t.deepEqual(merge(target, src), expected) t.end() }) -test('should replace arrays with objects', function(t) { - var target = { key1: [ "subkey" ] } +test(`should replace arrays with objects`, (t) => { + const target = { key1: [ `subkey` ] } - var src = { key1: { subkey: 'one' } } + const src = { key1: { subkey: `one` } } - var expected = { key1: { subkey: 'one' } } + const expected = { key1: { subkey: `one` } } t.deepEqual(merge(target, src), expected) t.end() }) -test('should replace dates with arrays', function(t) { - var target = { key1: new Date() } +test(`should replace dates with arrays`, (t) => { + const target = { key1: new Date() } - var src = { key1: [ "subkey" ] } + const src = { key1: [ `subkey` ] } - var expected = { key1: [ "subkey" ] } + const expected = { key1: [ `subkey` ] } t.deepEqual(merge(target, src), expected) t.end() }) -test('should replace null with arrays', function(t) { - var target = { +test(`should replace null with arrays`, (t) => { + const target = { key1: null, } - var src = { - key1: [ "subkey" ], + const src = { + key1: [ `subkey` ], } - var expected = { - key1: [ "subkey" ], + const expected = { + key1: [ `subkey` ], } t.deepEqual(merge(target, src), expected) t.end() }) -test('should work on simple array', function(t) { - var src = [ 'one', 'three' ] - var target = [ 'one', 'two' ] +test(`should work on simple array`, (t) => { + const src = [ `one`, `three` ] + const target = [ `one`, `two` ] - var expected = [ 'one', 'two', 'one', 'three' ] + const expected = [ `one`, `two`, `one`, `three` ] t.deepEqual(merge(target, src), expected) t.ok(Array.isArray(merge(target, src))) t.end() }) -test('should work on another simple array', function(t) { - var target = [ "a1", "a2", "c1", "f1", "p1" ] - var src = [ "t1", "s1", "c2", "r1", "p2", "p3" ] +test(`should work on another simple array`, (t) => { + const target = [ `a1`, `a2`, `c1`, `f1`, `p1` ] + const src = [ `t1`, `s1`, `c2`, `r1`, `p2`, `p3` ] - var expected = [ "a1", "a2", "c1", "f1", "p1", "t1", "s1", "c2", "r1", "p2", "p3" ] - t.deepEqual(target, [ "a1", "a2", "c1", "f1", "p1" ]) + const expected = [ `a1`, `a2`, `c1`, `f1`, `p1`, `t1`, `s1`, `c2`, `r1`, `p2`, `p3` ] + t.deepEqual(target, [ `a1`, `a2`, `c1`, `f1`, `p1` ]) t.deepEqual(merge(target, src), expected) t.ok(Array.isArray(merge(target, src))) t.end() }) -test('should work on array properties', function(t) { - var src = { - key1: [ 'one', 'three' ], - key2: [ 'four' ], +test(`should work on array properties`, (t) => { + const src = { + key1: [ `one`, `three` ], + key2: [ `four` ], } - var target = { - key1: [ 'one', 'two' ], + const target = { + key1: [ `one`, `two` ], } - var expected = { - key1: [ 'one', 'two', 'one', 'three' ], - key2: [ 'four' ], + const expected = { + key1: [ `one`, `two`, `one`, `three` ], + key2: [ `four` ], } t.deepEqual(merge(target, src), expected) @@ -273,70 +273,70 @@ test('should work on array properties', function(t) { t.end() }) -test('should work on array properties with clone option', function(t) { - var src = { - key1: [ 'one', 'three' ], - key2: [ 'four' ], +test(`should work on array properties with clone option`, (t) => { + const src = { + key1: [ `one`, `three` ], + key2: [ `four` ], } - var target = { - key1: [ 'one', 'two' ], + const target = { + key1: [ `one`, `two` ], } t.deepEqual(target, { - key1: [ 'one', 'two' ], + key1: [ `one`, `two` ], }) - var merged = merge(target, src, { clone: true }) + const merged = merge(target, src, { clone: true }) t.notEqual(merged.key1, src.key1) t.notEqual(merged.key1, target.key1) t.notEqual(merged.key2, src.key2) t.end() }) -test('should work on array of objects', function(t) { - var src = [ - { key1: [ 'one', 'three' ], key2: [ 'one' ] }, - { key3: [ 'five' ] }, +test(`should work on array of objects`, (t) => { + const src = [ + { key1: [ `one`, `three` ], key2: [ `one` ] }, + { key3: [ `five` ] }, ] - var target = [ - { key1: [ 'one', 'two' ] }, - { key3: [ 'four' ] }, + const target = [ + { key1: [ `one`, `two` ] }, + { key3: [ `four` ] }, ] - var expected = [ - { key1: [ 'one', 'two' ] }, - { key3: [ 'four' ] }, - { key1: [ 'one', 'three' ], key2: [ 'one' ] }, - { key3: [ 'five' ] }, + const expected = [ + { key1: [ `one`, `two` ] }, + { key3: [ `four` ] }, + { key1: [ `one`, `three` ], key2: [ `one` ] }, + { key3: [ `five` ] }, ] t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src)), 'result should be an array') - t.ok(Array.isArray(merge(target, src)[0].key1), 'subkey should be an array too') + t.ok(Array.isArray(merge(target, src)), `result should be an array`) + t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) t.end() }) -test('should work on array of objects with clone option', function(t) { - var src = [ - { key1: [ 'one', 'three' ], key2: [ 'one' ] }, - { key3: [ 'five' ] }, +test(`should work on array of objects with clone option`, (t) => { + const src = [ + { key1: [ `one`, `three` ], key2: [ `one` ] }, + { key3: [ `five` ] }, ] - var target = [ - { key1: [ 'one', 'two' ] }, - { key3: [ 'four' ] }, + const target = [ + { key1: [ `one`, `two` ] }, + { key3: [ `four` ] }, ] - var expected = [ - { key1: [ 'one', 'two' ] }, - { key3: [ 'four' ] }, - { key1: [ 'one', 'three' ], key2: [ 'one' ] }, - { key3: [ 'five' ] }, + const expected = [ + { key1: [ `one`, `two` ] }, + { key3: [ `four` ] }, + { key1: [ `one`, `three` ], key2: [ `one` ] }, + { key3: [ `five` ] }, ] - var merged = merge(target, src, { clone: true }) + const merged = merge(target, src, { clone: true }) t.deepEqual(merged, expected) - t.ok(Array.isArray(merge(target, src)), 'result should be an array') - t.ok(Array.isArray(merge(target, src)[0].key1), 'subkey should be an array too') + t.ok(Array.isArray(merge(target, src)), `result should be an array`) + t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) t.notEqual(merged[0].key1, src[0].key1) t.notEqual(merged[0].key1, target[0].key1) t.notEqual(merged[0].key2, src[0].key2) @@ -345,111 +345,111 @@ test('should work on array of objects with clone option', function(t) { t.end() }) -test('should treat regular expressions like primitive values', function(t) { - var target = { key1: /abc/ } - var src = { key1: /efg/ } - var expected = { key1: /efg/ } +test(`should treat regular expressions like primitive values`, (t) => { + const target = { key1: /abc/ } + const src = { key1: /efg/ } + const expected = { key1: /efg/ } t.deepEqual(merge(target, src), expected) - t.deepEqual(merge(target, src).key1.test('efg'), true) + t.deepEqual(merge(target, src).key1.test(`efg`), true) t.end() }) -test('should treat regular expressions like primitive values and should not' - + ' clone even with clone option', function(t) { - var target = { key1: /abc/ } - var src = { key1: /efg/ } +test(`should treat regular expressions like primitive values and should not` + + ` clone even with clone option`, (t) => { + const target = { key1: /abc/ } + const src = { key1: /efg/ } - var output = merge(target, src, { clone: true }) + const output = merge(target, src, { clone: true }) t.equal(output.key1, src.key1) t.end() -} +}, ) -test('should treat dates like primitives', function(t) { - var monday = new Date('2016-09-27T01:08:12.761Z') - var tuesday = new Date('2016-09-28T01:18:12.761Z') +test(`should treat dates like primitives`, (t) => { + const monday = new Date(`2016-09-27T01:08:12.761Z`) + const tuesday = new Date(`2016-09-28T01:18:12.761Z`) - var target = { + const target = { key: monday, } - var source = { + const source = { key: tuesday, } - var expected = { + const expected = { key: tuesday, } - var actual = merge(target, source) + const actual = merge(target, source) t.deepEqual(actual, expected) t.equal(actual.key.valueOf(), tuesday.valueOf()) t.end() }) -test('should treat dates like primitives and should not clone even with clone' - + ' option', function(t) { - var monday = new Date('2016-09-27T01:08:12.761Z') - var tuesday = new Date('2016-09-28T01:18:12.761Z') +test(`should treat dates like primitives and should not clone even with clone` + + ` option`, (t) => { + const monday = new Date(`2016-09-27T01:08:12.761Z`) + const tuesday = new Date(`2016-09-28T01:18:12.761Z`) - var target = { + const target = { key: monday, } - var source = { + const source = { key: tuesday, } - var actual = merge(target, source, { clone: true }) + const actual = merge(target, source, { clone: true }) t.equal(actual.key, tuesday) t.end() }) -test('should work on array with null in it', function(t) { - var target = [] +test(`should work on array with null in it`, (t) => { + const target = [] - var src = [ null ] + const src = [ null ] - var expected = [ null ] + const expected = [ null ] t.deepEqual(merge(target, src), expected) t.end() }) -test('should clone array\'s element if it is object', function(t) { - var a = { key: 'yup' } - var target = [] - var source = [ a ] +test(`should clone array's element if it is object`, (t) => { + const a = { key: `yup` } + const target = [] + const source = [ a ] - var output = merge(target, source, { clone: true }) + const output = merge(target, source, { clone: true }) t.notEqual(output[0], a) - t.equal(output[0].key, 'yup') + t.equal(output[0].key, `yup`) t.end() }) -test('should clone an array property when there is no target array', function(t) { +test(`should clone an array property when there is no target array`, (t) => { const someObject = {} - var target = {} - var source = { ary: [ someObject ] } - var output = merge(target, source, { clone: true }) + const target = {} + const source = { ary: [ someObject ] } + const output = merge(target, source, { clone: true }) t.deepEqual(output, { ary: [{}] }) t.notEqual(output.ary[0], someObject) t.end() }) -test('should overwrite values when property is initialised but undefined', function(t) { - var target1 = { value: [] } - var target2 = { value: null } - var target3 = { value: 2 } +test(`should overwrite values when property is initialised but undefined`, (t) => { + const target1 = { value: [] } + const target2 = { value: null } + const target3 = { value: 2 } - var src = { value: undefined } + const src = { value: undefined } function hasUndefinedProperty(o) { - t.ok(o.hasOwnProperty('value')) - t.equal(typeof o.value, 'undefined') + t.ok(Object.prototype.hasOwnProperty.call(o, `value`)) + t.equal(typeof o.value, `undefined`) } hasUndefinedProperty(merge(target1, src)) @@ -459,220 +459,215 @@ test('should overwrite values when property is initialised but undefined', funct t.end() }) -test('dates should copy correctly in an array', function(t) { - var monday = new Date('2016-09-27T01:08:12.761Z') - var tuesday = new Date('2016-09-28T01:18:12.761Z') +test(`dates should copy correctly in an array`, (t) => { + const monday = new Date(`2016-09-27T01:08:12.761Z`) + const tuesday = new Date(`2016-09-28T01:18:12.761Z`) - var target = [ monday, 'dude' ] - var source = [ tuesday, 'lol' ] + const target = [ monday, `dude` ] + const source = [ tuesday, `lol` ] - var expected = [ monday, 'dude', tuesday, 'lol' ] - var actual = merge(target, source) + const expected = [ monday, `dude`, tuesday, `lol` ] + const actual = merge(target, source) t.deepEqual(actual, expected) t.end() }) -test('should handle custom merge functions', function(t) { - var target = { - letters: ['a', 'b'], +test(`should handle custom merge functions`, (t) => { + const target = { + letters: [ `a`, `b` ], people: { - first: 'Alex', - second: 'Bert', - } + first: `Alex`, + second: `Bert`, + }, } - var source = { - letters: ['c'], + const source = { + letters: [ `c` ], people: { - first: 'Smith', - second: 'Bertson', - third: 'Car' - } - } - - const mergePeople = (target, source, options) => { - const keys = new Set(Object.keys(target).concat(Object.keys(source))) - const destination = {} - keys.forEach(key => { - if (key in target && key in source) { - destination[key] = `${target[key]}-${source[key]}` - } else if (key in target) { - destination[key] = target[key] - } else { - destination[key] = source[key] - } - }) - return destination - } - - const options = { - customMerge: (key, options) => { - if (key === 'people') { - return mergePeople - } - - return merge - } - } - - var expected = { - letters: ['a', 'b', 'c'], + first: `Smith`, + second: `Bertson`, + third: `Car`, + }, + } + + const mergePeople = (target, source, options) => { + const keys = new Set(Object.keys(target).concat(Object.keys(source))) + const destination = {} + keys.forEach((key) => { + if (key in target && key in source) { + destination[key] = `${ target[key] }-${ source[key] }` + } else if (key in target) { + destination[key] = target[key] + } else { + destination[key] = source[key] + } + }) + return destination + } + + const options = { + customMerge: (key, options) => { + if (key === `people`) { + return mergePeople + } + + return merge + }, + } + + const expected = { + letters: [ `a`, `b`, `c` ], people: { - first: 'Alex-Smith', - second: 'Bert-Bertson', - third: 'Car' - } + first: `Alex-Smith`, + second: `Bert-Bertson`, + third: `Car`, + }, } - var actual = merge(target, source, options) + const actual = merge(target, source, options) t.deepEqual(actual, expected) t.end() }) -test('should handle custom merge functions', function(t) { - var target = { - letters: ['a', 'b'], +test(`should handle custom merge functions`, (t) => { + const target = { + letters: [ `a`, `b` ], + people: { + first: `Alex`, + second: `Bert`, + }, + } + + const source = { + letters: [ `c` ], people: { - first: 'Alex', - second: 'Bert', - } + first: `Smith`, + second: `Bertson`, + third: `Car`, + }, + } + + const mergeLetters = (target, source, options) => `merged letters` + + + const options = { + customMerge: (key, options) => { + if (key === `letters`) { + return mergeLetters + } + }, } - var source = { - letters: ['c'], + const expected = { + letters: `merged letters`, people: { - first: 'Smith', - second: 'Bertson', - third: 'Car' - } - } - - const mergeLetters = (target, source, options) => { - return 'merged letters' - } - - - const options = { - customMerge: (key, options) => { - if (key === 'letters') { - return mergeLetters - } - } - } - - const expected = { - letters: 'merged letters', - people: { - first: 'Smith', - second: 'Bertson', - third: 'Car' - } - } - - var actual = merge(target, source, options) + first: `Smith`, + second: `Bertson`, + third: `Car`, + }, + } + + const actual = merge(target, source, options) t.deepEqual(actual, expected) t.end() }) -test('should merge correctly if custom merge is not a valid function', function(t) { - var target = { - letters: ['a', 'b'], +test(`should merge correctly if custom merge is not a valid function`, (t) => { + const target = { + letters: [ `a`, `b` ], + people: { + first: `Alex`, + second: `Bert`, + }, + } + + const source = { + letters: [ `c` ], people: { - first: 'Alex', - second: 'Bert', - } + first: `Smith`, + second: `Bertson`, + third: `Car`, + }, } - var source = { - letters: ['c'], + const options = { + customMerge: (key, options) => false, + } + + const expected = { + letters: [ `a`, `b`, `c` ], people: { - first: 'Smith', - second: 'Bertson', - third: 'Car' - } - } - - const options = { - customMerge: (key, options) => { - return false - } - } - - const expected = { - letters: ['a', 'b', 'c'], - people: { - first: 'Smith', - second: 'Bertson', - third: 'Car' - } - } - - var actual = merge(target, source, options) + first: `Smith`, + second: `Bertson`, + third: `Car`, + }, + } + + const actual = merge(target, source, options) t.deepEqual(actual, expected) t.end() - }) -test('copy symbol keys in target that do not exist on the target', function(t) { - var mySymbol = Symbol(); - var src = { [mySymbol]: 'value1' } - var target = {} +test(`copy symbol keys in target that do not exist on the target`, (t) => { + const mySymbol = Symbol() + const src = { [mySymbol]: `value1` } + const target = {} - var res = merge(target, src) + const res = merge(target, src) - t.equal(res[mySymbol], 'value1') + t.equal(res[mySymbol], `value1`) t.deepEqual(Object.getOwnPropertySymbols(res), Object.getOwnPropertySymbols(src)) t.end() }) -test('copy symbol keys in target that do exist on the target', function(t) { - var mySymbol = Symbol(); - var src = { [mySymbol]: 'value1' } - var target = { [mySymbol]: 'wat'} +test(`copy symbol keys in target that do exist on the target`, (t) => { + const mySymbol = Symbol() + const src = { [mySymbol]: `value1` } + const target = { [mySymbol]: `wat` } - var res = merge(target, src) + const res = merge(target, src) - t.equal(res[mySymbol], 'value1') + t.equal(res[mySymbol], `value1`) t.end() }) -test('should not mutate options', function(t) { - var options = {}; +test(`should not mutate options`, (t) => { + const options = {} - merge({}, {}, options); + merge({}, {}, options) - t.deepEqual(options, {}); - t.end(); + t.deepEqual(options, {}) + t.end() }) -test('Falsey properties should be mergeable', function(t) { - var uniqueValue = {} +test(`Falsey properties should be mergeable`, (t) => { + const uniqueValue = {} - var target = { - wat: false + const target = { + wat: false, } - var source = { - wat: false + const source = { + wat: false, } - var customMergeWasCalled = false + let customMergeWasCalled = false - var result = merge(target, source, { - isMergeable: function() { + const result = merge(target, source, { + isMergeable() { return true }, - customMerge: function() { + customMerge() { return function() { customMergeWasCalled = true return uniqueValue } - } + }, }) t.equal(result.wat, uniqueValue) - t.ok(customMergeWasCalled, 'custom merge function was called') + t.ok(customMergeWasCalled, `custom merge function was called`) t.end() }) diff --git a/test/prototype-poisoning.js b/test/prototype-poisoning.js index 34322ed..2a9d72d 100644 --- a/test/prototype-poisoning.js +++ b/test/prototype-poisoning.js @@ -1,49 +1,49 @@ -var merge = require('../').default -var test = require('tape') -var isMergeableObject = require('is-mergeable-object') +const merge = require(`../`).default +const test = require(`tape`) +const isMergeableObject = require(`is-mergeable-object`) -test('merging objects with own __proto__', function(t) { - var user = {} - var malicious = JSON.parse('{ "__proto__": { "admin": true } }') - var mergedObject = merge(user, malicious) - t.notOk(mergedObject.__proto__.admin, 'non-plain properties should not be merged') - t.notOk(mergedObject.admin, 'the destination should have an unmodified prototype') +test(`merging objects with own __proto__`, (t) => { + const user = {} + const malicious = JSON.parse(`{ "__proto__": { "admin": true } }`) + const mergedObject = merge(user, malicious) + t.notOk(mergedObject.__proto__.admin, `non-plain properties should not be merged`) + t.notOk(mergedObject.admin, `the destination should have an unmodified prototype`) t.end() }) -test('merging objects with plain and non-plain properties', function(t) { - var plainSymbolKey = Symbol('plainSymbolKey') - var parent = { - parentKey: 'should be undefined' +test(`merging objects with plain and non-plain properties`, (t) => { + const plainSymbolKey = Symbol(`plainSymbolKey`) + const parent = { + parentKey: `should be undefined`, } - var target = Object.create(parent) - target.plainKey = 'should be replaced' - target[plainSymbolKey] = 'should also be replaced' + const target = Object.create(parent) + target.plainKey = `should be replaced` + target[plainSymbolKey] = `should also be replaced` - var source = { - parentKey: 'foo', - plainKey: 'bar', - newKey: 'baz', - [plainSymbolKey]: 'qux' + const source = { + parentKey: `foo`, + plainKey: `bar`, + newKey: `baz`, + [plainSymbolKey]: `qux`, } - var mergedObject = merge(target, source) - t.equal(undefined, mergedObject.parentKey, 'inherited properties of target should be removed, not merged or ignored') - t.equal('bar', mergedObject.plainKey, 'enumerable own properties of target should be merged') - t.equal('baz', mergedObject.newKey, 'properties not yet on target should be merged') - t.equal('qux', mergedObject[plainSymbolKey], 'enumerable own symbol properties of target should be merged') + const mergedObject = merge(target, source) + t.equal(undefined, mergedObject.parentKey, `inherited properties of target should be removed, not merged or ignored`) + t.equal(`bar`, mergedObject.plainKey, `enumerable own properties of target should be merged`) + t.equal(`baz`, mergedObject.newKey, `properties not yet on target should be merged`) + t.equal(`qux`, mergedObject[plainSymbolKey], `enumerable own symbol properties of target should be merged`) t.end() }) // the following cases come from the thread here: https://github.com/TehShrike/deepmerge/pull/164 -test('merging strings works with a custom string merge', function(t) { - var target = { name: "Alexander" } - var source = { name: "Hamilton" } +test(`merging strings works with a custom string merge`, (t) => { + const target = { name: `Alexander` } + const source = { name: `Hamilton` } function customMerge(key, options) { - if (key === 'name') { + if (key === `name`) { return function(target, source, options) { - return target[0] + '. ' + source.substring(0, 3) + return target[0] + `. ` + source.substring(0, 3) } } else { return merge @@ -51,26 +51,26 @@ test('merging strings works with a custom string merge', function(t) { } function mergeable(target) { - return isMergeableObject(target) || (typeof target === 'string' && target.length > 1) + return isMergeableObject(target) || (typeof target === `string` && target.length > 1) } - t.equal('A. Ham', merge(target, source, { customMerge: customMerge, isMergeable: mergeable }).name) + t.equal(`A. Ham`, merge(target, source, { customMerge, isMergeable: mergeable }).name) t.end() }) -test('merging objects with null prototype', function(t) { - var target = Object.create(null) - var source = Object.create(null) +test(`merging objects with null prototype`, (t) => { + const target = Object.create(null) + const source = Object.create(null) target.wheels = 4 - target.trunk = { toolbox: ['hammer'] } - source.trunk = { toolbox: ['wrench'] } - source.engine = 'v8' - var expected = { + target.trunk = { toolbox: [ `hammer` ] } + source.trunk = { toolbox: [ `wrench` ] } + source.engine = `v8` + const expected = { wheels: 4, - engine: 'v8', + engine: `v8`, trunk: { - toolbox: ['hammer', 'wrench' ] - } + toolbox: [ `hammer`, `wrench` ], + }, } t.deepEqual(expected, merge(target, source)) diff --git a/test/types/test.ts b/test/types/test.ts index c9b5940..d104469 100644 --- a/test/types/test.ts +++ b/test/types/test.ts @@ -1,25 +1,25 @@ import deepmerge, { deepmergeAll } from "../../src" const a = { - foo: "abc", + foo: `abc`, baz: { - quuz: ["def", "ghi"], + quuz: [ `def`, `ghi` ], }, garply: 42, -}; +} const b = { - foo: "cba", + foo: `cba`, baz: { corge: 96, }, grault: 42, -}; +} // $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: number; grault: number; } -deepmerge(a, b); +deepmerge(a, b) // $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: number; grault: number; } -deepmergeAll([a, b]); +deepmergeAll([ a, b ]) type T = { readonly foo: string; @@ -28,153 +28,149 @@ type T = { // TODO: Should the result really be `T`? or should it be `DeepMutable`? // $ExpectType T -deepmerge(a as T, b as T); +deepmerge(a as T, b as T) // $ExpectType T -deepmergeAll([a as T, b as T]); +deepmergeAll([ a as T, b as T ]) type U = { bar?: string; } // $ExpectType { foo: string; bar?: string | undefined; } -deepmerge(a as T, b as U); +deepmerge(a as T, b as U) // $ExpectType { foo: string; bar?: string | undefined; } -deepmergeAll([a as T, b as U]); +deepmergeAll([ a as T, b as U ]) const c = { - bar: "123", - quux: "456", + bar: `123`, + quux: `456`, garply: 42, -} as const; +} as const // $ExpectType { foo: string; baz: { quuz: string[]; }; garply: 42; bar: "123"; quux: "456"; } -deepmerge(a, c); +deepmerge(a, c) // $ExpectType { foo: string; baz: { quuz: string[]; }; garply: 42; bar: "123"; quux: "456"; } -deepmergeAll([a, c]); +deepmergeAll([ a, c ]) // $ExpectType { foo: string; baz: { corge: number; }; grault: number; bar: "123"; quux: "456"; garply: 42; } -deepmerge(b, c); +deepmerge(b, c) // $ExpectType { foo: string; baz: { corge: number; }; grault: number; bar: "123"; quux: "456"; garply: 42; } -deepmergeAll([b, c]); +deepmergeAll([ b, c ]) // $ExpectType { foo: string; baz: { quuz: string[]; corge: number; }; garply: 42; grault: number; bar: "123"; quux: "456"; } -deepmergeAll([a, b, c]); +deepmergeAll([ a, b, c ]) // Allow abatort arrays of objects to be passes even if we can't determine anything about the result. -const abc = [a, b, c]; +const abc = [ a, b, c ] // $ExpectType object -deepmergeAll(abc); +deepmergeAll(abc) const d = { - bar: "abc", - quux: "def", + bar: `abc`, + quux: `def`, garply: 5, -} as const; +} as const // $ExpectType { bar: "abc"; quux: "def"; garply: 5; } -deepmerge(c, d); +deepmerge(c, d) // $ExpectType { bar: "abc"; quux: "def"; garply: 5; } -deepmergeAll([c, d]); +deepmergeAll([ c, d ]) -type E = { readonly foo: readonly number[] }; -type F = { readonly foo: readonly string[] }; +type E = { readonly foo: ReadonlyArray }; +type F = { readonly foo: ReadonlyArray }; const e = { - foo: [1, 2, 3], -} as const; + foo: [ 1, 2, 3 ], +} as const const f = { - foo: ["a", "b", "c"], -} as const; + foo: [ `a`, `b`, `c` ], +} as const // $ExpectType { foo: [1, 2, 3, "a", "b", "c"]; } -deepmerge(e, f); +deepmerge(e, f) // $ExpectType { foo: [1, 2, 3, "a", "b", "c"]; } -deepmergeAll([e, f]); +deepmergeAll([ e, f ]) // $ExpectType { foo: (string | number)[]; } -deepmerge(e as E, f as F); +deepmerge(e as E, f as F) // $ExpectType { foo: (string | number)[]; } -deepmergeAll([e as E, f as F]); +deepmergeAll([ e as E, f as F ]) const g = { - key1: "key1-val", + key1: `key1-val`, key2: { - key2key1: [false, "true"], + key2key1: [ false, `true` ], }, key3: { key3key1: { - key3key1key1: "key3key1key1-val", + key3key1key1: `key3key1key1-val`, key3key1key2: true, - key3key1key3: ["key3key1key3-val"], + key3key1key3: [ `key3key1key3-val` ], }, - key3key2: ["key3key2-val"], + key3key2: [ `key3key2-val` ], }, -}; +} const h = { - key1: ["key1-val"], + key1: [ `key1-val` ], key2: { key2key1: { - key2key1key1: () => "key2key1key1-val", + key2key1key1: () => `key2key1key1-val`, key2key1key2: true, - key2key1key3: ["key2key1key3-val"], + key2key1key3: [ `key2key1key3-val` ], }, }, key3: { key3key1: () => false, - key3key2: ["key3key2-val", true], + key3key2: [ `key3key2-val`, true ], }, -}; +} // $ExpectType { key1: string[]; key2: { key2key1: { key2key1key1: () => string; key2key1key2: boolean; key2key1key3: string[]; }; }; key3: { key3key1: { key3key1key1: string; key3key1key2: boolean; key3key1key3: string[]; }; key3key2: (string | boolean)[]; }; } -deepmerge(g, h); +deepmerge(g, h) // $ExpectType { key1: string[]; key2: { key2key1: { key2key1key1: () => string; key2key1key2: boolean; key2key1key3: string[]; }; }; key3: { key3key1: { key3key1key1: string; key3key1key2: boolean; key3key1key3: string[]; }; key3key2: (string | boolean)[]; }; } -deepmergeAll([g, h]); +deepmergeAll([ g, h ]) // $ExpectType { foo: string; baz: unknown; garply: number; grault: number; } deepmerge(a, b, { - isMergeable: (obj: object) => { - return false; - }, -}); + isMergeable: (obj: object) => false, +}) // $ExpectType { foo: string; baz: unknown; garply: number; grault: number; } -deepmergeAll([a, b], { - isMergeable: (obj: object) => { - return false; - }, -}); +deepmergeAll([ a, b ], { + isMergeable: (obj: object) => false, +}) const i = { baz: { - quuz: [5, 6], + quuz: [ 5, 6 ], }, -}; +} // $ExpectType { foo: string; baz: { quuz: number; }; garply: number; } deepmerge(a, i, { - arrayMerge: (target: unknown[], source: unknown[]) => + arrayMerge: (target: Array, source: Array) => target.length + source.length, -}); +}) // $ExpectType { foo: string; baz: { quuz: number; }; garply: number; } -deepmergeAll([a, i], { - arrayMerge: (target: unknown[], source: unknown[]) => +deepmergeAll([ a, i ], { + arrayMerge: (target: Array, source: Array) => target.length + source.length, -}); +}) // $ExpectType { foo: string; baz: string | { quuz: (string | number)[]; }; garply: number; } deepmerge(a, i, { customMerge: (key: string) => { - if (key === "bar") { - return (target: string, source: string) => target + source; + if (key === `bar`) { + return (target: string, source: string) => target + source } }, -}); +}) // $ExpectType { foo: string; baz: string | { quuz: (string | number)[]; }; garply: number; } -deepmergeAll([a, i], { +deepmergeAll([ a, i ], { customMerge: (key: string) => { - if (key === "bar") { - return (target: string, source: string) => target + source; + if (key === `bar`) { + return (target: string, source: string) => target + source } }, -}); +}) From 9b5505695b5d1a1e8685c239078c525615774361 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Nov 2020 13:11:23 +1300 Subject: [PATCH 27/36] fix: remove circular dependency between utils and deepmerge files --- src/deepmerge.ts | 66 ++------------------------ src/impl.ts | 117 +++++++++++++++++++++++++++++++++++++++++++++++ src/options.ts | 2 +- src/utils.ts | 55 ---------------------- 4 files changed, 121 insertions(+), 119 deletions(-) create mode 100644 src/impl.ts delete mode 100644 src/utils.ts diff --git a/src/deepmerge.ts b/src/deepmerge.ts index 36bfd88..e25ed3d 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -1,67 +1,7 @@ -import type { ExplicitOptions, FullOptions, Options } from "./options" +import { deepmergeImpl } from "./impl" +import type { ExplicitOptions, Options } from "./options" import { getFullOptions } from "./options" -import type { DeepMerge, DeepMergeAll, DeepMergeObjects, Property } from "./types" -import { - cloneUnlessOtherwiseSpecified, - getKeys, - getMergeFunction, - propertyIsOnObject, - propertyIsUnsafe, -} from "./utils" - -function mergeObject< - T1 extends Record, - T2 extends Record, - O extends Options ->(target: T1, source: T2, options: FullOptions): DeepMergeObjects { - const destination: any = {} - - if (options.isMergeable(target)) { - getKeys(target).forEach((key) => { - destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) - }) - } - - getKeys(source).forEach((key) => { - if (propertyIsUnsafe(target, key)) { - return - } - - if (!options.isMergeable(source[key]) || !propertyIsOnObject(target, key)) { - destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) - } else { - destination[key] = getMergeFunction(key, options)(target[key], source[key], options) - } - }) - - return destination -} - -export function deepmergeImpl( - target: T1, - source: T2, - options: FullOptions, -): DeepMerge> { - const sourceIsArray = Array.isArray(source) - const targetIsArray = Array.isArray(target) - const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray - - if (!sourceAndTargetTypesMatch) { - return cloneUnlessOtherwiseSpecified(source, options) as DeepMerge> - } else if (sourceIsArray) { - return options.arrayMerge( - target as Array, - source as Array, - options, - ) as DeepMerge> - } else { - return mergeObject( - target as Record, - source as Record, - options, - ) as DeepMerge> - } -} +import type { DeepMerge, DeepMergeAll } from "./types" /** * Deeply merge two objects. diff --git a/src/impl.ts b/src/impl.ts new file mode 100644 index 0000000..c4829be --- /dev/null +++ b/src/impl.ts @@ -0,0 +1,117 @@ +import type { ExplicitOptions, FullOptions, ObjectMerge, Options } from "./options" +import type { DeepMerge, DeepMergeObjects, Property } from "./types" + +function emptyTarget(value: unknown) { + return Array.isArray(value) ? [] : {} +} + +export function cloneUnlessOtherwiseSpecified(value: T, options: FullOptions): T { + return options.clone !== false && options.isMergeable(value) + ? (deepmergeImpl(emptyTarget(value), value, options) as T) + : value +} + +function getEnumerableOwnPropertySymbols(target: object) { + return Object.getOwnPropertySymbols + ? Object.getOwnPropertySymbols(target).filter((symbol) => + Object.prototype.propertyIsEnumerable.call(target, symbol), + ) + : [] +} + +function getKeys(target: object): Array { + // Symbols cannot be used to index objects yet. + // So cast to an array of strings for simplicity. + // @see https://github.com/microsoft/TypeScript/issues/1863 + // TODO: Remove cast once symbols indexing of objects is supported. + return [ ...Object.keys(target), ...getEnumerableOwnPropertySymbols(target) ] as Array +} + +function propertyIsOnObject(object: object, property: Property): boolean { + try { + return property in object + } catch (_) { + return false + } +} + +function getMergeFunction( + key: Property, + options: FullOptions, +): NonNullable> { + if (!options.customMerge) { + return deepmergeImpl + } + const customMerge = options.customMerge(key) + return typeof customMerge === `function` ? customMerge : deepmergeImpl +} + +/** + * Protects from prototype poisoning and unexpected merging up the prototype chain. + */ +export function propertyIsUnsafe(target: object, key: Property): boolean { + return ( + // Properties are safe to merge if they don't exist in the target yet, + propertyIsOnObject(target, key) + // unsafe if they exist up the prototype chain, + && !( + Object.hasOwnProperty.call(target, key) + // and also unsafe if they're nonenumerable. + && Object.propertyIsEnumerable.call(target, key) + ) + ) +} + +function mergeObject< + T1 extends Record, + T2 extends Record, + O extends Options +>(target: T1, source: T2, options: FullOptions): DeepMergeObjects { + const destination: any = {} + + if (options.isMergeable(target)) { + getKeys(target).forEach((key) => { + destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) + }) + } + + getKeys(source).forEach((key) => { + if (propertyIsUnsafe(target, key)) { + return + } + + if (!options.isMergeable(source[key]) || !propertyIsOnObject(target, key)) { + destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) + } else { + destination[key] = getMergeFunction(key, options)(target[key], source[key], options) + } + }) + + return destination +} + +export function deepmergeImpl( + target: T1, + source: T2, + options: FullOptions, +): DeepMerge> { + const sourceIsArray = Array.isArray(source) + const targetIsArray = Array.isArray(target) + const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray + + if (!sourceAndTargetTypesMatch) { + return cloneUnlessOtherwiseSpecified(source, options) as DeepMerge> + } else if (sourceIsArray) { + return options.arrayMerge( + target as Array, + source as Array, + options, + ) as DeepMerge> + } else { + return mergeObject( + target as Record, + source as Record, + options, + ) as DeepMerge> + } +} diff --git a/src/options.ts b/src/options.ts index ae62860..318ae94 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,7 +1,7 @@ import isPlainObj from "is-plain-obj" +import { cloneUnlessOtherwiseSpecified } from "./impl" import type { Property } from "./types" -import { cloneUnlessOtherwiseSpecified } from "./utils" /** * Deep merge options. diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index 51b90b6..0000000 --- a/src/utils.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { deepmergeImpl } from "./deepmerge" -import type { FullOptions, ObjectMerge } from "./options" -import type { Property } from "./types" - -function emptyTarget(value: unknown) { - return Array.isArray(value) ? [] : {} -} - -export function cloneUnlessOtherwiseSpecified(value: T, options: FullOptions): T { - return options.clone !== false && options.isMergeable(value) - ? (deepmergeImpl(emptyTarget(value), value, options) as T) - : value -} - -function getEnumerableOwnPropertySymbols(target: object) { - return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter((symbol) => - Object.prototype.propertyIsEnumerable.call(target, symbol), - ) - : [] -} - -export function getKeys(target: object): Array { - // Symbols cannot be used to index objects yet. - // So cast to an array of strings for simplicity. - // @see https://github.com/microsoft/TypeScript/issues/1863 - // TODO: Remove cast once symbols indexing of objects is supported. - return [ ...Object.keys(target), ...getEnumerableOwnPropertySymbols(target) ] as Array -} - -export function propertyIsOnObject(object: object, property: Property): boolean { - try { - return property in object - } catch (_) { - return false - } -} - -export function getMergeFunction( - key: Property, - options: FullOptions, -): NonNullable> { - if (!options.customMerge) { - return deepmergeImpl - } - const customMerge = options.customMerge(key) - return typeof customMerge === `function` ? customMerge : deepmergeImpl -} - -// Protects from prototype poisoning and unexpected merging up the prototype chain. -export function propertyIsUnsafe(target: object, key: Property): boolean { - return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, - && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, - && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. -} From 34fab736a181065c765d41679faf052136c9d804 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 17 Nov 2020 13:14:16 +1300 Subject: [PATCH 28/36] ci: update ci config --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8184ad6..a72c377 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,12 @@ language: node_js +cache: + directories: + - node_modules node_js: + - "node" + - "lts/*" - "12" - "10" - - "8" +script: + - npm run lint + - npm test From 03bd8a9abbb7ece1104864e41a50bd7dc56a4b5d Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Nov 2020 10:11:15 +1300 Subject: [PATCH 29/36] ci: switch to using GitHub Actions Travis has been running really slow lately --- .github/workflows/ci.yml | 49 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 12 ---------- 2 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..688440b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +name: CI + +on: + - push + - pull_request + +jobs: + lint: + name: Linting Checks + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup NodeJs + uses: actions/setup-node@v1 + with: + node-version: "14" + + - name: Install Dependencies + run: npm ci + + - name: Run Linting Checks + run: npm run lint + test: + strategy: + fail-fast: true + matrix: + os: + - ubuntu-latest + node_version: + - "14" + - "12" + name: Test with Node ${{ matrix.node_version }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup NodeJs + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node_version }} + + - name: Install Dependencies + run: npm ci + + - name: Run Tests + run: npm run test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a72c377..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: node_js -cache: - directories: - - node_modules -node_js: - - "node" - - "lts/*" - - "12" - - "10" -script: - - npm run lint - - npm test From fbf00cc9af82d95c1de3368ff892d3c0ff4a4592 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 17 Nov 2020 15:01:22 +1300 Subject: [PATCH 30/36] docs: update readme with new js interface --- readme.md | 68 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/readme.md b/readme.md index 5d4268b..26a5f14 100644 --- a/readme.md +++ b/readme.md @@ -2,13 +2,14 @@ Merges the enumerable properties of two or more objects deeply. -> UMD bundle is 716B minified+gzipped +> UMD bundle is 792B minified+gzipped ## Getting Started ### Example Usage + ```js @@ -48,10 +49,9 @@ const output = { quux: 5 } -merge(x, y) // => output +deepmerge(x, y) // => output ``` - ### Installation With [npm](http://npmjs.org) do: @@ -62,21 +62,25 @@ npm install deepmerge deepmerge can be used directly in the browser without the use of package managers/bundlers as well: [UMD version from unpkg.com](https://unpkg.com/deepmerge/dist/umd.js). - ### Include deepmerge exposes a CommonJS entry point: +```node +const { default: deepmerge, deepmergeAll } = require('deepmerge') ``` -const merge = require('deepmerge') -``` -The ESM entry point was dropped due to a [Webpack bug](https://github.com/webpack/webpack/issues/6584). +and a ESM entry point: + +```mjs +import deepmerge, { deepmergeAll } from 'deepmerge' +``` -# API +Note: The ESM entry point is not avaliable via the "module" field package.json due to a [Webpack bug](https://github.com/webpack/webpack/issues/6584). +## API -## `merge(x, y, [options])` +### `deepmerge(x, y, [options])` Merge two objects `x` and `y` deeply, returning a new merged object with the elements from both `x` and `y`. @@ -88,7 +92,7 @@ Merging creates a new object, so that neither `x` or `y` is modified. **Note:** By default, arrays are merged by concatenating them. -## `merge.all(arrayOfObjects, [options])` +### `deepmergeAll(arrayOfObjects, [options])` Merges any number of objects into a single result object. @@ -97,13 +101,12 @@ const foobar = { foo: { bar: 3 } } const foobaz = { foo: { baz: 4 } } const bar = { bar: 'yay!' } -merge.all([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' } +deepmergeAll([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' } ``` +### Options -## Options - -### `arrayMerge` +#### `arrayMerge` There are multiple ways to merge two arrays, below are a few examples but you can also create your own custom function. @@ -112,21 +115,21 @@ Your `arrayMerge` function will be called with three arguments: a `target` array - `isMergeableObject(value)` - `cloneUnlessOtherwiseSpecified(value, options)` -#### `arrayMerge` example: overwrite target array +##### `arrayMerge` example: overwrite target array Overwrites the existing array values completely rather than concatenating them: ```js const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray -merge( +deepmerge( [1, 2, 3], [3, 2, 1], { arrayMerge: overwriteMerge } ) // => [3, 2, 1] ``` -#### `arrayMerge` example: combine arrays +##### `arrayMerge` example: combine arrays Combines objects at the same index in the two arrays. @@ -140,7 +143,7 @@ const combineMerge = (target, source, options) => { if (typeof destination[index] === 'undefined') { destination[index] = options.cloneUnlessOtherwiseSpecified(item, options) } else if (options.isMergeable(item)) { - destination[index] = merge(target[index], item, options) + destination[index] = deepmerge(target[index], item, options) } else if (target.indexOf(item) === -1) { destination.push(item) } @@ -148,14 +151,14 @@ const combineMerge = (target, source, options) => { return destination } -merge( +deepmerge( [{ a: true }], [{ b: true }, 'ah yup'], { arrayMerge: combineMerge } ) // => [{ a: true, b: true }, 'ah yup'] ``` -### `isMergeable` +#### `isMergeable` By default, deepmerge clones properties of plain objects, and passes-by-reference all "special" kinds of instantiated objects. @@ -172,8 +175,10 @@ function mergeEverything(value) { return value !== null && typeof value === 'object' } -function SuperSpecial() { - this.special = 'oh yeah man totally' +class SuperSpecial { + constructor() { + this.special = 'oh yeah man totally' + } } const instantiatedSpecialObject = new SuperSpecial() @@ -188,13 +193,13 @@ const source = { someProperty: instantiatedSpecialObject } -const defaultOutput = merge(target, source) +const defaultOutput = deepmerge(target, source) defaultOutput.someProperty.cool // => undefined defaultOutput.someProperty.special // => 'oh yeah man totally' defaultOutput.someProperty instanceof SuperSpecial // => true -const customMergeOutput = merge(target, source, { +const customMergeOutput = deepmerge(target, source, { isMergeable: mergeEverything }) @@ -203,7 +208,7 @@ customMergeOutput.someProperty.special // => 'oh yeah man totally' customMergeOutput.someProperty instanceof SuperSpecial // => false ``` -### `customMerge` +#### `customMerge` Specifies a function which can be used to override the default merge behavior for a property, based on the property name. @@ -238,14 +243,13 @@ const options = { } } -const result = merge(alex, tony, options) +const result = deepmerge(alex, tony, options) result.name // => 'Alex and Tony' result.pets // => ['Cat', 'Parrot', 'Dog'] ``` - -### `clone` +#### `clone` *Deprecated.* @@ -253,8 +257,7 @@ Defaults to `true`. If `clone` is `false` then child objects will be copied directly instead of being cloned. This was the default behavior before version 2.x. - -# Testing +## Testing With [npm](http://npmjs.org) do: @@ -262,7 +265,6 @@ With [npm](http://npmjs.org) do: npm test ``` - -# License +## License MIT From 13d6db1070da122cfc41eef04c23077a1e50f63c Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Nov 2020 11:08:33 +1300 Subject: [PATCH 31/36] test: ensure options aren't mutated re #173 --- test/merge.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/merge.js b/test/merge.js index 92f381f..397937c 100644 --- a/test/merge.js +++ b/test/merge.js @@ -671,3 +671,12 @@ test(`Falsey properties should be mergeable`, (t) => { t.ok(customMergeWasCalled, `custom merge function was called`) t.end() }) + +test(`should not mutate options`, (t) => { + const options = {} + + merge({}, {}, options) + + t.deepEqual(options, {}) + t.end() +}) From ded6c510f2a343e69aedf6ae7bf88af97ee81c15 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Nov 2020 15:03:18 +1300 Subject: [PATCH 32/36] test: convert test to typescript and fixup errors this revealed --- package-lock.json | 98 +++++++++++++- package.json | 8 +- src/options.ts | 8 +- src/types.ts | 4 +- ...m-array-merge.js => custom-array-merge.ts} | 23 ++-- ...bject.js => custom-is-mergeable-object.ts} | 19 ++- test/{merge-all.js => merge-all.ts} | 24 ++-- ...lain-objects.js => merge-plain-objects.ts} | 8 +- test/{merge.js => merge.ts} | 123 +++++++++--------- ...pe-poisoning.js => prototype-poisoning.ts} | 28 ++-- test/types/test.ts | 2 +- tsconfig.test.json | 18 +++ 12 files changed, 233 insertions(+), 130 deletions(-) rename test/{custom-array-merge.js => custom-array-merge.ts} (63%) rename test/{custom-is-mergeable-object.js => custom-is-mergeable-object.ts} (62%) rename test/{merge-all.js => merge-all.ts} (68%) rename test/{merge-plain-objects.js => merge-plain-objects.ts} (82%) rename test/{merge.js => merge.ts} (78%) rename test/{prototype-poisoning.js => prototype-poisoning.ts} (72%) create mode 100644 tsconfig.test.json diff --git a/package-lock.json b/package-lock.json index 114b1db..6f16f83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -283,6 +283,12 @@ "integrity": "sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==", "dev": true }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", + "dev": true + }, "@types/node": { "version": "8.10.54", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.54.tgz", @@ -295,6 +301,15 @@ "integrity": "sha512-M56NfQHfaWuaj6daSgCVs7jh8fXLI3LmxjRoQxmOvYesgIkI+9HPsDLO0vd7wX7cwA0D0ZWFEJdp0VPwLdS+bQ==", "dev": true }, + "@types/tape": { + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/@types/tape/-/tape-4.13.0.tgz", + "integrity": "sha512-0V8cKowBdsiA9nbxAg7531sF2cdPZNiUogcfIUeUGm+bejUBE/bvibz3rH36iQP9bQjO/sOzFwU97/uC5mCyoA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@typescript-eslint/eslint-plugin": { "version": "4.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.8.0.tgz", @@ -487,6 +502,12 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1918,12 +1939,6 @@ "integrity": "sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw==", "dev": true }, - "is-mergeable-object": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-mergeable-object/-/is-mergeable-object-1.1.0.tgz", - "integrity": "sha512-JfyDDwUdtS4yHCgUpxOyKB9dnfZ0gecufxB0eytX6BmSXSE+8dbxDGt+V7CNRIRJ9sYFV/WQt2KJG6hNob2sBw==", - "dev": true - }, "is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", @@ -2129,6 +2144,15 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -2181,6 +2205,12 @@ "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", "dev": true }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", @@ -2809,8 +2839,17 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", "dev": true, - "optional": true + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } }, "sourcemap-codec": { "version": "1.4.6", @@ -2950,6 +2989,12 @@ "ansi-regex": "^2.0.0" } }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -3161,6 +3206,39 @@ "punycode": "^2.1.1" } }, + "ts-node": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz", + "integrity": "sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + }, + "dependencies": { + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + } + } + }, + "tsconfig-paths": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", + "integrity": "sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "json5": "^1.0.1", + "minimist": "^1.2.0", + "strip-bom": "^3.0.0" + } + }, "tslib": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz", @@ -3554,6 +3632,12 @@ "camelcase": "^5.0.0", "decamelize": "^1.2.0" } + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true } } } diff --git a/package.json b/package.json index 7b75bb7..4b43802 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,8 @@ "presize": "npm run build:js", "size": "terser --compress --mangle -- ./dist/index.umd.js | gzip -c | wc -c", "test": "npm run test:js && npm run test:types && npm run test:jsmd", - "pretest:js": "npm run build:js", - "test:js": "tape test/*.js", + "test:js": "ts-node -C typescript -P tsconfig.test.json -r tsconfig-paths/register node_modules/tape/bin/tape test/*.ts", + "pretest:jsmd": "npm run build:js", "test:jsmd": "jsmd readme.md", "pretest:types": "npm run build:types", "test:types": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types" @@ -72,17 +72,19 @@ "@rollup/plugin-node-resolve": "^10.0.0", "@rollup/plugin-typescript": "^6.1.0", "@types/node": "^8.10.54", + "@types/tape": "^4.13.0", "@typescript-eslint/eslint-plugin": "^4.8.0", "@typescript-eslint/parser": "^4.8.0", "dtslint": "^4.0.5", "eslint": "^7.13.0", - "is-mergeable-object": "1.1.0", "is-plain-obj": "^3.0.0", "jsmd": "^1.0.2", "rimraf": "^3.0.2", "rollup": "^2.33.1", "tape": "^5.0.1", "terser": "^5.3.8", + "ts-node": "^9.0.0", + "tsconfig-paths": "^3.9.0", "tslib": "^2.0.3", "typescript": "^4.1.2" }, diff --git a/src/options.ts b/src/options.ts index 318ae94..3a77b14 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,7 +1,7 @@ import isPlainObj from "is-plain-obj" import { cloneUnlessOtherwiseSpecified } from "./impl" -import type { Property } from "./types" +import type { FlattenAlias, Property } from "./types" /** * Deep merge options. @@ -23,7 +23,7 @@ export type ExplicitOptions = { /** * Deep merge options with defaults applied. */ -export type FullOptions = { +export type FullOptions = FlattenAlias<{ arrayMerge: O[`arrayMerge`] extends undefined ? typeof defaultArrayMerge : NonNullable @@ -33,7 +33,7 @@ export type FullOptions = { ? typeof defaultIsMergeable : NonNullable cloneUnlessOtherwiseSpecified: (value: T, options: FullOptions) => T -} +}> /** * A function that determins if a type is mergable. @@ -85,5 +85,5 @@ export function getFullOptions(options?: O): FullOptions { clone: true, ...overrides, cloneUnlessOtherwiseSpecified, - } as FullOptions + } as unknown as FullOptions } diff --git a/src/types.ts b/src/types.ts index f298a09..3775307 100644 --- a/src/types.ts +++ b/src/types.ts @@ -35,7 +35,7 @@ type DeepMergeValues = And, IsArray> /** * Deep merge 2 non-array objects. */ -export type DeepMergeObjects = FlatternAlias< +export type DeepMergeObjects = FlattenAlias< // @see https://github.com/microsoft/TypeScript/issues/41448 { -readonly [K in keyof T1]: DeepMergeObjectProps, ValueOfKey, O> @@ -118,7 +118,7 @@ type MaybeLeaf = Or< * single object. */ // eslint-disable-next-line @typescript-eslint/ban-types -type FlatternAlias = {} & { [P in keyof T]: T[P] } +export type FlattenAlias = {} & { [P in keyof T]: T[P] } /** * Get the value of the given key in the given object. diff --git a/test/custom-array-merge.js b/test/custom-array-merge.ts similarity index 63% rename from test/custom-array-merge.js rename to test/custom-array-merge.ts index 86c7299..35cc854 100644 --- a/test/custom-array-merge.js +++ b/test/custom-array-merge.ts @@ -1,9 +1,10 @@ -const merge = require(`../`).default -const test = require(`tape`) +import type { Options } from "deepmerge" +import deepmerge from "deepmerge" +import test from "tape" test(`custom merge array`, (t) => { let mergeFunctionCalled = false - function overwriteMerge(target, source, options) { + const overwriteMerge: Options[`arrayMerge`] = (target, source, options) => { mergeFunctionCalled = true t.equal(options.arrayMerge, overwriteMerge) @@ -17,7 +18,7 @@ test(`custom merge array`, (t) => { someArray: [ 1, 2, 3 ], } - const actual = merge(destination, source, { arrayMerge: overwriteMerge }) + const actual = deepmerge(destination, source, { arrayMerge: overwriteMerge }) const expected = { someArray: [ 1, 2, 3 ], someObject: { what: `yes` }, @@ -29,10 +30,8 @@ test(`custom merge array`, (t) => { }) test(`merge top-level arrays`, (t) => { - function overwriteMerge(a, b) { - return b - } - const actual = merge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) + const overwriteMerge: Options[`arrayMerge`] = (a, b) => b + const actual = deepmerge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) const expected = [ 1, 2 ] t.deepEqual(actual, expected) @@ -41,7 +40,7 @@ test(`merge top-level arrays`, (t) => { test(`cloner function is available for merge functions to use`, (t) => { let customMergeWasCalled = false - function cloneMerge(target, source, options) { + const cloneMerge: Options[`arrayMerge`] = (target, source, options) => { customMergeWasCalled = true t.ok(options.cloneUnlessOtherwiseSpecified, `cloner function is available`) return target.concat(source).map((element) => options.cloneUnlessOtherwiseSpecified(element, options)) @@ -60,9 +59,9 @@ test(`cloner function is available for merge functions to use`, (t) => { key2: [ `four` ], } - t.deepEqual(merge(target, src, { arrayMerge: cloneMerge }), expected) + t.deepEqual(deepmerge(target, src, { arrayMerge: cloneMerge }), expected) t.ok(customMergeWasCalled) - t.ok(Array.isArray(merge(target, src).key1)) - t.ok(Array.isArray(merge(target, src).key2)) + t.ok(Array.isArray(deepmerge(target, src).key1)) + t.ok(Array.isArray(deepmerge(target, src).key2)) t.end() }) diff --git a/test/custom-is-mergeable-object.js b/test/custom-is-mergeable-object.ts similarity index 62% rename from test/custom-is-mergeable-object.js rename to test/custom-is-mergeable-object.ts index 5025e61..e3b4de4 100644 --- a/test/custom-is-mergeable-object.js +++ b/test/custom-is-mergeable-object.ts @@ -1,15 +1,15 @@ -const merge = require(`../`).default -const test = require(`tape`) +import type { Options } from "deepmerge" +import deepmerge from "deepmerge" +import test from "tape" test(`isMergeable function copying object over object`, (t) => { const src = { key: { isMergeable: false }, baz: `yes` } const target = { key: { foo: `wat` }, baz: `whatever` } - function customIsMergeable(object) { - return object && typeof value === `object` && object.isMergeable !== false - } + const customIsMergeable: Options[`isMergeable`] = (object) => + object && typeof object === `object` && object.isMergeable !== false - const res = merge(target, src, { + const res = deepmerge(target, src, { isMergeable: customIsMergeable, }) @@ -22,11 +22,10 @@ test(`isMergeable function copying object over nothing`, (t) => { const src = { key: { isMergeable: false, foo: `bar` }, baz: `yes` } const target = { baz: `whatever` } - function customIsMergeable(object) { - return object && typeof value === `object` && object.isMergeable !== false - } + const customIsMergeable: Options[`isMergeable`] = (object) => + object && typeof object === `object` && object.isMergeable !== false - const res = merge(target, src, { + const res = deepmerge(target, src, { isMergeable: customIsMergeable, }) diff --git a/test/merge-all.js b/test/merge-all.ts similarity index 68% rename from test/merge-all.js rename to test/merge-all.ts index 9108874..5f7b004 100644 --- a/test/merge-all.js +++ b/test/merge-all.ts @@ -1,18 +1,20 @@ -const mergeAll = require(`../`).deepmergeAll -const test = require(`tape`) +import { deepmergeAll } from "deepmerge" +import test from "tape" test(`throw error if first argument is not an array`, (t) => { - t.throws(mergeAll.bind(null, { example: true }, { another: `2` }), Error) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error -- FIXME: Can't use @ts-expect-error due to it failing in tests. + // @ts-ignore Expect a type error when calling the function incorrectly. + t.throws(deepmergeAll.bind(null, { example: true }, { another: `2` }), Error) t.end() }) test(`return an empty object if first argument is an array with no elements`, (t) => { - t.deepEqual(mergeAll([]), {}) + t.deepEqual(deepmergeAll([]), {}) t.end() }) test(`Work just fine if first argument is an array with least than two elements`, (t) => { - const actual = mergeAll([{ example: true }]) + const actual = deepmergeAll([{ example: true }]) const expected = { example: true } t.deepEqual(actual, expected) t.end() @@ -20,13 +22,13 @@ test(`Work just fine if first argument is an array with least than two elements` test(`execute correctly if options object were not passed`, (t) => { const arrayToMerge = [{ example: true }, { another: `123` }] - t.doesNotThrow(mergeAll.bind(null, arrayToMerge)) + t.doesNotThrow(deepmergeAll.bind(null, arrayToMerge)) t.end() }) test(`execute correctly if options object were passed`, (t) => { const arrayToMerge = [{ example: true }, { another: `123` }] - t.doesNotThrow(mergeAll.bind(null, arrayToMerge, { clone: true })) + t.doesNotThrow(deepmergeAll.bind(null, arrayToMerge, { clone: true })) t.end() }) @@ -36,7 +38,7 @@ test(`invoke merge on every item in array should result with all props`, (t) => const thirdObject = { third: 123 } const fourthObject = { fourth: `some string` } - const mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) + const mergedObject = deepmergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) t.ok(mergedObject.first === true) t.ok(mergedObject.second === false) @@ -50,7 +52,7 @@ test(`invoke merge on every item in array with clone should clone all elements`, const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) + const mergedWithClone = deepmergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithClone.a, firstObject.a) t.notEqual(mergedWithClone.b, secondObject.b) @@ -64,7 +66,7 @@ test(`invoke merge on every item in array clone=false should not clone all eleme const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) + const mergedWithoutClone = deepmergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) t.equal(mergedWithoutClone.a, firstObject.a) t.equal(mergedWithoutClone.b, secondObject.b) @@ -79,7 +81,7 @@ test(`invoke merge on every item in array without clone should clone all element const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ]) + const mergedWithoutClone = deepmergeAll([ firstObject, secondObject, thirdObject ]) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge-plain-objects.js b/test/merge-plain-objects.ts similarity index 82% rename from test/merge-plain-objects.js rename to test/merge-plain-objects.ts index 29dcca3..91e59ba 100644 --- a/test/merge-plain-objects.js +++ b/test/merge-plain-objects.ts @@ -1,12 +1,12 @@ -const merge = require(`../`).default -const test = require(`tape`) +import deepmerge from "deepmerge" +import test from "tape" test(`plain objects are merged by default`, (t) => { const input = { newObject: new Object(), objectLiteral: { a: 123 }, } - const output = merge({}, input) + const output = deepmerge({}, input) t.deepEqual(output.newObject, input.newObject) t.notEqual(output.newObject, input.newObject) @@ -22,7 +22,7 @@ test(`instantiated objects are copied by reference`, (t) => { error: new Error(), regex: /regex/, } - const output = merge({}, input) + const output = deepmerge({}, input) t.equal(output.date, input.date) t.equal(output.error, input.error) diff --git a/test/merge.js b/test/merge.ts similarity index 78% rename from test/merge.js rename to test/merge.ts index 397937c..a29a11d 100644 --- a/test/merge.js +++ b/test/merge.ts @@ -1,11 +1,12 @@ -const merge = require(`../`).default -const test = require(`tape`) +import type { Options } from "deepmerge" +import deepmerge from "deepmerge" +import test from "tape" test(`add keys in target that do not exist at the root`, (t) => { const src = { key1: `value1`, key2: `value2` } const target = {} - const res = merge(target, src) + const res = deepmerge(target, src) t.deepEqual(target, {}, `merge should be immutable`) t.deepEqual(res, src) @@ -23,7 +24,7 @@ test(`merge existing simple keys in target at the roots`, (t) => { } t.deepEqual(target, { key1: `value1`, key3: `value3` }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -55,7 +56,7 @@ test(`merge nested objects into target`, (t) => { subkey2: `value2`, }, }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -80,7 +81,7 @@ test(`replace simple key with nested object in target`, (t) => { } t.deepEqual(target, { key1: `value1`, key2: `value2` }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -102,7 +103,7 @@ test(`should add nested object in target`, (t) => { }, } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -128,7 +129,7 @@ test(`should clone source and target`, (t) => { }, } - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.deepEqual(merged, expected) @@ -151,7 +152,7 @@ test(`should clone source and target`, (t) => { }, } - const merged = merge(target, src) + const merged = deepmerge(target, src) t.notEqual(merged.a, target.a) t.notEqual(merged.b, src.b) @@ -177,7 +178,7 @@ test(`should replace object with simple key in target`, (t) => { }, key2: `value2`, }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -188,7 +189,7 @@ test(`should replace objects with arrays`, (t) => { const expected = { key1: [ `subkey` ] } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -199,7 +200,7 @@ test(`should replace arrays with objects`, (t) => { const expected = { key1: { subkey: `one` } } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -210,7 +211,7 @@ test(`should replace dates with arrays`, (t) => { const expected = { key1: [ `subkey` ] } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -227,7 +228,7 @@ test(`should replace null with arrays`, (t) => { key1: [ `subkey` ], } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -237,8 +238,8 @@ test(`should work on simple array`, (t) => { const expected = [ `one`, `two`, `one`, `three` ] - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src))) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src))) t.end() }) @@ -248,8 +249,8 @@ test(`should work on another simple array`, (t) => { const expected = [ `a1`, `a2`, `c1`, `f1`, `p1`, `t1`, `s1`, `c2`, `r1`, `p2`, `p3` ] t.deepEqual(target, [ `a1`, `a2`, `c1`, `f1`, `p1` ]) - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src))) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src))) t.end() }) @@ -267,9 +268,9 @@ test(`should work on array properties`, (t) => { key2: [ `four` ], } - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src).key1)) - t.ok(Array.isArray(merge(target, src).key2)) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src).key1)) + t.ok(Array.isArray(deepmerge(target, src).key2)) t.end() }) @@ -285,7 +286,7 @@ test(`should work on array properties with clone option`, (t) => { t.deepEqual(target, { key1: [ `one`, `two` ], }) - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.notEqual(merged.key1, src.key1) t.notEqual(merged.key1, target.key1) t.notEqual(merged.key2, src.key2) @@ -309,9 +310,9 @@ test(`should work on array of objects`, (t) => { { key3: [ `five` ] }, ] - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src)), `result should be an array`) - t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src)), `result should be an array`) + t.ok(Array.isArray(deepmerge(target, src)[0].key1), `subkey should be an array too`) t.end() }) @@ -333,13 +334,12 @@ test(`should work on array of objects with clone option`, (t) => { { key3: [ `five` ] }, ] - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.deepEqual(merged, expected) - t.ok(Array.isArray(merge(target, src)), `result should be an array`) - t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) + t.ok(Array.isArray(deepmerge(target, src)), `result should be an array`) + t.ok(Array.isArray(deepmerge(target, src)[0].key1), `subkey should be an array too`) t.notEqual(merged[0].key1, src[0].key1) t.notEqual(merged[0].key1, target[0].key1) - t.notEqual(merged[0].key2, src[0].key2) t.notEqual(merged[1].key3, src[1].key3) t.notEqual(merged[1].key3, target[1].key3) t.end() @@ -350,8 +350,8 @@ test(`should treat regular expressions like primitive values`, (t) => { const src = { key1: /efg/ } const expected = { key1: /efg/ } - t.deepEqual(merge(target, src), expected) - t.deepEqual(merge(target, src).key1.test(`efg`), true) + t.deepEqual(deepmerge(target, src), expected) + t.deepEqual(deepmerge(target, src).key1.test(`efg`), true) t.end() }) @@ -360,7 +360,7 @@ test(`should treat regular expressions like primitive values and should not` const target = { key1: /abc/ } const src = { key1: /efg/ } - const output = merge(target, src, { clone: true }) + const output = deepmerge(target, src, { clone: true }) t.equal(output.key1, src.key1) t.end() @@ -381,7 +381,7 @@ test(`should treat dates like primitives`, (t) => { const expected = { key: tuesday, } - const actual = merge(target, source) + const actual = deepmerge(target, source) t.deepEqual(actual, expected) t.equal(actual.key.valueOf(), tuesday.valueOf()) @@ -400,29 +400,29 @@ test(`should treat dates like primitives and should not clone even with clone` key: tuesday, } - const actual = merge(target, source, { clone: true }) + const actual = deepmerge(target, source, { clone: true }) t.equal(actual.key, tuesday) t.end() }) test(`should work on array with null in it`, (t) => { - const target = [] + const target = [] as Array const src = [ null ] const expected = [ null ] - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) test(`should clone array's element if it is object`, (t) => { const a = { key: `yup` } - const target = [] + const target = [] as Array const source = [ a ] - const output = merge(target, source, { clone: true }) + const output = deepmerge(target, source, { clone: true }) t.notEqual(output[0], a) t.equal(output[0].key, `yup`) @@ -433,7 +433,7 @@ test(`should clone an array property when there is no target array`, (t) => { const someObject = {} const target = {} const source = { ary: [ someObject ] } - const output = merge(target, source, { clone: true }) + const output = deepmerge(target, source, { clone: true }) t.deepEqual(output, { ary: [{}] }) t.notEqual(output.ary[0], someObject) @@ -447,14 +447,14 @@ test(`should overwrite values when property is initialised but undefined`, (t) = const src = { value: undefined } - function hasUndefinedProperty(o) { + function hasUndefinedProperty(o: any) { t.ok(Object.prototype.hasOwnProperty.call(o, `value`)) t.equal(typeof o.value, `undefined`) } - hasUndefinedProperty(merge(target1, src)) - hasUndefinedProperty(merge(target2, src)) - hasUndefinedProperty(merge(target3, src)) + hasUndefinedProperty(deepmerge(target1, src)) + hasUndefinedProperty(deepmerge(target2, src)) + hasUndefinedProperty(deepmerge(target3, src)) t.end() }) @@ -467,7 +467,7 @@ test(`dates should copy correctly in an array`, (t) => { const source = [ tuesday, `lol` ] const expected = [ monday, `dude`, tuesday, `lol` ] - const actual = merge(target, source) + const actual = deepmerge(target, source) t.deepEqual(actual, expected) t.end() @@ -491,9 +491,9 @@ test(`should handle custom merge functions`, (t) => { }, } - const mergePeople = (target, source, options) => { + const mergePeople = (target: Record, source: Record) => { const keys = new Set(Object.keys(target).concat(Object.keys(source))) - const destination = {} + const destination: Record = {} keys.forEach((key) => { if (key in target && key in source) { destination[key] = `${ target[key] }-${ source[key] }` @@ -506,13 +506,13 @@ test(`should handle custom merge functions`, (t) => { return destination } - const options = { - customMerge: (key, options) => { + const options: Options = { + customMerge: (key) => { if (key === `people`) { return mergePeople } - return merge + return deepmerge }, } @@ -525,7 +525,7 @@ test(`should handle custom merge functions`, (t) => { }, } - const actual = merge(target, source, options) + const actual = deepmerge(target, source, options) t.deepEqual(actual, expected) t.end() }) @@ -549,11 +549,10 @@ test(`should handle custom merge functions`, (t) => { }, } - const mergeLetters = (target, source, options) => `merged letters` - + const mergeLetters = () => `merged letters` const options = { - customMerge: (key, options) => { + customMerge: (key: string) => { if (key === `letters`) { return mergeLetters } @@ -569,7 +568,7 @@ test(`should handle custom merge functions`, (t) => { }, } - const actual = merge(target, source, options) + const actual = deepmerge(target, source, options) t.deepEqual(actual, expected) t.end() }) @@ -592,8 +591,8 @@ test(`should merge correctly if custom merge is not a valid function`, (t) => { }, } - const options = { - customMerge: (key, options) => false, + const options: Options = { + customMerge: () => undefined, } const expected = { @@ -605,7 +604,7 @@ test(`should merge correctly if custom merge is not a valid function`, (t) => { }, } - const actual = merge(target, source, options) + const actual = deepmerge(target, source, options) t.deepEqual(actual, expected) t.end() }) @@ -615,7 +614,7 @@ test(`copy symbol keys in target that do not exist on the target`, (t) => { const src = { [mySymbol]: `value1` } const target = {} - const res = merge(target, src) + const res = deepmerge(target, src) t.equal(res[mySymbol], `value1`) t.deepEqual(Object.getOwnPropertySymbols(res), Object.getOwnPropertySymbols(src)) @@ -627,7 +626,7 @@ test(`copy symbol keys in target that do exist on the target`, (t) => { const src = { [mySymbol]: `value1` } const target = { [mySymbol]: `wat` } - const res = merge(target, src) + const res = deepmerge(target, src) t.equal(res[mySymbol], `value1`) t.end() @@ -636,7 +635,7 @@ test(`copy symbol keys in target that do exist on the target`, (t) => { test(`should not mutate options`, (t) => { const options = {} - merge({}, {}, options) + deepmerge({}, {}, options) t.deepEqual(options, {}) t.end() @@ -655,7 +654,7 @@ test(`Falsey properties should be mergeable`, (t) => { let customMergeWasCalled = false - const result = merge(target, source, { + const result = deepmerge(target, source, { isMergeable() { return true }, @@ -675,7 +674,7 @@ test(`Falsey properties should be mergeable`, (t) => { test(`should not mutate options`, (t) => { const options = {} - merge({}, {}, options) + deepmerge({}, {}, options) t.deepEqual(options, {}) t.end() diff --git a/test/prototype-poisoning.js b/test/prototype-poisoning.ts similarity index 72% rename from test/prototype-poisoning.js rename to test/prototype-poisoning.ts index 2a9d72d..444b940 100644 --- a/test/prototype-poisoning.js +++ b/test/prototype-poisoning.ts @@ -1,11 +1,12 @@ -const merge = require(`../`).default -const test = require(`tape`) -const isMergeableObject = require(`is-mergeable-object`) +import type { Options } from "deepmerge" +import deepmerge from "deepmerge" +import test from "tape" +import isPlainObj from 'is-plain-obj' test(`merging objects with own __proto__`, (t) => { const user = {} const malicious = JSON.parse(`{ "__proto__": { "admin": true } }`) - const mergedObject = merge(user, malicious) + const mergedObject = deepmerge(user, malicious) t.notOk(mergedObject.__proto__.admin, `non-plain properties should not be merged`) t.notOk(mergedObject.admin, `the destination should have an unmodified prototype`) t.end() @@ -28,7 +29,7 @@ test(`merging objects with plain and non-plain properties`, (t) => { [plainSymbolKey]: `qux`, } - const mergedObject = merge(target, source) + const mergedObject = deepmerge(target, source) t.equal(undefined, mergedObject.parentKey, `inherited properties of target should be removed, not merged or ignored`) t.equal(`bar`, mergedObject.plainKey, `enumerable own properties of target should be merged`) t.equal(`baz`, mergedObject.newKey, `properties not yet on target should be merged`) @@ -40,21 +41,20 @@ test(`merging objects with plain and non-plain properties`, (t) => { test(`merging strings works with a custom string merge`, (t) => { const target = { name: `Alexander` } const source = { name: `Hamilton` } - function customMerge(key, options) { + const customMerge: Options[`customMerge`] = (key) => { if (key === `name`) { - return function(target, source, options) { - return target[0] + `. ` + source.substring(0, 3) + return function(target: string, source: string, options) { + return `${ target[0] }. ${ source.substring(0, 3) }` } } else { - return merge + return deepmerge } } - function mergeable(target) { - return isMergeableObject(target) || (typeof target === `string` && target.length > 1) - } + const mergeable: Options[`isMergeable`] = (target) => + isPlainObj(target) || (typeof target === `string` && target.length > 1) - t.equal(`A. Ham`, merge(target, source, { customMerge, isMergeable: mergeable }).name) + t.equal(`A. Ham`, deepmerge(target, source, { customMerge, isMergeable: mergeable }).name) t.end() }) @@ -73,6 +73,6 @@ test(`merging objects with null prototype`, (t) => { }, } - t.deepEqual(expected, merge(target, source)) + t.deepEqual(expected, deepmerge(target, source)) t.end() }) diff --git a/test/types/test.ts b/test/types/test.ts index d104469..f020ae2 100644 --- a/test/types/test.ts +++ b/test/types/test.ts @@ -1,4 +1,4 @@ -import deepmerge, { deepmergeAll } from "../../src" +import deepmerge, { deepmergeAll } from "deepmerge" const a = { foo: `abc`, diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..9cb74ce --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,18 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "removeComments": false, + "noFallthroughCasesInSwitch": false, + "noImplicitAny": false, + "noImplicitReturns": false, + "noImplicitThis": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "strict": false, + "strictBindCallApply": false, + "strictFunctionTypes": false, + "strictNullChecks": false, + "strictPropertyInitialization": false + } +} From 1e02b16e68697681fbbf350d5f32a1757d138983 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Wed, 18 Nov 2020 12:35:17 +1300 Subject: [PATCH 33/36] docs: update changelog --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 652bbc7..35da49a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # [5.0.0](https://github.com/TehShrike/deepmerge/releases/tag/v5.0.0) +- Breaking: Endpoint are now exported in esm style [#215](https://github.com/TehShrike/deepmerge/pull/215) + - The main merge function is now a default export + - The all merge function is now exported as "deepmergeAll" and is no longer a property on the main merge function. +- Breaking: TypeScript types have been completely reworked [#215](https://github.com/TehShrike/deepmerge/pull/215) - Breaking for ES5 environments: `Object.assign` is now used to avoid mutating the `options` argument. [#167](https://github.com/TehShrike/deepmerge/pull/167) - Breaking: by default, only [plain objects](https://github.com/sindresorhus/is-plain-obj/#is-plain-obj-) will have their properties merged, with all other values being copied to the target. [#152](https://github.com/TehShrike/deepmerge/issues/152) - Breaking: the `isMergeableObject` option is renamed to `isMergeable` [#168](https://github.com/TehShrike/deepmerge/pull/168) From 6494a3398ec116d3af3427af8d3fda4c2a85c1c2 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 19 Nov 2020 13:43:18 +1300 Subject: [PATCH 34/36] build: set required node version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b43802..25287e2 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,6 @@ "typescript": "^4.1.2" }, "engines": { - "node": ">=0.10.0" + "node": ">=12" } } From 0c343f2ef216557fed674db18853a91d08e57d93 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 20 Nov 2020 13:02:54 +1300 Subject: [PATCH 35/36] fix: small tweaks to types and formatting --- src/deepmerge.ts | 4 ++-- src/impl.ts | 14 +++++++------- src/options.ts | 20 ++++++++++---------- src/types.ts | 5 +++-- test/merge-all.ts | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/deepmerge.ts b/src/deepmerge.ts index e25ed3d..6763c58 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -25,7 +25,7 @@ export default function deepmerge], + Ts extends readonly [object, ...ReadonlyArray], O extends Options = object >(objects: [...Ts], options?: O): DeepMergeAll> @@ -38,7 +38,7 @@ export function deepmergeAll< export function deepmergeAll(objects: ReadonlyArray, options?: Options): object export function deepmergeAll(objects: ReadonlyArray, options?: Options): object { if (!Array.isArray(objects)) { - throw new Error(`first argument should be an array`) + throw new TypeError(`first argument should be an array`) } return objects.reduce((prev, next) => deepmergeImpl(prev, next, getFullOptions(options)), {}) diff --git a/src/impl.ts b/src/impl.ts index c4829be..b043670 100644 --- a/src/impl.ts +++ b/src/impl.ts @@ -7,7 +7,7 @@ function emptyTarget(value: unknown) { export function cloneUnlessOtherwiseSpecified(value: T, options: FullOptions): T { return options.clone !== false && options.isMergeable(value) - ? (deepmergeImpl(emptyTarget(value), value, options) as T) + ? deepmergeImpl(emptyTarget(value), value, options) as T : value } @@ -30,7 +30,7 @@ function getKeys(target: object): Array { function propertyIsOnObject(object: object, property: Property): boolean { try { return property in object - } catch (_) { + } catch { return false } } @@ -101,17 +101,17 @@ export function deepmergeImpl if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options) as DeepMerge> - } else if (sourceIsArray) { + } + if (sourceIsArray) { return options.arrayMerge( target as Array, source as Array, options, ) as DeepMerge> - } else { - return mergeObject( + } + return mergeObject( target as Record, source as Record, options, - ) as DeepMerge> - } + ) as DeepMerge> } diff --git a/src/options.ts b/src/options.ts index 3a77b14..016f4c5 100644 --- a/src/options.ts +++ b/src/options.ts @@ -7,32 +7,32 @@ import type { FlattenAlias, Property } from "./types" * Deep merge options. */ export type Options = Partial<{ - arrayMerge?: ArrayMerge - clone?: boolean - customMerge?: ObjectMerge - isMergeable?: IsMergeable + readonly arrayMerge?: ArrayMerge + readonly clone?: boolean + readonly customMerge?: ObjectMerge + readonly isMergeable?: IsMergeable }> /** * Deep merge options with explicit keys. */ export type ExplicitOptions = { - [K in keyof Options]-?: undefined extends O[K] ? never : O[K] + readonly [K in keyof Options]-?: undefined extends O[K] ? never : O[K] } /** * Deep merge options with defaults applied. */ export type FullOptions = FlattenAlias<{ - arrayMerge: O[`arrayMerge`] extends undefined + readonly arrayMerge: O[`arrayMerge`] extends undefined ? typeof defaultArrayMerge : NonNullable - clone: O[`clone`] extends undefined ? true : NonNullable - customMerge?: O[`customMerge`] - isMergeable: O[`isMergeable`] extends undefined + readonly clone: O[`clone`] extends undefined ? true : NonNullable + readonly customMerge?: O[`customMerge`] + readonly isMergeable: O[`isMergeable`] extends undefined ? typeof defaultIsMergeable : NonNullable - cloneUnlessOtherwiseSpecified: (value: T, options: FullOptions) => T + readonly cloneUnlessOtherwiseSpecified: (value: T, options: FullOptions) => T }> /** diff --git a/src/types.ts b/src/types.ts index 3775307..ce9be99 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,9 +4,9 @@ import type { Options } from "./options" * Deep merge 1 or more types given in an array. */ export type DeepMergeAll< - Ts extends readonly [any, ...Array], + Ts extends readonly [any, ...ReadonlyArray], O extends Options -> = Ts extends readonly [infer T1, ...Array] +> = Ts extends readonly [infer T1, ...ReadonlyArray] ? Ts extends readonly [T1, infer T2, ...infer TRest] ? TRest extends ReadonlyArray ? DeepMerge @@ -81,6 +81,7 @@ type DeepMergeObjectPropsCustom = ReturnType< * * Cannot get return type from arrayMerge passing generics. * TypeScript does not yet support higher order types. + * * @see https://github.com/Microsoft/TypeScript/issues/1213 */ type DeepMergeArrays = IsUndefinedOrNever extends true diff --git a/test/merge-all.ts b/test/merge-all.ts index 5f7b004..b299ea1 100644 --- a/test/merge-all.ts +++ b/test/merge-all.ts @@ -4,7 +4,7 @@ import test from "tape" test(`throw error if first argument is not an array`, (t) => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error -- FIXME: Can't use @ts-expect-error due to it failing in tests. // @ts-ignore Expect a type error when calling the function incorrectly. - t.throws(deepmergeAll.bind(null, { example: true }, { another: `2` }), Error) + t.throws(deepmergeAll.bind(null, { example: true }, { another: `2` }), TypeError) t.end() }) From ced4b6dde428066d4280230901e1b032911e8a54 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Fri, 27 Nov 2020 15:15:32 +1300 Subject: [PATCH 36/36] refactor: extract out defaultClone --- src/options.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/options.ts b/src/options.ts index 016f4c5..f23c76e 100644 --- a/src/options.ts +++ b/src/options.ts @@ -27,7 +27,7 @@ export type FullOptions = FlattenAlias<{ readonly arrayMerge: O[`arrayMerge`] extends undefined ? typeof defaultArrayMerge : NonNullable - readonly clone: O[`clone`] extends undefined ? true : NonNullable + readonly clone: O[`clone`] extends undefined ? typeof defaultClone : NonNullable readonly customMerge?: O[`customMerge`] readonly isMergeable: O[`isMergeable`] extends undefined ? typeof defaultIsMergeable @@ -52,6 +52,8 @@ export type ObjectMerge = ( key: K ) => ((target: any, source: any, options: FullOptions) => any) | undefined +const defaultClone = true as const + function defaultIsMergeable(value: unknown): value is Record | Array { return Array.isArray(value) || isPlainObj(value) } @@ -82,7 +84,7 @@ export function getFullOptions(options?: O): FullOptions { return { arrayMerge: defaultArrayMerge, isMergeable: defaultIsMergeable, - clone: true, + clone: defaultClone, ...overrides, cloneUnlessOtherwiseSpecified, } as unknown as FullOptions