@adamhl8/configs 0.15.17 → 0.15.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mergeWith } from "es-toolkit";
2
- import { isPlainObject } from "remeda";
2
+ import { clone, isPlainObject } from "remeda";
3
3
  function merge(target, source) {
4
4
  return mergeWith(target, source, (objValue, srcValue) => Array.isArray(objValue) ? objValue.concat(srcValue) : void 0);
5
5
  }
@@ -7,7 +7,7 @@ function createMergeConfigFn(baseConfig) {
7
7
  function mergeConfig(userConfig) {
8
8
  if (userConfig === void 0) return baseConfig;
9
9
  if (!(isPlainObject(baseConfig) && isPlainObject(userConfig))) throw new Error(`target and/or source is not an object: target='${baseConfig}'\nsource='${userConfig}'`);
10
- return merge(baseConfig, userConfig);
10
+ return merge(clone(baseConfig), clone(userConfig));
11
11
  }
12
12
  return mergeConfig;
13
13
  }
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { mergeWith } from \"es-toolkit\"\nimport { isPlainObject } from \"remeda\"\nimport type { MergeDeep } from \"type-fest\"\n\ntype AnyObj = Record<PropertyKey, unknown>\n\n/**\n * A wrapper around es-toolkit's `mergeWith` with a custom merge function that concatenates arrays.\n */\nfunction merge<T extends AnyObj, S extends AnyObj>(target: T, source: S): T & S {\n return mergeWith(target, source, (objValue: unknown, srcValue: unknown) =>\n Array.isArray(objValue) ? objValue.concat(srcValue) : undefined,\n )\n}\n\ntype MergeDeepConcat<D, S> = MergeDeep<D, S, { arrayMergeMode: \"spread\" }>\n\nexport interface MergeConfigFn<UserConfigType, BaseConfig extends UserConfigType> {\n // if `userConfig` is not provided, return the type of `baseConfig`\n (): BaseConfig\n // if `userConfig` is provided, instead of returning `BaseConfig & UserConfig` (from `merge`), return a more friendly type using `MergeDeep`\n <UserConfig extends UserConfigType>(userConfig: UserConfig): MergeDeepConcat<BaseConfig, UserConfig>\n}\n\n/**\n * Creates a config merge function with proper type overloads for merging with a base config.\n */\nexport function createMergeConfigFn<UserConfigType, BaseConfig extends UserConfigType>(\n baseConfig: BaseConfig,\n): MergeConfigFn<UserConfigType, BaseConfig> {\n function mergeConfig(): BaseConfig\n\n function mergeConfig<UserConfig extends UserConfigType>(\n userConfig: UserConfig,\n ): MergeDeepConcat<BaseConfig, UserConfig>\n\n function mergeConfig<UserConfig extends UserConfigType>(userConfig?: UserConfig) {\n if (userConfig === undefined) return baseConfig\n\n if (!(isPlainObject(baseConfig) && isPlainObject(userConfig)))\n throw new Error(`target and/or source is not an object: target='${baseConfig}'\\nsource='${userConfig}'`)\n\n return merge(baseConfig, userConfig)\n }\n\n return mergeConfig\n}\n"],"mappings":";;AASA,SAAS,MAA0C,QAAW,QAAkB;AAC9E,QAAO,UAAU,QAAQ,SAAS,UAAmB,aACnD,MAAM,QAAQ,SAAS,GAAG,SAAS,OAAO,SAAS,GAAG,KAAA,EACvD;;AAeH,SAAgB,oBACd,YAC2C;CAO3C,SAAS,YAA+C,YAAyB;AAC/E,MAAI,eAAe,KAAA,EAAW,QAAO;AAErC,MAAI,EAAE,cAAc,WAAW,IAAI,cAAc,WAAW,EAC1D,OAAM,IAAI,MAAM,kDAAkD,WAAW,aAAa,WAAW,GAAG;AAE1G,SAAO,MAAM,YAAY,WAAW;;AAGtC,QAAO"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { mergeWith } from \"es-toolkit\"\nimport { clone, isPlainObject } from \"remeda\"\nimport type { MergeDeep } from \"type-fest\"\n\ntype AnyObj = Record<PropertyKey, unknown>\n\n/**\n * A wrapper around es-toolkit's `mergeWith` with a custom merge function that concatenates arrays.\n */\nfunction merge<T extends AnyObj, S extends AnyObj>(target: T, source: S): T & S {\n return mergeWith(target, source, (objValue: unknown, srcValue: unknown) =>\n Array.isArray(objValue) ? objValue.concat(srcValue) : undefined,\n )\n}\n\ntype MergeDeepConcat<D, S> = MergeDeep<D, S, { arrayMergeMode: \"spread\" }>\n\nexport interface MergeConfigFn<UserConfigType, BaseConfig extends UserConfigType> {\n // if `userConfig` is not provided, return the type of `baseConfig`\n (): BaseConfig\n // if `userConfig` is provided, instead of returning `BaseConfig & UserConfig` (from `merge`), return a more friendly type using `MergeDeep`\n <UserConfig extends UserConfigType>(userConfig: UserConfig): MergeDeepConcat<BaseConfig, UserConfig>\n}\n\n/**\n * Creates a config merge function with proper type overloads for merging with a base config.\n */\nexport function createMergeConfigFn<UserConfigType, BaseConfig extends UserConfigType>(\n baseConfig: BaseConfig,\n): MergeConfigFn<UserConfigType, BaseConfig> {\n function mergeConfig(): BaseConfig\n\n function mergeConfig<UserConfig extends UserConfigType>(\n userConfig: UserConfig,\n ): MergeDeepConcat<BaseConfig, UserConfig>\n\n function mergeConfig<UserConfig extends UserConfigType>(userConfig?: UserConfig) {\n if (userConfig === undefined) return baseConfig\n\n if (!(isPlainObject(baseConfig) && isPlainObject(userConfig)))\n throw new Error(`target and/or source is not an object: target='${baseConfig}'\\nsource='${userConfig}'`)\n\n // clone both target and source so we never mutate the original objects\n return merge(clone(baseConfig), clone(userConfig))\n }\n\n return mergeConfig\n}\n"],"mappings":";;AASA,SAAS,MAA0C,QAAW,QAAkB;AAC9E,QAAO,UAAU,QAAQ,SAAS,UAAmB,aACnD,MAAM,QAAQ,SAAS,GAAG,SAAS,OAAO,SAAS,GAAG,KAAA,EACvD;;AAeH,SAAgB,oBACd,YAC2C;CAO3C,SAAS,YAA+C,YAAyB;AAC/E,MAAI,eAAe,KAAA,EAAW,QAAO;AAErC,MAAI,EAAE,cAAc,WAAW,IAAI,cAAc,WAAW,EAC1D,OAAM,IAAI,MAAM,kDAAkD,WAAW,aAAa,WAAW,GAAG;AAG1G,SAAO,MAAM,MAAM,WAAW,EAAE,MAAM,WAAW,CAAC;;AAGpD,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamhl8/configs",
3
- "version": "0.15.17",
3
+ "version": "0.15.18",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",