diff --git a/readme.md b/readme.md index 3523406..f1f4f9c 100644 --- a/readme.md +++ b/readme.md @@ -25,5 +25,4 @@ import { Logger, LogFn, } from '@js/types'; - ``` diff --git a/src/functions.d.ts b/src/functions.d.ts new file mode 100644 index 0000000..7f0afd3 --- /dev/null +++ b/src/functions.d.ts @@ -0,0 +1,10 @@ + +export type Func = (...args: any[]) => T; + +export type Params = T extends (...args: infer P) => any ? P : never; + +export type FirstParam = T extends (first: infer F, ...args: any[]) => any ? F : never; + +export type NonFirstParams = T extends (first: any, ...args: infer P) => any ? P : never; + +export type WithoutFirstParam = T extends (first: any, ...args: infer P) => infer R ? (...args: P) => R : never; diff --git a/src/identifiers.d.ts b/src/identifiers.d.ts index 7e0d388..dee212a 100644 --- a/src/identifiers.d.ts +++ b/src/identifiers.d.ts @@ -1,6 +1,12 @@ +/** An HTTP URL, e.g. `https://example.com/foo?bar=baz` */ export type HttpURL = `http://${string}` | `https://${string}`; +/** An HTTP URL without the scheme specified, e.g. `//example.com/foo?bar=baz` */ +export type HttpURLSchemeless = `//${string}`; + +/** An RFC 4122 Universally Unique Identifier string */ export type UUID = `${string}-${string}-${string}-${string}-${string}`; +/** A Snowflake unique identifier string */ export type SnowflakeID = `${bigint}`; diff --git a/src/index.d.ts b/src/index.d.ts index aa0cc5a..98a7efd 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,7 @@ +export * from './functions'; export * from './http'; export * from './identifiers'; +export * from './locale'; export * from './logger'; +export * from './time'; diff --git a/src/locale.d.ts b/src/locale.d.ts new file mode 100644 index 0000000..194a740 --- /dev/null +++ b/src/locale.d.ts @@ -0,0 +1,3 @@ + +/** A combined ISO 639-1 language code and ISO 3166-1 alpha-2 country code, like `en-US` */ +export type Locale = `${string}-${string}`; diff --git a/src/time.d.ts b/src/time.d.ts new file mode 100644 index 0000000..9091524 --- /dev/null +++ b/src/time.d.ts @@ -0,0 +1,21 @@ + +/** A date string, formatted `YYYY-MM-DD` */ +export type ISODate = `${number}-${number}-${number}`; + +/** A time string, formatted `HH:mm:ss.sss` */ +export type ISOTime = `${number}:${number}:${number}.${number}`; + +/** */ +export type ISOZoneOffset = 'Z' | `${'+' | '-' | ''}${number}:${number}`; + +/** */ +export type ISOTimestamp = `${ISODate}T${ISOTime}${ISOZoneOffset}`; + +/** A time string, formatted `HH:mm` */ +export type TimeShort = `${number}:${number}`; + +/** A date/time string, formatted `YYYY-MM-DD HH:mm` */ +export type LocalDateTime = `${ISODate} ${TimeShort}`; + +/** A timezone identifier string, like `America/Los_Angeles` */ +export type Timezone = `${string}/${string}`;