Skip to content

Commit

Permalink
feat(utils): isLowercase, isUppercase
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed May 16, 2023
1 parent 249e217 commit 45bccc7
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-lowercase.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isLowercase
* @module tutils/utils/tests/unit-d/isLowercase
*/

import type testSubject from '../is-lowercase'

describe('unit-d:utils/isLowercase', () => {
it('should guard Lowercase<T>', () => {
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Lowercase<string>>()
})
})
16 changes: 16 additions & 0 deletions src/utils/__tests__/is-lowercase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isLowercase
* @module tutils/utils/tests/unit/isLowercase
*/

import testSubject from '../is-lowercase'

describe('unit:utils/isLowercase', () => {
it('should return false if value is not lowercase string', () => {
expect(testSubject(faker.string.sample().toUpperCase())).to.be.false
})

it('should return true if value is lowercase string', () => {
expect(testSubject(faker.string.sample().toLowerCase())).to.be.true
})
})
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-uppercase.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isUppercase
* @module tutils/utils/tests/unit-d/isUppercase
*/

import type testSubject from '../is-uppercase'

describe('unit-d:utils/isUppercase', () => {
it('should guard Uppercase<T>', () => {
expectTypeOf<typeof testSubject>().guards.toEqualTypeOf<Uppercase<string>>()
})
})
16 changes: 16 additions & 0 deletions src/utils/__tests__/is-uppercase.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file Unit Tests - isUppercase
* @module tutils/utils/tests/unit/isUppercase
*/

import testSubject from '../is-uppercase'

describe('unit:utils/isUppercase', () => {
it('should return false if value is not uppercase string', () => {
expect(testSubject(faker.string.sample().toLowerCase())).to.be.false
})

it('should return true if value is uppercase string', () => {
expect(testSubject(faker.string.sample().toUpperCase())).to.be.true
})
})
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as isEmptyString } from './is-empty-string'
export { default as isEmptyValue } from './is-empty-value'
export { default as isFunction } from './is-function'
export { default as isJsonPrimitive } from './is-json-primitive'
export { default as isLowercase } from './is-lowercase'
export { default as isNIL } from './is-nil'
export { default as isNodeEnv } from './is-node-env'
export { default as isNull } from './is-null'
Expand All @@ -21,5 +22,6 @@ export { default as isPrimitive } from './is-primitive'
export { default as isString } from './is-string'
export { default as isSymbol } from './is-symbol'
export { default as isUndefined } from './is-undefined'
export { default as isUppercase } from './is-uppercase'
export { default as lowercase } from './lowercase'
export { default as uppercase } from './uppercase'
19 changes: 19 additions & 0 deletions src/utils/is-lowercase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Utilities - isLowercase
* @module tutils/utils/isLowercase
*/

import isString from './is-string'
import lowercase from './lowercase'

/**
* Checks if `value` is a lowercase string.
*
* @param {unknown} value - Value to check
* @return {value is Lowercase<string>} `true` if `value` is lowercase string
*/
const isLowercase = (value: unknown): value is Lowercase<string> => {
return isString(value) && value === lowercase(value)
}

export default isLowercase
19 changes: 19 additions & 0 deletions src/utils/is-uppercase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Utilities - isUppercase
* @module tutils/utils/isUppercase
*/

import isString from './is-string'
import uppercase from './uppercase'

/**
* Checks if `value` is an uppercase string.
*
* @param {unknown} value - Value to check
* @return {value is Uppercase<string>} `true` if `value` is uppercase string
*/
const isUppercase = (value: unknown): value is Uppercase<string> => {
return isString(value) && value === uppercase(value)
}

export default isUppercase

0 comments on commit 45bccc7

Please sign in to comment.