From 2f967c573629d1dbf7549c4b977325b1ad8d648e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0er=C3=BD?= Date: Tue, 11 Apr 2023 09:48:19 +0200 Subject: [PATCH] feature: ESM version exports `deepMerge` function `deepMerge` function used by the package for deep merging multiple objects is now exported. --- src/Collapsable.ts | 4 ++-- src/index.esm.ts | 5 ++--- src/index.ts | 4 +--- src/utils.ts | 6 +++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Collapsable.ts b/src/Collapsable.ts index a994cb3..6c22da0 100644 --- a/src/Collapsable.ts +++ b/src/Collapsable.ts @@ -1,5 +1,5 @@ import { CollapsableItem } from './CollapsableItem' -import { DeepPartial, mergeDeep } from './utils' +import { DeepPartial, deepMerge } from './utils' import { CollapsableExtLink } from './CollapsableExtLink' export type CollapsableOptions = { @@ -76,7 +76,7 @@ export class Collapsable { } public constructor(elements: HTMLElement | NodeListOf, options?: DeepPartial) { - this.options = mergeDeep({}, this.defaults, options) as CollapsableOptions + this.options = deepMerge({}, this.defaults, options) as CollapsableOptions this.promiseOpen = false if (elements instanceof NodeList) { diff --git a/src/index.esm.ts b/src/index.esm.ts index 536073a..840e239 100644 --- a/src/index.esm.ts +++ b/src/index.esm.ts @@ -1,3 +1,2 @@ -import { Collapsable } from './Collapsable' - -export default Collapsable +export { deepMerge } from './utils' +export { Collapsable as default } from './Collapsable' diff --git a/src/index.ts b/src/index.ts index 536073a..ab0d833 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1 @@ -import { Collapsable } from './Collapsable' - -export default Collapsable +export { Collapsable as default } from './Collapsable' diff --git a/src/utils.ts b/src/utils.ts index f5a7aea..eb8799d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,7 +6,7 @@ function isObject(item: unknown) { return item && typeof item === 'object' && !Array.isArray(item) } -export function mergeDeep(target: any, ...sources: any): Record { +export function deepMerge(target: any, ...sources: any): Record { if (!sources.length) return target const source = sources.shift() @@ -14,14 +14,14 @@ export function mergeDeep(target: any, ...sources: any): Record for (const key in source) { if (isObject(source[key])) { if (!target[key]) Object.assign(target, { [key]: {} }) - mergeDeep(target[key], source[key]) + deepMerge(target[key], source[key]) } else { Object.assign(target, { [key]: source[key] }) } } } - return mergeDeep(target, ...sources) + return deepMerge(target, ...sources) } // UID for CollapsableItem