Skip to content

Commit a26baad

Browse files
authored
Uncapitalize String (#68)
1 parent 768a4ea commit a26baad

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `uncapitalize` string utils
13+
1014
## [1.3.1] - 2025-06-06
1115

1216
### Fixed

src/lib/string.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNullOrEmpty, isNullOrWhitespace, capitalize } from "./string";
1+
import { isNullOrEmpty, isNullOrWhitespace, capitalize, uncapitalize } from "./string";
22

33
describe("string tests", () => {
44
test.each([
@@ -72,4 +72,16 @@ describe("string tests", () => {
7272
])("capitalize", (value, expected) => {
7373
expect(capitalize(value)).toBe(expected);
7474
});
75+
76+
test.each([
77+
[null as unknown as string, null],
78+
[undefined as unknown as string, undefined],
79+
["", ""],
80+
["A", "a"],
81+
["Hello", "hello"],
82+
["Hello world", "hello world"],
83+
["hello world", "hello world"],
84+
])("uncapitalize", (value, expected) => {
85+
expect(uncapitalize(value)).toBe(expected);
86+
});
7587
});

src/lib/string.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ export function capitalize(value?: string): string | undefined {
3232

3333
return value.charAt(0).toUpperCase() + value.slice(1);
3434
}
35+
36+
/**
37+
* Uncapitalize the string
38+
* @param value The string to uncapitalize
39+
* @returns The uncapitalized string
40+
*/
41+
export function uncapitalize(value?: string): string | undefined {
42+
if (!value || isNullOrWhitespace(value)) {
43+
return value;
44+
}
45+
46+
return value.charAt(0).toLowerCase() + value.slice(1);
47+
}

0 commit comments

Comments
 (0)