diff --git a/src/lib/functions/camelize.ts b/src/lib/functions/camelize.ts index c329903..3f04e2b 100644 --- a/src/lib/functions/camelize.ts +++ b/src/lib/functions/camelize.ts @@ -2,23 +2,30 @@ * Converts a string to camelCase. * Removes all non-alphanumeric separators and capitalizes each word except the first. * - * @param input The input string to be camelized. - * @returns The camelCased version of the input string. + * ## Usage * - * @example + * ```ts * camelize("hello world"); // "helloWorld" + * ``` * - * @example + * ```ts * camelize("Hello_world"); // "helloWorld" + * ``` * - * @example + * ```ts * camelize("API_response_code"); // "apiResponseCode" + * ``` * - * @example + * ```ts * camelize("user-42-profile"); // "user42Profile" + * ``` * - * @example + * ```ts * camelize("ThisIsALongVariableName"); // "thisIsALongVariableName" + * ``` + * + * @param input The input string to be camelized. + * @returns The camelCased version of the input string. */ export function camelize(input: string): string { const parts = input diff --git a/src/lib/functions/kebabify.ts b/src/lib/functions/kebabify.ts index 5e23370..82109b4 100644 --- a/src/lib/functions/kebabify.ts +++ b/src/lib/functions/kebabify.ts @@ -6,26 +6,34 @@ import { PLACEHOLDER } from "../private/constants"; * Replaces spaces, underscores, camelCase transitions, and other separators with dashes. * It also preserves version tokens like "v2" and lowercases the result. * - * @param input A string to be converted to kebab-case. - * @returns The kebab-cased version of the input string. + * ## Usage * - * @example + * ```ts * kebabify("hello world"); // "hello-world" + * ``` * - * @example + * ```ts * kebabify("first_name"); // "first-name" + * ``` * - * @example + * ```ts * kebabify("userProfile42"); // "user-profile-42" + * ``` * - * @example + * ```ts * kebabify("APIResponseV2"); // "api-response-v2" + * ``` * - * @example + * ```ts * kebabify("HTML5_Parser v3"); // "html-5-parser-v3" + * ``` * - * @example + * ```ts * kebabify(" Leading_and trailing "); // "leading-and-trailing" + * ``` + * + * @param input A string to be converted to kebab-case. + * @returns The kebab-cased version of the input string. */ export function kebabify(input: string): string { const versionMatches: string[] = []; @@ -35,7 +43,7 @@ export function kebabify(input: string): string { const id = versionMatches.length; versionMatches.push(match); return `-${PLACEHOLDER}-${id}`; - }); + }); let kebabed = preserved .replace(/([a-z0-9])([A-Z])/g, '$1-$2') // camelCase @@ -55,4 +63,4 @@ export function kebabify(input: string): string { // Step 4: lowercase entire result return kebabed.toLowerCase(); -} \ No newline at end of file +} diff --git a/src/lib/functions/pascalize.ts b/src/lib/functions/pascalize.ts index a22f985..3fe7402 100644 --- a/src/lib/functions/pascalize.ts +++ b/src/lib/functions/pascalize.ts @@ -4,23 +4,30 @@ * Removes non-alphanumeric characters, splits on casing and digits, * capitalizes each word, and strips leading/trailing separators. * - * @param input A string to be returned in PascalCase. - * @returns The PascalCased version of the input string. + * ## Usage * - * @example + * ```ts * pascalize("hello world"); // "HelloWorld" + * ``` * - * @example + * ```ts * pascalize("first_name"); // "FirstName" + * ``` * - * @example + * ```ts * pascalize("user42Profile"); // "User42Profile" + * ``` * - * @example + * ```ts * pascalize("API response code"); // "ApiResponseCode" + * ``` * - * @example + * ```ts * pascalize(" messy__input--string "); // "MessyInputString" + * ``` + * + * @param input A string to be returned in PascalCase. + * @returns The PascalCased version of the input string. */ export function pascalize(input: string): string { const parts = input diff --git a/src/lib/functions/pluralize.ts b/src/lib/functions/pluralize.ts index 683c5bf..9e630ee 100644 --- a/src/lib/functions/pluralize.ts +++ b/src/lib/functions/pluralize.ts @@ -11,41 +11,54 @@ import { preserveCasing } from '../private/util'; * * The output preserves the casing of the input, especially the prefix. * - * @param word A singular word to be pluralized. - * @returns The plural form of the input word. + * ## Usage * - * @example + * ```ts * pluralize("city"); // "cities" + * ``` * - * @example + * ```ts * pluralize("box"); // "boxes" + * ``` * - * @example + * ```ts * pluralize("child"); // "children" + * ``` * - * @example + * ```ts * pluralize("person"); // "people" + * ``` * - * @example + * ```ts * pluralize("API"); // "APIs" + * ``` * - * @example + * ```ts * pluralize("ID"); // "IDs" + * ``` * - * @example + * ```ts * pluralize("File"); // "Files" + * ``` * - * @example + * ```ts * pluralize("buzz"); // "buzzes" + * ``` * - * @example + * ```ts * pluralize("CPU"); // "CPUs" + * ``` * - * @example + * ```ts * pluralize("DOG"); // "DOGS" + * ``` + * + * ```ts + * pluralize("A"); // "As" + * ``` * - * @example - * pluralize("A"); // "as" + * @param word A singular word to be pluralized. + * @returns The plural form of the input word. */ export function pluralize(word: string): string { if (word.length === 0) return ''; diff --git a/src/lib/functions/quantify.ts b/src/lib/functions/quantify.ts index 351a148..d650bae 100644 --- a/src/lib/functions/quantify.ts +++ b/src/lib/functions/quantify.ts @@ -3,37 +3,46 @@ import { pluralize } from './pluralize'; /** * Formats a number with a unit, automatically pluralizing the unit based on the count. * - * If the `count` is exactly 1, the singular `unit` is used. Otherwise, it either uses - * the provided `plural` form or calls `pluralize(unit)` to generate one. + * If the `count` is exactly 1, the singular `unit` is used. + * Otherwise, it either uses the provided `plural` form or calls + * pluralize(unit) + * to generate one. * - * @param count Number of units, as a number or numeric string. - * @param unit Label for the singular unit (e.g., "apple"). - * @param plural Optional plural label. If not provided, the unit is pluralized automatically. - * @returns A formatted string in the form `x unit(s)`. + * ## Usage * - * @example + * ```ts * quantify(1, "apple"); // "1 apple" + * ``` * - * @example + * ```ts * quantify(3, "apple"); // "3 apples" + * ``` * - * @example - * quantify("2", "box"); // "2 boxes" + * ```ts + * quantify("02", "box"); // "02 boxes" + * ``` * - * @example + * ```ts * quantify(1, "child", "children"); // "1 child" + * ``` * - * @example + * ```ts * quantify(2, "child", "children"); // "2 children" + * ``` * - * @example + * ```ts * quantify(5, "CPU"); // "5 CPUs" + * ``` + * + * @param count Number of units, as a number or numeric string. + * @param unit Label for the singular unit (e.g., "apple"). + * @param plural Optional plural label. If not provided, the unit is pluralized automatically. + * @returns A formatted string in the form `x unit(s)`. */ -export function quantify(count: number|string, unit: string, plural?: string) { +export function quantify(count: number | string, unit: string, plural?: string) { const value = typeof count == 'number' ? count : Number(count); const label = value === 1 ? unit : plural === undefined ? pluralize(unit) : plural; return `${count} ${label}` - -} \ No newline at end of file +} diff --git a/src/lib/functions/singularize.ts b/src/lib/functions/singularize.ts index b2ce99a..a7d09d3 100644 --- a/src/lib/functions/singularize.ts +++ b/src/lib/functions/singularize.ts @@ -11,29 +11,38 @@ import { preserveCasing } from '../private/util'; * * Preserves the casing of the original input, including acronyms or title case. * - * @param word Plural word to be converted to singular. - * @returns The singular form of the input word. + * ## Usage * - * @example + * ```ts * singularize("cities"); // "city" + * ``` * - * @example + * ```ts * singularize("boxes"); // "box" + * ``` * - * @example + * ```ts * singularize("children"); // "child" + * ``` * - * @example + * ```ts * singularize("teeth"); // "tooth" + * ``` * - * @example + * ```ts * singularize("dogs"); // "dog" + * ``` * - * @example + * ```ts * singularize("BUZZES"); // "BUZZ" + * ``` * - * @example + * ```ts * singularize("IDs"); // "ID" + * ``` + * + * @param word Plural word to be converted to singular. + * @returns The singular form of the input word. */ export function singularize(word: string): string { const lower = word.toLowerCase(); @@ -83,4 +92,4 @@ export function singularize(word: string): string { // Default: assume word is already singular return word; -} \ No newline at end of file +} diff --git a/src/lib/functions/snakify.ts b/src/lib/functions/snakify.ts index c643503..88aec27 100644 --- a/src/lib/functions/snakify.ts +++ b/src/lib/functions/snakify.ts @@ -7,23 +7,30 @@ import { PLACEHOLDER } from '../private/constants'; * removes special characters, preserves embedded version tokens (like "v2"), * and lowercases the result. * - * @param input A string to be converted to snake_case. - * @returns The snake_cased version of the input. + * ## Usage * - * @example + * ```ts * snakify("hello world"); // "hello_world" + * ``` * - * @example + * ```ts * snakify("UserProfileV2"); // "user_profile_v2" + * ``` * - * @example + * ```ts * snakify("HTML5 Parser"); // "html_5_parser" + * ``` * - * @example + * ```ts * snakify(" messy-input_string "); // "messy_input_string" + * ``` * - * @example + * ```ts * snakify("ReportV3Final"); // "report_v3_final" + * ``` + * + * @param input A string to be converted to snake_case. + * @returns The snake_cased version of the input. */ export function snakify(input: string): string { const versionMatches: string[] = []; diff --git a/src/lib/functions/titalize.ts b/src/lib/functions/titalize.ts index 95378ce..075dd96 100644 --- a/src/lib/functions/titalize.ts +++ b/src/lib/functions/titalize.ts @@ -5,23 +5,30 @@ * (like "of", "and", "the") unless they appear at the beginning. * Preserves words already containing uppercase letters (e.g., acronyms). * - * @param input The string to be converted to title case. - * @returns The input string formatted in title case. + * ## Usage * - * @example + * ```ts * titalize("the quick brown fox"); // "The Quick Brown Fox" + * ``` * - * @example + * ```ts * titalize("a tale of two cities"); // "A Tale of Two Cities" + * ``` * - * @example + * ```ts * titalize("in the heart of the sea"); // "In the Heart of the Sea" + * ``` * - * @example + * ```ts * titalize("API reference guide"); // "API Reference Guide" + * ``` * - * @example + * ```ts * titalize(" war and peace "); // "War and Peace" + * ``` + * + * @param input The string to be converted to title case. + * @returns The input string formatted in title case. */ export function titalize(input: string): string { const smallWords = new Set([ @@ -46,4 +53,4 @@ export function titalize(input: string): string { } ) .join(' '); -} \ No newline at end of file +} diff --git a/src/lib/functions/verbalize.ts b/src/lib/functions/verbalize.ts index 7c2acc9..9f3c935 100644 --- a/src/lib/functions/verbalize.ts +++ b/src/lib/functions/verbalize.ts @@ -7,26 +7,34 @@ import { PLACEHOLDER } from '../private/constants'; * identifiers into space-separated words. Capitalizes the first word, and * preserves acronyms and version tokens (e.g., `v2`, `v3.1`). * - * @param input A string to be returned as spoken words. - * @returns A natural-language version of the input identifier. + * ## Usage * - * @example + * ```ts * verbalize("helloWorld"); // "Hello world" + * ``` * - * @example + * ```ts * verbalize("HTML5Parser"); // "HTML 5 parser" + * ``` * - * @example + * ```ts * verbalize("api_v2_response"); // "Api v2 response" + * ``` * - * @example + * ```ts * verbalize("User-ID"); // "User ID" + * ``` * - * @example + * ```ts * verbalize("employeeV3Final"); // "Employee v3 final" + * ``` * - * @example + * ```ts * verbalize("version_2_0_release"); // "Version 2 0 release" + * ``` + * + * @param input A string to be returned as spoken words. + * @returns A natural-language version of the input identifier. */ export function verbalize(input: string): string { const versionMatches: string[] = []; @@ -61,4 +69,4 @@ export function verbalize(input: string): string { .join(' '); return result.charAt(0).toUpperCase() + result.slice(1); -} \ No newline at end of file +}