Skip to content

Commit c87f31b

Browse files
Merge pull request #10 from AgapeToolkit/update-docs
update typedocs
2 parents 6db757f + b5c160d commit c87f31b

9 files changed

Lines changed: 163 additions & 88 deletions

File tree

src/lib/functions/camelize.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
22
* Converts a string to camelCase.
33
* Removes all non-alphanumeric separators and capitalizes each word except the first.
44
*
5-
* @param input The input string to be camelized.
6-
* @returns The camelCased version of the input string.
5+
* ## Usage
76
*
8-
* @example
7+
* ```ts
98
* camelize("hello world"); // "helloWorld"
9+
* ```
1010
*
11-
* @example
11+
* ```ts
1212
* camelize("Hello_world"); // "helloWorld"
13+
* ```
1314
*
14-
* @example
15+
* ```ts
1516
* camelize("API_response_code"); // "apiResponseCode"
17+
* ```
1618
*
17-
* @example
19+
* ```ts
1820
* camelize("user-42-profile"); // "user42Profile"
21+
* ```
1922
*
20-
* @example
23+
* ```ts
2124
* camelize("ThisIsALongVariableName"); // "thisIsALongVariableName"
25+
* ```
26+
*
27+
* @param input The input string to be camelized.
28+
* @returns The camelCased version of the input string.
2229
*/
2330
export function camelize(input: string): string {
2431
const parts = input

src/lib/functions/kebabify.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@ import { PLACEHOLDER } from "../private/constants";
66
* Replaces spaces, underscores, camelCase transitions, and other separators with dashes.
77
* It also preserves version tokens like "v2" and lowercases the result.
88
*
9-
* @param input A string to be converted to kebab-case.
10-
* @returns The kebab-cased version of the input string.
9+
* ## Usage
1110
*
12-
* @example
11+
* ```ts
1312
* kebabify("hello world"); // "hello-world"
13+
* ```
1414
*
15-
* @example
15+
* ```ts
1616
* kebabify("first_name"); // "first-name"
17+
* ```
1718
*
18-
* @example
19+
* ```ts
1920
* kebabify("userProfile42"); // "user-profile-42"
21+
* ```
2022
*
21-
* @example
23+
* ```ts
2224
* kebabify("APIResponseV2"); // "api-response-v2"
25+
* ```
2326
*
24-
* @example
27+
* ```ts
2528
* kebabify("HTML5_Parser v3"); // "html-5-parser-v3"
29+
* ```
2630
*
27-
* @example
31+
* ```ts
2832
* kebabify(" Leading_and trailing "); // "leading-and-trailing"
33+
* ```
34+
*
35+
* @param input A string to be converted to kebab-case.
36+
* @returns The kebab-cased version of the input string.
2937
*/
3038
export function kebabify(input: string): string {
3139
const versionMatches: string[] = [];
@@ -35,7 +43,7 @@ export function kebabify(input: string): string {
3543
const id = versionMatches.length;
3644
versionMatches.push(match);
3745
return `-${PLACEHOLDER}-${id}`;
38-
});
46+
});
3947

4048
let kebabed = preserved
4149
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') // camelCase
@@ -55,4 +63,4 @@ export function kebabify(input: string): string {
5563

5664
// Step 4: lowercase entire result
5765
return kebabed.toLowerCase();
58-
}
66+
}

src/lib/functions/pascalize.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@
44
* Removes non-alphanumeric characters, splits on casing and digits,
55
* capitalizes each word, and strips leading/trailing separators.
66
*
7-
* @param input A string to be returned in PascalCase.
8-
* @returns The PascalCased version of the input string.
7+
* ## Usage
98
*
10-
* @example
9+
* ```ts
1110
* pascalize("hello world"); // "HelloWorld"
11+
* ```
1212
*
13-
* @example
13+
* ```ts
1414
* pascalize("first_name"); // "FirstName"
15+
* ```
1516
*
16-
* @example
17+
* ```ts
1718
* pascalize("user42Profile"); // "User42Profile"
19+
* ```
1820
*
19-
* @example
21+
* ```ts
2022
* pascalize("API response code"); // "ApiResponseCode"
23+
* ```
2124
*
22-
* @example
25+
* ```ts
2326
* pascalize(" messy__input--string "); // "MessyInputString"
27+
* ```
28+
*
29+
* @param input A string to be returned in PascalCase.
30+
* @returns The PascalCased version of the input string.
2431
*/
2532
export function pascalize(input: string): string {
2633
const parts = input

src/lib/functions/pluralize.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,54 @@ import { preserveCasing } from '../private/util';
1111
*
1212
* The output preserves the casing of the input, especially the prefix.
1313
*
14-
* @param word A singular word to be pluralized.
15-
* @returns The plural form of the input word.
14+
* ## Usage
1615
*
17-
* @example
16+
* ```ts
1817
* pluralize("city"); // "cities"
18+
* ```
1919
*
20-
* @example
20+
* ```ts
2121
* pluralize("box"); // "boxes"
22+
* ```
2223
*
23-
* @example
24+
* ```ts
2425
* pluralize("child"); // "children"
26+
* ```
2527
*
26-
* @example
28+
* ```ts
2729
* pluralize("person"); // "people"
30+
* ```
2831
*
29-
* @example
32+
* ```ts
3033
* pluralize("API"); // "APIs"
34+
* ```
3135
*
32-
* @example
36+
* ```ts
3337
* pluralize("ID"); // "IDs"
38+
* ```
3439
*
35-
* @example
40+
* ```ts
3641
* pluralize("File"); // "Files"
42+
* ```
3743
*
38-
* @example
44+
* ```ts
3945
* pluralize("buzz"); // "buzzes"
46+
* ```
4047
*
41-
* @example
48+
* ```ts
4249
* pluralize("CPU"); // "CPUs"
50+
* ```
4351
*
44-
* @example
52+
* ```ts
4553
* pluralize("DOG"); // "DOGS"
54+
* ```
55+
*
56+
* ```ts
57+
* pluralize("A"); // "As"
58+
* ```
4659
*
47-
* @example
48-
* pluralize("A"); // "as"
60+
* @param word A singular word to be pluralized.
61+
* @returns The plural form of the input word.
4962
*/
5063
export function pluralize(word: string): string {
5164
if (word.length === 0) return '';

src/lib/functions/quantify.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,46 @@ import { pluralize } from './pluralize';
33
/**
44
* Formats a number with a unit, automatically pluralizing the unit based on the count.
55
*
6-
* If the `count` is exactly 1, the singular `unit` is used. Otherwise, it either uses
7-
* the provided `plural` form or calls `pluralize(unit)` to generate one.
6+
* If the `<property>count` is exactly 1, the singular `<property>unit` is used.
7+
* Otherwise, it either uses the provided `<property>plural` form or calls
8+
* <code><reference>pluralize</reference>(<property>unit</property>)</code>
9+
* to generate one.
810
*
9-
* @param count Number of units, as a number or numeric string.
10-
* @param unit Label for the singular unit (e.g., "apple").
11-
* @param plural Optional plural label. If not provided, the unit is pluralized automatically.
12-
* @returns A formatted string in the form `x unit(s)`.
11+
* ## Usage
1312
*
14-
* @example
13+
* ```ts
1514
* quantify(1, "apple"); // "1 apple"
15+
* ```
1616
*
17-
* @example
17+
* ```ts
1818
* quantify(3, "apple"); // "3 apples"
19+
* ```
1920
*
20-
* @example
21-
* quantify("2", "box"); // "2 boxes"
21+
* ```ts
22+
* quantify("02", "box"); // "02 boxes"
23+
* ```
2224
*
23-
* @example
25+
* ```ts
2426
* quantify(1, "child", "children"); // "1 child"
27+
* ```
2528
*
26-
* @example
29+
* ```ts
2730
* quantify(2, "child", "children"); // "2 children"
31+
* ```
2832
*
29-
* @example
33+
* ```ts
3034
* quantify(5, "CPU"); // "5 CPUs"
35+
* ```
36+
*
37+
* @param count Number of units, as a number or numeric string.
38+
* @param unit Label for the singular unit (e.g., "apple").
39+
* @param plural Optional plural label. If not provided, the unit is pluralized automatically.
40+
* @returns A formatted string in the form `x unit(s)`.
3141
*/
32-
export function quantify(count: number|string, unit: string, plural?: string) {
42+
export function quantify(count: number | string, unit: string, plural?: string) {
3343
const value = typeof count == 'number' ? count : Number(count);
3444

3545
const label = value === 1 ? unit : plural === undefined ? pluralize(unit) : plural;
3646

3747
return `${count} ${label}`
38-
39-
}
48+
}

src/lib/functions/singularize.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,38 @@ import { preserveCasing } from '../private/util';
1111
*
1212
* Preserves the casing of the original input, including acronyms or title case.
1313
*
14-
* @param word Plural word to be converted to singular.
15-
* @returns The singular form of the input word.
14+
* ## Usage
1615
*
17-
* @example
16+
* ```ts
1817
* singularize("cities"); // "city"
18+
* ```
1919
*
20-
* @example
20+
* ```ts
2121
* singularize("boxes"); // "box"
22+
* ```
2223
*
23-
* @example
24+
* ```ts
2425
* singularize("children"); // "child"
26+
* ```
2527
*
26-
* @example
28+
* ```ts
2729
* singularize("teeth"); // "tooth"
30+
* ```
2831
*
29-
* @example
32+
* ```ts
3033
* singularize("dogs"); // "dog"
34+
* ```
3135
*
32-
* @example
36+
* ```ts
3337
* singularize("BUZZES"); // "BUZZ"
38+
* ```
3439
*
35-
* @example
40+
* ```ts
3641
* singularize("IDs"); // "ID"
42+
* ```
43+
*
44+
* @param word Plural word to be converted to singular.
45+
* @returns The singular form of the input word.
3746
*/
3847
export function singularize(word: string): string {
3948
const lower = word.toLowerCase();
@@ -83,4 +92,4 @@ export function singularize(word: string): string {
8392

8493
// Default: assume word is already singular
8594
return word;
86-
}
95+
}

src/lib/functions/snakify.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,30 @@ import { PLACEHOLDER } from '../private/constants';
77
* removes special characters, preserves embedded version tokens (like "v2"),
88
* and lowercases the result.
99
*
10-
* @param input A string to be converted to snake_case.
11-
* @returns The snake_cased version of the input.
10+
* ## Usage
1211
*
13-
* @example
12+
* ```ts
1413
* snakify("hello world"); // "hello_world"
14+
* ```
1515
*
16-
* @example
16+
* ```ts
1717
* snakify("UserProfileV2"); // "user_profile_v2"
18+
* ```
1819
*
19-
* @example
20+
* ```ts
2021
* snakify("HTML5 Parser"); // "html_5_parser"
22+
* ```
2123
*
22-
* @example
24+
* ```ts
2325
* snakify(" messy-input_string "); // "messy_input_string"
26+
* ```
2427
*
25-
* @example
28+
* ```ts
2629
* snakify("ReportV3Final"); // "report_v3_final"
30+
* ```
31+
*
32+
* @param input A string to be converted to snake_case.
33+
* @returns The snake_cased version of the input.
2734
*/
2835
export function snakify(input: string): string {
2936
const versionMatches: string[] = [];

0 commit comments

Comments
 (0)