Skip to content

Commit 92680f0

Browse files
authored
feat: Add iEqual to ts/strings (#84)
1 parent 59a13b3 commit 92680f0

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"typedoc-material-theme": "^1.3.0"
2727
},
2828
"pnpm": {
29-
"onlyBuiltDependencies": [
30-
"@biomejs/biome",
31-
"esbuild"
32-
]
29+
"onlyBuiltDependencies": ["@biomejs/biome", "esbuild"]
3330
}
3431
}

src/ts/strings.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ describe('endsWithOneOf', () => {
1414
expect(strings.endsWithOneOf('baa', ['ab', 'ac'])).toBe(false);
1515
});
1616
});
17+
18+
describe('iEqual', () => {
19+
it('returns true when strings are equal', () => {
20+
expect(strings.iEqual('A', 'a')).toBe(true);
21+
expect(strings.iEqual('Hello, World!', 'hello, world!')).toBe(true);
22+
});
23+
24+
it('returns false when strings are not equal', () => {
25+
expect(strings.iEqual('a', 'b')).toBe(false);
26+
});
27+
});

src/ts/strings.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@ export function endsWithOneOf(str: string, strings: string[]): boolean {
3737

3838
return false;
3939
}
40+
41+
/** Case insensitive equality. Returns true if `left.toLowerCase()` and `right.toLowerCase()` are equal.
42+
*
43+
* @param left
44+
* @param right
45+
* @returns
46+
*
47+
* ## Usage
48+
* ```ts
49+
* iEqual('Hello, World!', 'hello, World!'); // true
50+
* ```
51+
*/
52+
export function iEqual(left: string, right: string): boolean {
53+
return left.toLowerCase() === right.toLowerCase();
54+
}

0 commit comments

Comments
 (0)