From b0d99425868d6887905bc68892691acd8dc4b676 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 7 May 2024 11:32:05 +0200 Subject: [PATCH] feat: :label: add utility types --- types.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 types.ts diff --git a/types.ts b/types.ts new file mode 100644 index 0000000..ec9ddd5 --- /dev/null +++ b/types.ts @@ -0,0 +1,28 @@ +import { JsonValue } from '@std/json' + +export type UUID = `${string}-${string}-${string}-${string}-${string}` +export type DateString = + `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z"` +export type Login = `${string}.${string}` +export type MailAddress = `${string}@${string}.${string}` + +export type ToJson = T extends JsonValue ? T + : T extends { toJSON(): unknown } ? ReturnType + : T extends { toJSON(): unknown }[] + ? { [K: number]: ReturnType } + : never + +export type MethodOf = { + [P in keyof Pick]: never +} + +export type Serializable = { + [key in Exclude]: + ToJson +} + +export type Posix = { + id: number + home: string + shell: string +}