mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
25 lines
748 B
TypeScript
25 lines
748 B
TypeScript
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||
|
// This module is browser compatible.
|
||
|
|
||
|
import { capitalizeWord, splitToWords } from "./_util.ts";
|
||
|
|
||
|
/**
|
||
|
* Converts a string into camelCase.
|
||
|
*
|
||
|
* @example Usage
|
||
|
* ```ts
|
||
|
* import { toCamelCase } from "@std/text/to-camel-case";
|
||
|
* import { assertEquals } from "@std/assert";
|
||
|
*
|
||
|
* assertEquals(toCamelCase("deno is awesome"),"denoIsAwesome");
|
||
|
* ```
|
||
|
*
|
||
|
* @param input The string that is going to be converted into camelCase
|
||
|
* @returns The string as camelCase
|
||
|
*/
|
||
|
export function toCamelCase(input: string): string {
|
||
|
input = input.trim();
|
||
|
const [first = "", ...rest] = splitToWords(input);
|
||
|
return [first.toLocaleLowerCase(), ...rest.map(capitalizeWord)].join("");
|
||
|
}
|