-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compat): implement upperFirst/lowerFirst
- Loading branch information
Showing
7 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { lowerFirst } from './lowerFirst'; | ||
import { map } from '../array/map'; | ||
import { stubString } from '../util/stubString'; | ||
|
||
describe('lowerFirst', () => { | ||
it('should lowercase only the first character', () => { | ||
expect(lowerFirst('fred')).toBe('fred'); | ||
expect(lowerFirst('Fred')).toBe('fred'); | ||
expect(lowerFirst('FRED')).toBe('fRED'); | ||
}); | ||
|
||
it('should return an empty string for empty values', () => { | ||
// eslint-disable-next-line no-sparse-arrays | ||
const values = [, null, undefined, '']; | ||
const expected = map(values, stubString); | ||
|
||
const actual = map(values, (value, index) => (index ? lowerFirst(value as any) : lowerFirst())); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { lowerFirst as lowerFirstToolkit } from '../../string/lowerFirst.ts'; | ||
import { toString } from '../util/toString.ts'; | ||
|
||
/** | ||
* Converts the first character of string to lower case. | ||
* | ||
* @param {string} str - The string that is to be changed | ||
* @returns {string} - The converted string. | ||
* | ||
* @example | ||
* const convertedStr1 = lowerCase('fred') // returns 'fred' | ||
* const convertedStr2 = lowerCase('Fred') // returns 'fred' | ||
* const convertedStr3 = lowerCase('FRED') // returns 'fRED' | ||
*/ | ||
export function lowerFirst(str?: string): string { | ||
return lowerFirstToolkit(toString(str)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { upperFirst } from './upperFirst'; | ||
import { map } from '../array/map'; | ||
import { stubString } from '../util/stubString'; | ||
|
||
describe('upperFirst', () => { | ||
it('should uppercase only the first character', () => { | ||
expect(upperFirst('fred')).toBe('Fred'); | ||
expect(upperFirst('Fred')).toBe('Fred'); | ||
expect(upperFirst('FRED')).toBe('FRED'); | ||
}); | ||
|
||
it('should return an empty string for empty values', () => { | ||
// eslint-disable-next-line no-sparse-arrays | ||
const values = [, null, undefined, '']; | ||
const expected = map(values, stubString); | ||
|
||
const actual = map(values, (value, index) => (index ? upperFirst(value as any) : upperFirst())); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { upperFirst as upperFirstToolkit } from '../../string/upperFirst.ts'; | ||
import { toString } from '../util/toString.ts'; | ||
|
||
/** | ||
* Converts the first character of string to upper case. | ||
* | ||
* @param {string} str - The string that is to be changed | ||
* @returns {string} - The converted string. | ||
* | ||
* @example | ||
* const convertedStr1 = upperFirst('fred') // returns 'Fred' | ||
* const convertedStr2 = upperFirst('Fred') // returns 'Fred' | ||
* const convertedStr3 = upperFirst('FRED') // returns 'FRED' | ||
*/ | ||
export function upperFirst(str?: string): string { | ||
return upperFirstToolkit(toString(str)); | ||
} |