diff --git a/src/pack/array.ts b/src/pack/array.ts index dd951fb..a04c2e3 100644 --- a/src/pack/array.ts +++ b/src/pack/array.ts @@ -1,18 +1,19 @@ import type { PackArrayOptions } from '../types' -import { packObject } from './object' +import { InternalKeySymbol, packObject } from './object' export function packArray[]>(input: T, options?: PackArrayOptions): Partial> { const packed: Partial> = {} for (const i of input) { const packedObj = packObject(i, options) const pKey = Object.keys(packedObj)[0] as keyof typeof packed + const isDedupeKey = pKey.startsWith(InternalKeySymbol) - if (!pKey.startsWith('key-') && packed[pKey]) { + if (!isDedupeKey && packed[pKey]) { packed[pKey] = Array.isArray(packed[pKey]) ? packed[pKey] : [packed[pKey]] packed[pKey].push(Object.values(packedObj)[0]) } else { - packed[pKey.startsWith('key-') ? (pKey.split('-').pop() || pKey) : pKey] = packedObj[pKey] + packed[isDedupeKey ? (pKey.split('-').slice(1).join('-') || pKey) : pKey] = packedObj[pKey] } } return packed