UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 2.44 kB
{"version":3,"file":"join.cjs","names":["purry"],"sources":["../src/join.ts"],"sourcesContent":["import type { Join } from \"type-fest\";\nimport { purry } from \"./purry\";\n\n// Copied from type-fest, from the Join type.\ntype JoinableItem = bigint | boolean | number | string | null | undefined;\n\n/**\n * Joins the elements of the array by: casting them to a string and\n * concatenating them one to the other, with the provided glue string in between\n * every two elements.\n *\n * When called on a tuple and with stricter item types (union of literal values,\n * the result is strictly typed to the tuples shape and it's item types).\n *\n * @param data - The array to join.\n * @param glue - The string to put in between every two elements.\n * @signature\n * R.join(data, glue)\n * @example\n * R.join([1,2,3], \",\") // => \"1,2,3\" (typed `string`)\n * R.join(['a','b','c'], \"\") // => \"abc\" (typed `string`)\n * R.join(['hello', 'world'] as const, \" \") // => \"hello world\" (typed `hello world`)\n * @dataFirst\n * @category Array\n */\nexport function join<\n T extends ReadonlyArray<JoinableItem> | [],\n Glue extends string,\n>(data: T, glue: Glue): Join<T, Glue>;\n\n/**\n * Joins the elements of the array by: casting them to a string and\n * concatenating them one to the other, with the provided glue string in between\n * every two elements.\n *\n * When called on a tuple and with stricter item types (union of literal values,\n * the result is strictly typed to the tuples shape and it's item types).\n *\n * @param glue - The string to put in between every two elements.\n * @signature\n * R.join(glue)(data)\n * @example\n * R.pipe([1,2,3], R.join(\",\")) // => \"1,2,3\" (typed `string`)\n * R.pipe(['a','b','c'], R.join(\"\")) // => \"abc\" (typed `string`)\n * R.pipe(['hello', 'world'] as const, R.join(\" \")) // => \"hello world\" (typed `hello world`)\n * @dataLast\n * @category Array\n */\nexport function join<\n T extends ReadonlyArray<JoinableItem> | [],\n Glue extends string,\n>(glue: Glue): (data: T) => Join<T, Glue>;\n\nexport function join(...args: ReadonlyArray<unknown>): unknown {\n return purry(joinImplementation, args);\n}\n\nconst joinImplementation = (\n data: ReadonlyArray<unknown>,\n glue: string,\n): string => data.join(glue);\n"],"mappings":"wCAqDA,SAAgB,EAAK,GAAG,EAAuC,CAC7D,OAAOA,EAAAA,EAAM,EAAoB,EAAK,CAGxC,MAAM,GACJ,EACA,IACW,EAAK,KAAK,EAAK"}