more types

This commit is contained in:
James Brumond 2023-08-26 13:49:57 -07:00
parent 2eea0e09c4
commit 065a29f0cc
Signed by: james
GPG Key ID: E8F2FC44BAA3357A
6 changed files with 43 additions and 1 deletions

View File

@ -25,5 +25,4 @@ import {
Logger,
LogFn,
} from '@js/types';
```

10
src/functions.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export type Func<T extends any = any> = (...args: any[]) => T;
export type Params<T extends Func> = T extends (...args: infer P) => any ? P : never;
export type FirstParam<T extends Func> = T extends (first: infer F, ...args: any[]) => any ? F : never;
export type NonFirstParams<T extends Func> = T extends (first: any, ...args: infer P) => any ? P : never;
export type WithoutFirstParam<T extends Func> = T extends (first: any, ...args: infer P) => infer R ? (...args: P) => R : never;

View File

@ -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}`;

3
src/index.d.ts vendored
View File

@ -1,4 +1,7 @@
export * from './functions';
export * from './http';
export * from './identifiers';
export * from './locale';
export * from './logger';
export * from './time';

3
src/locale.d.ts vendored Normal file
View File

@ -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}`;

21
src/time.d.ts vendored Normal file
View File

@ -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}`;