Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 8x 16x | import { capitalize } from './capitalize';
import { splitWords } from './split-words';
/**
* Converts a string to camelCase; acronyms are words (`XMLHttpRequest` → `xmlHttpRequest`).
*
* @param input - The identifier or sentence to convert, in any case style.
* @returns The camelCase string; `''` when the input has no word.
* @example
* camelCase('user-id'); // 'userId'
* camelCase('XML HTTP request'); // 'xmlHttpRequest'
*/
export function camelCase(input: string): string {
return splitWords(input)
.map((word, index) => (index === 0 ? word.toLowerCase() : capitalize(word.toLowerCase())))
.join('');
}
|