Skip to content

Commit

Permalink
✨ Add toLower and toUpper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Apr 15, 2021
1 parent ec4af99 commit 699602e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export type { IsSymbol } from '@/isSymbol'
export { isSymbol } from '@/isSymbol'
export { multiply } from '@/multiply'
export { subtract } from '@/subtract'
export { toLower } from '@/toLower'
export { toUpper } from '@/toUpper'
export type { AnyFn } from '@/types'
13 changes: 13 additions & 0 deletions src/toLower.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Return lowercase string
*
* @param val - input string value
* @returns lowercase string
*
* @example
* toLower('Hello') // hello
*/
const toLower = <T extends string>(val: T): Lowercase<T> =>
val.toLowerCase() as Lowercase<T>

export { toLower }
13 changes: 13 additions & 0 deletions src/toUpper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Return uppercase string
*
* @param val - input string value
* @returns uppercase string
*
* @example
* toUpper('Hello') // HELLO
*/
const toUpper = <T extends string>(val: T): Uppercase<T> =>
val.toUpperCase() as Uppercase<T>

export { toUpper }
15 changes: 15 additions & 0 deletions test/toLower.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { toLower } from '@/toLower'

describe('toLower', () => {
const table: [string, string][] = [
['', ''],
['Hello', 'hello'],
['HeLlo', 'hello'],
['hello', 'hello'],
['Hello World', 'hello world']
]

it.each(table)('toLower(%s) -> %s', (val, expected) => {
expect(toLower(val)).toBe(expected)
})
})
14 changes: 14 additions & 0 deletions test/toUpper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { toUpper } from '@/toUpper'

describe('toUpper', () => {
const table: [string, string][] = [
['', ''],
['Hello', 'HELLO'],
['hello', 'HELLO'],
['Hello World', 'HELLO WORLD']
]

it.each(table)('toUpper(%s) -> %s', (val, expected) => {
expect(toUpper(val)).toBe(expected)
})
})

0 comments on commit 699602e

Please sign in to comment.