capitalize/uncapitalize

Runtime implementation of the Capitalize helper type.

capitalize()

import { assert, Equals } from "tsafe";
import { capitalize } from "tsafe/capitalize";

const str = "foo";

const capitalizedStr = capitalize(str);

assert<Equals<typeof capitalizedStr, "Foo">>();
assert(capitalizedStr === "Foo");

//NOTE: There is a 'Capitalize' builtin type in TypeScript such that:
assert<Equals<Capitalize<"foo">, "Foo">>();

uncapitalize()

import { assert, Equals } from "tsafe";
import { uncapitalize } from "tsafe/uncapitalize";

const capitalizedStr = "Foo";

const str = uncapitalize(capitalizedStr);

assert<Equals<typeof str, "foo">>();
assert(str === "foo");

//NOTE: There is a 'Uncapitalize' builtin type in TypeScript such that:
assert<Equals<Uncapitalize<"Foo">, "foo">>();

Last updated