remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 3.34 kB
Source Map (JSON)
{"version":3,"file":"capitalize.cjs","names":["purry"],"sources":["../src/capitalize.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Makes the first character of a string uppercase while leaving the rest\n * unchanged.\n *\n * It uses the built-in [`String.prototype.toUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)\n * for the runtime and the built-in [`Capitalize`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#capitalizestringtype)\n * utility type for typing and thus shares their _[locale inaccuracies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase#description)_.\n *\n * For display purposes, prefer using the CSS pseudo-element [`::first-letter`](https://developer.mozilla.org/en-US/docs/Web/CSS/::first-letter) to target\n * just the first letter of the word, and [`text-transform: uppercase`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform#uppercase)\n * to capitalize it. This transformation **is** locale-aware.\n *\n * For other case manipulations see: `toUpperCase`, `toLowerCase`,\n * `uncapitalize`, `toCamelCase`, `toKebabCase`, `toSnakeCase`, and\n * `toTitleCase`.\n *\n * @param data - A string.\n * @signature\n * R.capitalize(data);\n * @example\n * R.capitalize(\"hello world\"); // \"Hello world\"\n * @dataFirst\n * @category String\n */\nexport function capitalize<T extends string>(data: T): Capitalize<T>;\n\n/**\n * Makes the first character of a string uppercase while leaving the rest\n * unchanged.\n *\n * It uses the built-in [`String.prototype.toUpperCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)\n * for the runtime and the built-in [`Capitalize`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#capitalizestringtype)\n * utility type for typing and thus shares their _[locale inaccuracies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase#description)_.\n *\n * For display purposes, prefer using the CSS pseudo-element [`::first-letter`](https://developer.mozilla.org/en-US/docs/Web/CSS/::first-letter) to target\n * just the first letter of the word, and [`text-transform: uppercase`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform#uppercase)\n * to capitalize it. This transformation **is** locale-aware.\n *\n * For other case manipulations see: `toUpperCase`, `toLowerCase`,\n * `uncapitalize`, `toCamelCase`, `toKebabCase`, `toSnakeCase`, and\n * `toTitleCase`.\n *\n * @signature\n * R.capitalize()(data);\n * @example\n * R.pipe(\"hello world\", R.capitalize()); // \"Hello world\"\n * @dataLast\n * @category String\n */\nexport function capitalize(): <T extends string>(data: T) => Capitalize<T>;\n\nexport function capitalize(...args: ReadonlyArray<unknown>): unknown {\n return purry(capitalizeImplementation, args);\n}\n\nconst capitalizeImplementation = <T extends string>(data: T): Capitalize<T> =>\n `${data[0]?.toUpperCase() ?? \"\"}${data.slice(1)}` as Capitalize<T>;\n"],"mappings":"wCAqDA,SAAgB,EAAW,GAAG,EAAuC,CACnE,OAAOA,EAAAA,EAAM,EAA0B,EAAK,CAG9C,MAAM,EAA8C,GAClD,GAAG,EAAK,IAAI,aAAa,EAAI,KAAK,EAAK,MAAM,EAAE"}