Skip to content

Commit

Permalink
feat(utils): isDate
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed May 16, 2023
1 parent 469f4ac commit 0690a24
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/__tests__/is-date.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file Type Tests - isDate
* @module tutils/utils/tests/unit-d/isDate
*/

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

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

import testSubject from '../is-date'

describe('unit:utils/isDate', () => {
it('should return false if value is not Date instance', () => {
expect(testSubject(faker.date.anytime().toISOString())).to.be.false
})

it('should return true if value is Date instance', () => {
expect(testSubject(faker.date.anytime())).to.be.true
})
})
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { default as isArray } from './is-array'
export { default as isBigInt } from './is-big-int'
export { default as isBoolean } from './is-boolean'
export { default as isBooleanish } from './is-booleanish'
export { default as isDate } from './is-date'
export { default as isEmptyString } from './is-empty-string'
export { default as isEmptyValue } from './is-empty-value'
export { default as isFloat } from './is-float'
Expand Down
18 changes: 18 additions & 0 deletions src/utils/is-date.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Utilities - isDate
* @module tutils/utils/isDate
*/

import isObject from './is-object'

/**
* Checks if `value` is a {@linkcode Date} instance.
*
* @param {unknown} value - Value to check
* @return {value is Date} `true` if `value` is {@linkcode Date} instance
*/
function isDate(value: unknown): value is Date {
return isObject(value) && Reflect.get(value, 'constructor') === Date
}

export default isDate

0 comments on commit 0690a24

Please sign in to comment.