UNPKG

typedash

Version:

modern, type-safe collection of utility functions

16 lines (15 loc) 702 B
//#region src/functions/join/join.ts /** * Same as `Array.prototype.join`, but allows specifying a non-`string` separator. * @param elements The elements to join. * @param separator The separator to use. * @returns An array with the elements joined by the separator. */ function join(elements, separator) { const emptySeparator = Symbol("emptySeparator"); const separatorFunction = typeof separator === "function" ? separator : () => separator; return elements.flatMap((element, index, array) => [element, index < array.length - 1 ? separatorFunction(index) : emptySeparator]).filter((item) => item !== emptySeparator); } //#endregion export { join as t }; //# sourceMappingURL=join-FaijElfo.js.map