Vangware's Types

Build Status License NPM Version Open Issues

🏷️ Vangware shared types.

Collection of TypeScript types to be used as base for development of other libraries.

Documentation

Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.

Changelog

Changelog can be found HERE.

Index

Array Type aliases

Empty

Empty<Type>: Type extends ReadOnlyArray ? EmptyArray : Type extends ReadOnlyRecord ? EmptyRecord : Type extends string ? EmptyString : never

Empty array, object or string.

Type parameters

EmptyArray

EmptyArray: readonly []

Empty array.

Entries

Entries<Key, Value>: ReadonlyArray<Entry<Key, Value>>

Array of Entry.

Type parameters

  • Key = PropertyKey

  • Value = unknown

EntriesOf

EntriesOf<Input>: Entries<KeyOf<Input>, ValueOf<Input>>

Array of EntryOf.

Type parameters

Entry

Entry<Key, Value>: readonly [key: Key, value: Value]

Entry couple [key, value].

Type parameters

  • Key = PropertyKey

  • Value = unknown

EntryKey

EntryKey<Input>: Input[0]

Entry key.

Type parameters

EntryOf

EntryOf<Input>: Entry<KeyOf<Input>, ValueOf<Input>>

Entry of given array or object.

Type parameters

EntryValue

EntryValue<Input>: Input[1]

Entry value.

Type parameters

Head

Head<Input>: HeadAndTail<Input>[0]

Initial value of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

HeadAndTail

HeadAndTail<Input>: Input extends readonly [infer Head, ...infer Tail] ? readonly [Head, Tail] : Input extends `${infer Head}${infer Tail}` ? readonly [Head, Tail] : Input extends EmptyArray | EmptyString ? readonly [undefined, Input] : readonly [Input[number] | undefined, Input]

Get a couple with the head and tail of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

Init

Init<Input>: InitAndLast<Input>[0]

Initial values of an array or string (omitting the last).

Type parameters

  • Input: ArrayLike<unknown>

InitAndLast

InitAndLast<Input>: Input extends readonly [...infer Init, infer Last] ? readonly [Init, Last] : Input extends EmptyArray | EmptyString ? readonly [Input, undefined] : Input extends `${infer Init}${infer Rest}` ? readonly [`${Rest extends EmptyString ? EmptyString : Init}${InitAndLast<Rest>[0]}`, `${Rest extends EmptyString ? Init : InitAndLast<Rest>[1]}`] : readonly [Input, Input[number] | undefined]

Get a couple with the initial and last values of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

KeyOf

KeyOf<Input>: Input extends ReadOnlyArray ? DefaultNever<Exclude<Partial<Input>["length"], Input["length"]>, number> : keyof Input extends Exclude<PropertyKey, symbol> ? `${keyof Input}` : never

Generic key for either object or array.

Type parameters

Last

Last<Input>: InitAndLast<Input>[1]

Last value of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

ReadOnlyArray

ReadOnlyArray<Item>: ReadonlyArray<Item>

Read-only array.

Type parameters

  • Item = unknown

Reducer

Reducer<Item, Accumulator>: Unary<Item, Unary<Accumulator, Accumulator>>

Reducer/Folder function.

Type parameters

  • Item

  • Accumulator

Sorter

Sorter<Item>: Unary<Item, Unary<Item, number>>

Sorter function.

Type parameters

  • Item

Tail

Tail<Input>: HeadAndTail<Input>[1]

Last values of an array or string (omitting the first).

Type parameters

  • Input: ArrayLike<unknown>

ValueOf

ValueOf<ArrayOrObject>: ArrayOrObject[KeyOf<ArrayOrObject>]

Generic key for either object or array.

Type parameters

Common Type aliases

DefaultNever

DefaultNever<Input, Default>: Monuple<Input> extends Monuple<never> ? Default : Input

Takes a value that could be never and turns it into the given Default.

Type parameters

  • Input

  • Default

Falsy

Falsy: EmptyString | 0 | 0n | 0 | 0n | false | undefined

Types that evaluates to false in JS.

Monuple

Monuple<Type>: readonly [Type]

Tuple of length 1.

Type parameters

  • Type

Primitive

Primitive: bigint | boolean | number | string | symbol | undefined

Valid JavaScript primitives (excluding null).

Truthy

Truthy<Actual>: Actual extends Falsy ? never : Actual

Generic type to check if value is not Falsy.

Type parameters

  • Actual = unknown

TypeOfMap

TypeOfMap: { bigint: bigint; boolean: boolean; number: number; object: ReadOnlyRecord; string: string; symbol: symbol; undefined: undefined; function: any }

typeof type map.

Type declaration

  • Readonly bigint: bigint
  • Readonly boolean: boolean
  • Readonly number: number
  • Readonly object: ReadOnlyRecord
  • Readonly string: string
  • Readonly symbol: symbol
  • Readonly undefined: undefined
  • function: function

TypeOfValue

TypeOfValue: keyof TypeOfMap

Possible type values returned by typeof.

Date Type aliases

ISODate

ISODate: `${number}-${ISOMonth}-${ISODay}T${number}:${number}:${number}.${number}Z`

String representing an ISO date.

ISODay

ISODay: `0${Exclude<Digit, 0>}` | `1${Digit}` | `2${Digit}` | `3${0 | 1}`

ISO day value ("01" to "31").

ISOMonth

ISOMonth: `0${Exclude<Digit, 0>}` | `1${0 | 1 | 2}`

ISO month value ("01" to "12").

Function Type aliases

Comparative

Comparative<Wanted, Received>: Unary<Wanted, Unary<Received, boolean>>

Unary function that takes a Wanted value and returns another Unary function that takes a Received value and returns a boolean.

Type parameters

  • Wanted

  • Received: Wanted = Wanted

Predicate

Predicate<Input, Predicated>: Unary<Input, boolean> | ((input: Input) => input is Predicated)

Unary function that returns a boolean.

Type parameters

  • Input

  • Predicated: Input = Input

Reducer

Reducer<Item, Accumulator>: Unary<Item, Unary<Accumulator, Accumulator>>

Reducer/Folder function.

Type parameters

  • Item

  • Accumulator

Sorter

Sorter<Item>: Unary<Item, Unary<Item, number>>

Sorter function.

Type parameters

  • Item

Unary

Unary<Input, Output>: (input: Input) => Output

Type parameters

  • Input

  • Output

Type declaration

    • (input: Input): Output
    • Unary function (takes a single value).

      Parameters

      • input: Input

      Returns Output

UnaryInput

UnaryInput<UnaryFunction>: UnaryFunction extends Unary<infer Input, unknown> ? Input : never

Unary input type.

Type parameters

  • UnaryFunction: Unary<never, unknown>

UnaryOutput

UnaryOutput<UnaryFunction>: UnaryFunction extends Unary<never, infer Output> ? Output : never

Unary output type.

Type parameters

  • UnaryFunction: Unary<never, unknown>

Number Type aliases

Digit

Digit: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Valid digits (0 to 9).

Object Type aliases

Empty

Empty<Type>: Type extends ReadOnlyArray ? EmptyArray : Type extends ReadOnlyRecord ? EmptyRecord : Type extends string ? EmptyString : never

Empty array, object or string.

Type parameters

EmptyRecord

EmptyRecord: ReadOnlyRecord<never>

Empty record (object).

Entries

Entries<Key, Value>: ReadonlyArray<Entry<Key, Value>>

Array of Entry.

Type parameters

  • Key = PropertyKey

  • Value = unknown

EntriesOf

EntriesOf<Input>: Entries<KeyOf<Input>, ValueOf<Input>>

Array of EntryOf.

Type parameters

Entry

Entry<Key, Value>: readonly [key: Key, value: Value]

Entry couple [key, value].

Type parameters

  • Key = PropertyKey

  • Value = unknown

EntryKey

EntryKey<Input>: Input[0]

Entry key.

Type parameters

EntryOf

EntryOf<Input>: Entry<KeyOf<Input>, ValueOf<Input>>

Entry of given array or object.

Type parameters

EntryValue

EntryValue<Input>: Input[1]

Entry value.

Type parameters

KeyOf

KeyOf<Input>: Input extends ReadOnlyArray ? DefaultNever<Exclude<Partial<Input>["length"], Input["length"]>, number> : keyof Input extends Exclude<PropertyKey, symbol> ? `${keyof Input}` : never

Generic key for either object or array.

Type parameters

ReadOnlyRecord

ReadOnlyRecord<Value, Key>: Readonly<Record<Key, Value>>

Read-only record.

Type parameters

  • Value = unknown

  • Key: PropertyKey = PropertyKey

ValueOf

ValueOf<ArrayOrObject>: ArrayOrObject[KeyOf<ArrayOrObject>]

Generic key for either object or array.

Type parameters

RegExp Type aliases

RegularExpression

RegularExpression: `/${string}/${RegularExpressionFlags}`

String representing a regular expression.

RegularExpressionFlags

RegularExpressionFlags: `${EmptyString | "g"}${EmptyString | "i"}${EmptyString | "m"}${EmptyString | "s"}u`

Possible combinations of regular expression flags (always unicode).

String Type aliases

Empty

Empty<Type>: Type extends ReadOnlyArray ? EmptyArray : Type extends ReadOnlyRecord ? EmptyRecord : Type extends string ? EmptyString : never

Empty array, object or string.

Type parameters

EmptyString

EmptyString: ""

Empty string.

Head

Head<Input>: HeadAndTail<Input>[0]

Initial value of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

HeadAndTail

HeadAndTail<Input>: Input extends readonly [infer Head, ...infer Tail] ? readonly [Head, Tail] : Input extends `${infer Head}${infer Tail}` ? readonly [Head, Tail] : Input extends EmptyArray | EmptyString ? readonly [undefined, Input] : readonly [Input[number] | undefined, Input]

Get a couple with the head and tail of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

Init

Init<Input>: InitAndLast<Input>[0]

Initial values of an array or string (omitting the last).

Type parameters

  • Input: ArrayLike<unknown>

InitAndLast

InitAndLast<Input>: Input extends readonly [...infer Init, infer Last] ? readonly [Init, Last] : Input extends EmptyArray | EmptyString ? readonly [Input, undefined] : Input extends `${infer Init}${infer Rest}` ? readonly [`${Rest extends EmptyString ? EmptyString : Init}${InitAndLast<Rest>[0]}`, `${Rest extends EmptyString ? Init : InitAndLast<Rest>[1]}`] : readonly [Input, Input[number] | undefined]

Get a couple with the initial and last values of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

Last

Last<Input>: InitAndLast<Input>[1]

Last value of an array or string.

Type parameters

  • Input: ArrayLike<unknown>

Tail

Tail<Input>: HeadAndTail<Input>[1]

Last values of an array or string (omitting the first).

Type parameters

  • Input: ArrayLike<unknown>