UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.19 kB
{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TGetUnionArgs = Parameters<typeof getUnion>;\r\n\r\nexport type TGetUnionReturn = ReturnType<typeof getUnion>;\r\n\r\n/**\r\n * Gets union Array of two given Arrays\r\n * @template T\r\n * @param {Array<T>} arr1 first source Array\r\n * @param {Array<T>} arr2 sound source Array\r\n * @returns {Array<T>}\r\n * @throws {TypeError} getUnion: arr1 and arr2 must be arrays\r\n * @example\r\n * // How to merge two arrays in JavaScript and deduplicate items?\r\n * const arr1 = [ 1, 2, 3 ];\r\n * const arr2 = [ 2, 3, 4, 5 ];\r\n * const union = getUnion(arr1, arr2);\r\n * console.log(union); // => [ 1, 2, 3, 4, 5 ];\r\n */\r\nexport const getUnion = <T>(arr1: T[], arr2: T[]): T[] => {\r\n if (!Array.isArray(arr1) || !Array.isArray(arr2)) {\r\n throw new TypeError(\"getUnion: arr1 and arr2 must be arrays\");\r\n }\r\n return [ ...new Set<T>([ ...arr1, ...arr2 ]) ];\r\n};\r\n"],"names":["getUnion","arr1","arr2","Array","isArray","TypeError","Set"],"mappings":";;;;;;;;;;;;;;SAkBaA,SAAWA,CAAIC,KAAWC,QACrC,IAAKC,MAAMC,QAAQH,QAAUE,MAAMC,QAAQF,MACzC,MAAM,IAAIG,UAAU,0CAEtB,MAAO,IAAK,IAAIC,IAAO,IAAKL,QAASC"}