@stryke/prisma-trpc-generator
Version:
A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.
1 lines • 2.85 kB
Source Map (JSON)
{"version":3,"file":"title-case.mjs","names":[],"sources":["../../../../string-format/src/title-case.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ACRONYMS } from \"./acronyms\";\nimport { combine } from \"./combine\";\nimport { decamelize } from \"./decamelize\";\nimport type { FormatSpecialCasesOptions } from \"./format-special-cases\";\nimport { formatSpecialCases } from \"./format-special-cases\";\nimport { upperCaseFirst } from \"./upper-case-first\";\n\nexport interface TitleCaseOptions extends FormatSpecialCasesOptions {\n /**\n * Whether to expand acronyms in the input string.\n *\n * @remarks\n * If true, acronyms will be expanded to their full form before being converted to title case. For example, \"NASA\" would be expanded to \"National Aeronautics and Space Administration\".\n *\n * @defaultValue false\n */\n expandAcronyms?: boolean;\n}\n\n/**\n * Convert a string to title case.\n *\n * @param input - The input string to convert.\n * @param options - Options for formatting special cases.\n * @returns The title cased string.\n */\nexport function titleCase<T extends string | undefined>(\n input: T,\n options?: TitleCaseOptions\n): T {\n return input\n ?.replaceAll(\":\", \" - \")\n ?.replaceAll(\"+\", \" + \")\n ?.split(/\\s+-\\s+/)\n .map(segment =>\n decamelize(segment)\n .split(/[\\s\\-_]/)\n .map(upperCaseFirst)\n .map(value =>\n options?.expandAcronyms\n ? ACRONYMS[value]?.description || value\n : value\n )\n .map((value: string, index: number, array: string[]) =>\n formatSpecialCases(value, index, array, options)\n )\n .reduce(combine)\n )\n .join(\" - \") as T;\n}\n"],"mappings":";;;;;;;;;;;;;;AA4CA,SAAgB,UACd,OACA,SACG;AACH,QAAO,OACH,WAAW,KAAK,MAAM,EACtB,WAAW,KAAK,MAAM,EACtB,MAAM,UAAU,CACjB,KAAI,YACH,WAAW,QAAQ,CAChB,MAAM,UAAU,CAChB,IAAI,eAAe,CACnB,KAAI,UACH,SAAS,iBACL,SAAS,QAAQ,eAAe,QAChC,MACL,CACA,KAAK,OAAe,OAAe,UAClC,mBAAmB,OAAO,OAAO,OAAO,QAAQ,CACjD,CACA,OAAO,QAAQ,CACnB,CACA,KAAK,MAAM"}