Skip to content

Commit

Permalink
refactor!: rename DeepMergeMerge* to DeepMerge*
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed May 20, 2024
1 parent 0784f63 commit fd4d2d4
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 198 deletions.
24 changes: 12 additions & 12 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@ All these options are optional.

#### `mergeRecords`

Type: `false | (values: Record<any, unknown>[], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => unknown`
Type: `false | (values: Record<any, unknown>[], utils: DeepMergeFunctionUtils, meta: MetaData) => unknown`

If `false`, records won't be merged. If set to a function, that function will be used to merge records.

Note: Records are "vanilla" objects (e.g. `{ foo: "hello", bar: "world" }`).

#### `mergeArrays`

Type: `false | (values: unknown[][], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => unknown`
Type: `false | (values: unknown[][], utils: DeepMergeFunctionUtils, meta: MetaData) => unknown`

If `false`, arrays won't be merged. If set to a function, that function will be used to merge arrays.

#### `mergeMaps`

Type: `false | (values: Map<unknown, unknown>[], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => unknown`
Type: `false | (values: Map<unknown, unknown>[], utils: DeepMergeFunctionUtils, meta: MetaData) => unknown`

If `false`, maps won't be merged. If set to a function, that function will be used to merge maps.

#### `mergeSets`

Type: `false | (values: Set<unknown>[], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => unknown`
Type: `false | (values: Set<unknown>[], utils: DeepMergeFunctionUtils, meta: MetaData) => unknown`

If `false`, sets won't be merged. If set to a function, that function will be used to merge sets.

#### `mergeOthers`

Type: `(values: unknown[], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => unknown`
Type: `(values: unknown[], utils: DeepMergeFunctionUtils, meta: MetaData) => unknown`

If set to a function, that function will be used to merge everything else.

Expand All @@ -72,7 +72,7 @@ Type: `MetaData`

The given meta data value will be passed to root level merges.

### DeepMergeMergeFunctionUtils
### DeepMergeFunctionUtils

This is a set of utility functions that are made available to your custom merge functions.

Expand Down Expand Up @@ -115,7 +115,7 @@ All these options are optional.

#### `mergeRecords`

Type: `false | (target: DeepMergeValueReference<Record<PropertyKey, unknown>>, values: Record<any, unknown>[], utils: DeepMergeMergeFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->
Type: `false | (target: DeepMergeValueReference<Record<PropertyKey, unknown>>, values: Record<any, unknown>[], utils: DeepMergeFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->

If `false`, records won't be merged. If set to a function, that function will be used to merge records by mutating
`target.value`.
Expand All @@ -124,28 +124,28 @@ Note: Records are "vanilla" objects (e.g. `{ foo: "hello", bar: "world" }`).

#### `mergeArrays`

Type: `false | (target: DeepMergeValueReference<unknown[]>, values: unknown[][], utils: DeepMergeMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->
Type: `false | (target: DeepMergeValueReference<unknown[]>, values: unknown[][], utils: DeepMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->

If `false`, arrays won't be merged. If set to a function, that function will be used to merge arrays by mutating
`target.value`.

#### `mergeMaps`

Type: `false | (target: DeepMergeValueReference<Map<unknown, unknown>>, values: Map<unknown, unknown>[], utils: DeepMergeMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->
Type: `false | (target: DeepMergeValueReference<Map<unknown, unknown>>, values: Map<unknown, unknown>[], utils: DeepMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->

If `false`, maps won't be merged. If set to a function, that function will be used to merge maps by mutating
`target.value`.

#### `mergeSets`

Type: `false | (target: DeepMergeValueReference<Set<unknown>>, values: Set<unknown>[], utils: DeepMergeMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->
Type: `false | (target: DeepMergeValueReference<Set<unknown>>, values: Set<unknown>[], utils: DeepMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->

If `false`, sets won't be merged. If set to a function, that function will be used to merge sets by mutating
`target.value`.

#### `mergeOthers`

Type: `(target: DeepMergeValueReference<unknown>, values: unknown[], utils: DeepMergeMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->
Type: `(target: DeepMergeValueReference<unknown>, values: unknown[], utils: DeepMergeIntoFunctionUtils, meta: MetaData) => void | symbol` <!-- markdownlint-disable-line MD013 -->

If set to a function, that function will be used to merge everything else by mutating `target.value`.

Expand All @@ -164,7 +164,7 @@ Type: `MetaData`

The given meta data value will be passed to root level merges.

### DeepMergeMergeIntoFunctionUtils
### DeepMergeIntoFunctionUtils

This is a set of utility functions that are made available to your custom merge functions.

Expand Down
46 changes: 23 additions & 23 deletions docs/deepmergeCustom.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const y = { foo: [5, 6] };
customDeepmerge(x, y); // => { foo: [5, 6], bar: [3, 4] }
```

When resolving a HKT, we use a lookup inside an interface called `DeepMergeMergeFunctionURItoKind`.
When resolving a HKT, we use a lookup inside an interface called `DeepMergeFunctionURItoKind`.
This interface needs to contain all the mappings of the URIs to their actual type.

When defining your own HKT for use with deepmerge, you need to extend this interface with your mapping.
Expand All @@ -168,9 +168,9 @@ declaring a module block for this library and defining the same interface.

```ts
declare module "deepmerge-ts" {
interface DeepMergeMergeFunctionURItoKind<
interface DeepMergeFunctionURItoKind<
Ts extends ReadonlyArray<unknown>,
MF extends DeepMergeMergeFunctionsURIs,
MF extends DeepMergeFunctionsURIs,
M,
> {
readonly MyCustomMergeURI: MyValue;
Expand All @@ -184,9 +184,9 @@ Here's an example of creating a custom deepmerge function that amalgamates dates

```ts
import {
type DeepMergeFunctionURItoKind,
type DeepMergeFunctionsURIs,
type DeepMergeLeaf,
type DeepMergeMergeFunctionURItoKind,
type DeepMergeMergeFunctionsURIs,
deepmergeCustom,
} from "deepmerge-ts";

Expand All @@ -213,9 +213,9 @@ const z = { foo: new Date("2022-03-03") };
customDeepmerge(x, y, z); // => { foo: [Date, Date, Date] }

declare module "deepmerge-ts" {
interface DeepMergeMergeFunctionURItoKind<
interface DeepMergeFunctionURItoKind<
Ts extends ReadonlyArray<unknown>,
MF extends DeepMergeMergeFunctionsURIs,
MF extends DeepMergeFunctionsURIs,
M,
> {
readonly MyDeepMergeDatesURI: EveryIsDate<Ts> extends true
Expand Down Expand Up @@ -247,8 +247,8 @@ Be sure to also set the `DeepMergeFilterValuesURI` to `DeepMergeNoFilteringURI`

```ts
import {
type DeepMergeMergeFunctionURItoKind,
type DeepMergeMergeFunctionsURIs,
type DeepMergeFunctionURItoKind,
type DeepMergeFunctionsURIs,
type DeepMergeNoFilteringURI,
deepmergeCustom,
} from "deepmerge-ts";
Expand All @@ -275,8 +275,8 @@ Here's an example that creates a custom deepmerge function that filters out all

```ts
import {
type DeepMergeMergeFunctionURItoKind,
type DeepMergeMergeFunctionsURIs,
type DeepMergeFunctionURItoKind,
type DeepMergeFunctionsURIs,
type FilterOut,
deepmergeCustom,
} from "deepmerge-ts";
Expand All @@ -299,9 +299,9 @@ const z = { key1: { subkey2: `two` } };
customizedDeepmerge(x, y, z); // => { key1: { subkey1: `one`, subkey2: `two` } }

declare module "deepmerge-ts" {
interface DeepMergeMergeFunctionURItoKind<
interface DeepMergeFunctionURItoKind<
Ts extends Readonly<ReadonlyArray<unknown>>,
MF extends DeepMergeMergeFunctionsURIs,
MF extends DeepMergeFunctionsURIs,
M,
> {
readonly FilterNullValues: FilterOut<Ts, null>;
Expand All @@ -318,9 +318,9 @@ under.

```ts
import {
type DeepMergeFunctionURItoKind,
type DeepMergeFunctionsURIs,
type DeepMergeLeaf,
type DeepMergeMergeFunctionURItoKind,
type DeepMergeMergeFunctionsURIs,
deepmergeCustom,
} from "deepmerge-ts";

Expand Down Expand Up @@ -370,9 +370,9 @@ Here's an example that uses custom metadata that accumulates the full key path.

```ts
import {
type DeepMergeFunctionURItoKind,
type DeepMergeFunctionsURIs,
type DeepMergeLeaf,
type DeepMergeMergeFunctionURItoKind,
type DeepMergeMergeFunctionsURIs,
deepmergeCustom,
} from "deepmerge-ts";

Expand Down Expand Up @@ -431,9 +431,9 @@ const y = {
customizedDeepmerge(x, y); // => { foo: { bar: { baz: "special merge", bar: { baz: 6, qux: 7 }, qux: 2 } }, bar: { baz: "special merge", qux: 9 }, }

declare module "deepmerge-ts" {
interface DeepMergeMergeFunctionURItoKind<
interface DeepMergeFunctionURItoKind<
Ts extends Readonly<ReadonlyArray<unknown>>,
MF extends DeepMergeMergeFunctionsURIs,
MF extends DeepMergeFunctionsURIs,
M, // This is the meta data type
> {
readonly KeyPathBasedMerge: Ts[number] extends number
Expand Down Expand Up @@ -507,10 +507,10 @@ type CustomizedDeepmergeInto = <
DeepMergeHKT<
[Target, ...Ts], // Don't forget to pass the `Target` type here too.
{
DeepMergeRecordsURI: DeepMergeMergeFunctionsDefaultURIs["DeepMergeRecordsURI"]; // Use default behavior.
DeepMergeArraysURI: DeepMergeMergeFunctionsDefaultURIs["DeepMergeArraysURI"]; // Use default behavior.
DeepMergeSetsURI: DeepMergeMergeFunctionsDefaultURIs["DeepMergeSetsURI"]; // Use default behavior.
DeepMergeMapsURI: DeepMergeMergeFunctionsDefaultURIs["DeepMergeMapsURI"]; // Use default behavior.
DeepMergeRecordsURI: DeepMergeFunctionsDefaultURIs["DeepMergeRecordsURI"]; // Use default behavior.
DeepMergeArraysURI: DeepMergeFunctionsDefaultURIs["DeepMergeArraysURI"]; // Use default behavior.
DeepMergeSetsURI: DeepMergeFunctionsDefaultURIs["DeepMergeSetsURI"]; // Use default behavior.
DeepMergeMapsURI: DeepMergeFunctionsDefaultURIs["DeepMergeMapsURI"]; // Use default behavior.
DeepMergeOthersURI: "CustomDeepMergeOthersURI"; // Use custom behavior (see deepmergeCustom's docs above for details).
},
DeepMergeBuiltInMetaData // Use default meta data.
Expand Down
33 changes: 15 additions & 18 deletions src/deepmerge-into.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
import * as defaultMergeIntoFunctions from "./defaults/into";
import {
type DeepMergeBuiltInMetaData,
type DeepMergeFunctionsDefaultURIs,
type DeepMergeHKT,
type DeepMergeIntoFunctionUtils,
type DeepMergeIntoOptions,
type DeepMergeMergeFunctionsDefaultURIs,
type DeepMergeMergeIntoFunctionUtils,
type Reference,
} from "./types";
import { type SimplifyObject } from "./types/utils";
Expand Down Expand Up @@ -42,7 +42,7 @@ export function deepmergeInto<
Target &
DeepMergeHKT<
[Target, ...Ts],
DeepMergeMergeFunctionsDefaultURIs,
DeepMergeFunctionsDefaultURIs,
DeepMergeBuiltInMetaData
>
>;
Expand All @@ -57,7 +57,7 @@ export function deepmergeInto<
Target &
DeepMergeHKT<
[Target, ...Ts],
DeepMergeMergeFunctionsDefaultURIs,
DeepMergeFunctionsDefaultURIs,
DeepMergeBuiltInMetaData
>
> {
Expand Down Expand Up @@ -119,7 +119,7 @@ export function deepmergeIntoCustom<
...objects: Ts
) => void;

const utils: DeepMergeMergeIntoFunctionUtils<MetaData, MetaMetaData> =
const utils: DeepMergeIntoFunctionUtils<MetaData, MetaMetaData> =
getIntoUtils(options, customizedDeepmergeInto as CustomizedDeepmergeInto);

/**
Expand Down Expand Up @@ -150,11 +150,8 @@ function getIntoUtils<
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
options: DeepMergeIntoOptions<M, MM>,
customizedDeepmergeInto: DeepMergeMergeIntoFunctionUtils<
M,
MM
>["deepmergeInto"],
): DeepMergeMergeIntoFunctionUtils<M, MM> {
customizedDeepmergeInto: DeepMergeIntoFunctionUtils<M, MM>["deepmergeInto"],
): DeepMergeIntoFunctionUtils<M, MM> {
return {
defaultMergeFunctions: defaultMergeIntoFunctions,
mergeFunctions: {
Expand All @@ -170,9 +167,9 @@ function getIntoUtils<
: [key, option],
),
),
} as DeepMergeMergeIntoFunctionUtils<M, MM>["mergeFunctions"],
} as DeepMergeIntoFunctionUtils<M, MM>["mergeFunctions"],
metaDataUpdater: (options.metaDataUpdater ??
defaultMetaDataUpdater) as unknown as DeepMergeMergeIntoFunctionUtils<
defaultMetaDataUpdater) as unknown as DeepMergeIntoFunctionUtils<
M,
MM
>["metaDataUpdater"],
Expand All @@ -193,7 +190,7 @@ function getIntoUtils<
*/
export function mergeUnknownsInto<
Ts extends ReadonlyArray<unknown>,
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand Down Expand Up @@ -291,7 +288,7 @@ export function mergeUnknownsInto<
* @param values - The records.
*/
function mergeRecordsInto<
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand Down Expand Up @@ -324,7 +321,7 @@ function mergeRecordsInto<
* @param values - The arrays.
*/
function mergeArraysInto<
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand Down Expand Up @@ -352,7 +349,7 @@ function mergeArraysInto<
* @param values - The sets.
*/
function mergeSetsInto<
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand All @@ -375,7 +372,7 @@ function mergeSetsInto<
* @param values - The maps.
*/
function mergeMapsInto<
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand All @@ -398,7 +395,7 @@ function mergeMapsInto<
* @param values - The other things.
*/
function mergeOthersInto<
U extends DeepMergeMergeIntoFunctionUtils<M, MM>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData,
>(
Expand Down
Loading

0 comments on commit fd4d2d4

Please sign in to comment.