Content-Length: 536170 | pFad | http://github.com/TehShrike/deepmerge/pull/217/commits/ded6c510f2a343e69aedf6ae7bf88af97ee81c15

B9 Update deep merge interface (api) by RebeccaStevens · Pull Request #217 · TehShrike/deepmerge · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deep merge interface (api) #217

Draft
wants to merge 40 commits into
base: v5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ca08a6c
chore(editorconfig): declare the charset
Nov 11, 2020
09c3e67
chore(editorconfig): have package.json and its lockfile keep their de…
Nov 11, 2020
9e6c637
chore(editorconfig): have markdown files keep there trailing whitespace
Nov 11, 2020
21e5999
chore(editorconfig): use space instead of tabs for markdown files
Nov 11, 2020
dc8df6b
chore(editorconfig): use space instead of tabs for yaml files
Nov 17, 2020
29b862b
chore: use files field in package.json instead of .npmignore
Nov 11, 2020
c32dfd4
chore: sort package.json fields
Nov 11, 2020
b62e6e1
refactor: move src file to src/
Nov 12, 2020
48a6eaf
refactor: move typedefs to types/
Nov 12, 2020
e246c61
chore(devdeps): update rollup to v2.33.1
Nov 11, 2020
6f2930b
chore(devdeps): update is-plain-obj to v3.0.0
Nov 12, 2020
1a82cba
chore(devdeps): update tape to v5.0.1
Nov 12, 2020
a27988f
chore(devdeps): replace uglify-js with more modern terser
Nov 12, 2020
4e74235
build(typescript): add typescript and setup the build to build with t…
Nov 12, 2020
2fb71c2
refactor: move implementation out of index file
Nov 13, 2020
5646fd6
refactor: upgrade code
Nov 13, 2020
7b894d1
perf: only compute the full options on the top level call
Nov 13, 2020
6e5dcd3
refactor: move utility functions to a utils file
Nov 13, 2020
8373879
refactor: move options stuff to its own file
Nov 13, 2020
5676ca7
add typedefs from #211
Nov 13, 2020
776fc22
test: tests types
Nov 13, 2020
a2af763
chore: refactor npm script commands
Nov 13, 2020
0a2be40
build: update package exports
Nov 18, 2020
2246372
build: add type support for older TypeScript versions
Nov 15, 2020
8c562f5
build(lint): add eslint
Nov 16, 2020
e0b302f
style(lint): apply linting fixes
Nov 16, 2020
9b55056
fix: remove circular dependency between utils and deepmerge files
Nov 19, 2020
34fab73
ci: update ci config
Nov 17, 2020
03bd8a9
ci: switch to using GitHub Actions
Nov 18, 2020
fbf00cc
docs: update readme with new js interface
Nov 17, 2020
13d6db1
test: ensure options aren't mutated
Nov 17, 2020
ded6c51
test: convert test to typescript and fixup errors this revealed
Nov 18, 2020
1e02b16
docs: update changelog
Nov 17, 2020
6494a33
build: set required node version
Nov 19, 2020
0c343f2
fix: small tweaks to types and formatting
Nov 20, 2020
ced4b6d
refactor: extract out defaultClone
RebeccaStevens Nov 27, 2020
f450b1f
feat: don't clone by deafult
RebeccaStevens Nov 27, 2020
992e0af
feat: allow a custom clone function to be provided
RebeccaStevens Nov 27, 2020
d194991
feat: custom merge is now a single function
RebeccaStevens Nov 28, 2020
049dc4f
docs: update changelog
RebeccaStevens Nov 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: convert test to typescript and fixup errors this revealed
  • Loading branch information
Rebecca Stevens authored and RebeccaStevens committed Nov 27, 2020
commit ded6c510f2a343e69aedf6ae7bf88af97ee81c15
98 changes: 91 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,7 +23,7 @@ export type ExplicitOptions<O extends Options = Options> = {
/**
* Deep merge options with defaults applied.
*/
export type FullOptions<O extends Options = Options> = {
export type FullOptions<O extends Options = Options> = FlattenAlias<{
arrayMerge: O[`arrayMerge`] extends undefined
? typeof defaultArrayMerge
: NonNullable<O[`arrayMerge`]>
Expand All @@ -33,7 +33,7 @@ export type FullOptions<O extends Options = Options> = {
? typeof defaultIsMergeable
: NonNullable<O[`isMergeable`]>
cloneUnlessOtherwiseSpecified: <T>(value: T, options: FullOptions) => T
}
}>

/**
* A function that determins if a type is mergable.
Expand Down Expand Up @@ -85,5 +85,5 @@ export function getFullOptions<O extends Options>(options?: O): FullOptions<O> {
clone: true,
...overrides,
cloneUnlessOtherwiseSpecified,
} as FullOptions<O>
} as unknown as FullOptions<O>
}
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type DeepMergeValues<T1, T2, O extends Options> = And<IsArray<T1>, IsArray<T2>>
/**
* Deep merge 2 non-array objects.
*/
export type DeepMergeObjects<T1, T2, O extends Options> = FlatternAlias<
export type DeepMergeObjects<T1, T2, O extends Options> = FlattenAlias<
// @see https://github.com/microsoft/TypeScript/issues/41448
{
-readonly [K in keyof T1]: DeepMergeObjectProps<ValueOfKey<T1, K>, ValueOfKey<T2, K>, O>
Expand Down Expand Up @@ -118,7 +118,7 @@ type MaybeLeaf<T1, T2> = Or<
* single object.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
type FlatternAlias<T> = {} & { [P in keyof T]: T[P] }
export type FlattenAlias<T> = {} & { [P in keyof T]: T[P] }

/**
* Get the value of the given key in the given object.
Expand Down
23 changes: 11 additions & 12 deletions test/custom-array-merge.js → test/custom-array-merge.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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` },
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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()
})
Original file line number Diff line number Diff line change
@@ -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,
})

Expand All @@ -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,
})

Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/TehShrike/deepmerge/pull/217/commits/ded6c510f2a343e69aedf6ae7bf88af97ee81c15

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy