-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types):
TimestampFormat
, Timestamp
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
3632179
commit 35fdbd3
Showing
5 changed files
with
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Type Tests - TimestampFormat | ||
* @module tutils/types/tests/unit-d/TimestampFormat | ||
*/ | ||
|
||
import type TestSubject from '../timestamp-format' | ||
|
||
describe('unit-d:types/TimestampFormat', () => { | ||
it('should extract "iso"', () => { | ||
expectTypeOf<TestSubject>().extract<'iso'>().not.toBeNever() | ||
}) | ||
|
||
it('should extract "unix"', () => { | ||
expectTypeOf<TestSubject>().extract<'unix'>().not.toBeNever() | ||
}) | ||
}) |
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,24 @@ | ||
/** | ||
* @file Type Tests - Timestamp | ||
* @module tutils/types/tests/unit-d/Timestamp | ||
*/ | ||
|
||
import type { tag } from '../opaque' | ||
import type TestSubject from '../timestamp' | ||
import type TimestampFormat from '../timestamp-format' | ||
|
||
describe('unit-d:types/Timestamp', () => { | ||
it('should extend number if Format extends "unix"', () => { | ||
expectTypeOf<TestSubject<'unix'>>().toMatchTypeOf<number>() | ||
}) | ||
|
||
it('should extend string if Format extends "iso"', () => { | ||
expectTypeOf<TestSubject<'iso'>>().toMatchTypeOf<string>() | ||
}) | ||
|
||
it('should match [readonly [tag]: "$timestamp"]', () => { | ||
expectTypeOf<TestSubject<TimestampFormat>>().toMatchTypeOf<{ | ||
readonly [tag]: '$timestamp' | ||
}>() | ||
}) | ||
}) |
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,14 @@ | ||
/** | ||
* @file Type Definitions - TimestampFormat | ||
* @module tutils/types/TimestampFormat | ||
*/ | ||
|
||
/** | ||
* Timestamp formats. | ||
* | ||
* @see https://en.wikipedia.org/wiki/ISO_8601 | ||
* @see https://unixtimestamp.com | ||
*/ | ||
type TimestampFormat = 'iso' | 'unix' | ||
|
||
export type { TimestampFormat as default } |
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,26 @@ | ||
/** | ||
* @file Type Definitions - Timestamp | ||
* @module tutils/types/Timestamp | ||
*/ | ||
|
||
import type NumberString from './number-string' | ||
import type Opaque from './opaque' | ||
import type TimestampFormat from './timestamp-format' | ||
|
||
/** | ||
* An [ISO 8601][1] or [unix][2] timestamp. | ||
* | ||
* [1]: https://en.wikipedia.org/wiki/ISO_8601 | ||
* [2]: https://unixtimestamp.com | ||
* | ||
* @see {@linkcode TimestampFormat} | ||
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date | ||
* | ||
* @template Format - Timestamp format | ||
*/ | ||
type Timestamp<Format extends TimestampFormat> = Opaque< | ||
Format extends 'unix' ? number : Format extends 'iso' ? string : NumberString, | ||
'$timestamp' | ||
> | ||
|
||
export type { Timestamp as default } |