TreasureTrails/node_modules/remeda/dist/toTitleCase.cjs.map

1 line
7.1 KiB
Text
Raw Permalink Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"toTitleCase.cjs","names":["words"],"sources":["../src/toTitleCase.ts"],"sourcesContent":["import type { IsEqual, IsLiteral, Join, Words } from \"type-fest\";\nimport type { OptionalOptionsWithDefaults } from \"./internal/types/OptionalOptionsWithDefaults\";\nimport { words } from \"./internal/words\";\n\nconst LOWER_CASE_CHARACTER_RE = /[a-z]/u;\n\nconst DEFAULT_PRESERVE_CONSECUTIVE_UPPERCASE = true;\n\ntype TitleCaseOptions = {\n readonly preserveConsecutiveUppercase?: boolean;\n};\n\ntype TitleCaseOptionsWithDefaults<Options extends TitleCaseOptions> =\n OptionalOptionsWithDefaults<\n TitleCaseOptions,\n Options,\n {\n // We use the runtime const for the default type so they stay coupled.\n preserveConsecutiveUppercase: typeof DEFAULT_PRESERVE_CONSECUTIVE_UPPERCASE;\n }\n >;\n\ntype TitleCase<S extends string, Options extends TitleCaseOptions> =\n IsLiteral<S> extends true\n ? Join<\n TitleCasedArray<\n Words<IsEqual<S, Uppercase<S>> extends true ? Lowercase<S> : S>,\n TitleCaseOptionsWithDefaults<Options>\n >,\n \" \"\n >\n : string;\n\ntype TitleCasedArray<\n T extends readonly string[],\n Options extends TitleCaseOptions,\n> = {\n [I in keyof T]: Capitalize<\n Options[\"preserveConsecutiveUppercase\"] extends true\n ? T[I]\n : Lowercase<T[I]>\n >;\n};\n\n/**\n * Converts text to **Title Case** by splitting it into words, capitalizing the\n * first letter of each word, then joining them back together with spaces.\n *\n * Because it uses the built-in case conversion methods, the function shares\n * their _[locale inaccuracies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase#description)_,\n * making it best suited for simple strings like identifiers and internal keys.\n * For linguistic text processing, use [`Intl.Segmenter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)\n * with [`granularity: \"word\"`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter#parameters),\n * [`toLocaleLowerCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase),\n * and [`toLocaleUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)\n * which are purpose-built to handle nuances in languages and locales.\n *\n * For other case manipulations see: `toLowerCase`, `toUpperCase`, `capitalize`,\n * `uncapitalize`, `toCamelCase`, `toKebabCase`, and `toSnakeCase`.\n *\n * @param data - A string.\n * @param options - An _optional_ object with the _optional_ property\n * `preserveConsecutiveUppercase` that can be used to change the way consecutive\n * uppercase characters are handled. Defaults to `true`.\n * @signature\n * R.toTitleCase(data);\n * R.toTitleCase(data, { preserveConsecutiveUppercase });\n * @example\n * R.toTitleCase(\"hello world\"); // \"Hello World\"\n * R.toTitleCase(\"--foo-bar--\"); // \"Foo Bar\"\n * R.toTitleCase(\"fooBar\"); // \"Foo Bar\"\n * R.toTitleCase(\"__FOO_BAR__\"); // \"Foo Bar\"\n * R.toTitleCase(\"XMLHttpRequest\"); // \"XML Http Request\"\n * R.toTitleCase(\"XMLHttpRequest\", { preserveConsecutiveUppercase: false }); // \"Xml Http Request\"\n * @dataFirst\n * @category String\n */\nexport function toTitleCase<S extends string, Options extends TitleCaseOptions>(\n data: S,\n options?: Options,\n): TitleCase<S, Options>;\n\n/**\n * Converts text to **Title Case** by splitting it into words, capitalizing the\n * first letter of each word, then joining them back together with spaces.\n *\n * Because it uses the built-in case conversion methods, the function shares\n * their _[locale inaccuracies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase#description)_,\n * making it best suited for simple strings like identifiers and internal keys.\n * For linguistic