toCapitalizedCase()

Capitalize specific or general letters in a string.

Note:

Range & at properties are 0-first.

All optional arguments are ordered by importance.

Arguments

Required:

s: <T extends string> // Could be a string, or a custom object that extends it

Optional:

at: number; // Capitalize only that letter
range: [number, number]; // Capitalize letters between this Range, both inclusive
forChars: "all" | "first" | "last" // Defaults to all

Returns

(string): Outputs the input string with desired capitalization.

Example

const stringLowerCased = "hello world";

const strBasic = toCapitalizedCase(stringLowerCased); // Default will capitalize entire string
// => "HELLO WORLD";

const strCapitalizedAt = toCapitalizedCase(stringLowerCased, { at: 8 }); // 0-first based param
// => "hello woRld";

const strCapitalizedRange = toCapitalizedCase(stringLowerCased, { range: [0, 5] }); // 0-first based param
// => "HELLO world";

const strCapitalizedForChars = toCapitalizedCase(stringLowerCased, { forChars: "first" });
// => "Hello world";