mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
14 lines
430 B
TypeScript
14 lines
430 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
export function splitToWords(input: string) {
|
|
input = input.replaceAll(/[^a-zA-Z0-9\s-_]/g, "");
|
|
if (/[\s-_]+/.test(input)) return input.split(/[\s-_]+/);
|
|
return input.split(/(?=[A-Z])+/);
|
|
}
|
|
|
|
export function capitalizeWord(word: string): string {
|
|
return word
|
|
? word?.[0]?.toLocaleUpperCase() + word.slice(1).toLocaleLowerCase()
|
|
: word;
|
|
}
|