Skip to content

objectenvy / ArrayMergeStrategy

Type Alias: ArrayMergeStrategy

ts
type ArrayMergeStrategy = "replace" | "concat" | "concat-unique";

Defined in: types.ts:72

Strategy for merging arrays when combining configuration objects via merge() or override().

Remarks

  • 'replace' — the second (higher-priority) array wholly replaces the first. This is the default and the safest choice when arrays are not additive (e.g., an allowed-hosts list you want to completely override).
  • 'concat' — the two arrays are concatenated: first-object elements followed by second-object elements. Duplicates are preserved.
  • 'concat-unique' — same as 'concat' but duplicate primitive values are filtered out. Object items are compared via JSON.stringify; order-sensitive and unaware of undefined.

Example

ts
import { merge } from 'objectenvy';
import type { ArrayMergeStrategy } from 'objectenvy';
const strategy: ArrayMergeStrategy = 'concat-unique';
merge({ hosts: ['a', 'b'] }, { hosts: ['b', 'c'] }, { arrayMergeStrategy: strategy });
// { hosts: ['a', 'b', 'c'] }

Default Value

'replace'

Released under the MIT License.