@thi.ng/api
- Version 8.11.11
- Published
- 124 kB
- No dependencies
- Apache-2.0 license
Install
npm i @thi.ng/api
yarn add @thi.ng/api
pnpm add @thi.ng/api
Overview
Common, generic types, interfaces & mixins
Index
Variables
Functions
- always()
- asGLType()
- asInt()
- asNativeType()
- asyncIdentity()
- configurable()
- deprecated()
- deref()
- identity()
- IEnableMixin()
- IGrid1DMixin()
- IGrid2DMixin()
- IGrid3DMixin()
- IGrid4DMixin()
- inotify_dispatch()
- INotifyMixin()
- intTypeForBits()
- intTypeForSize()
- isDeref()
- iterable()
- IWatchMixin()
- mixin()
- narrowFloat()
- narrowInt()
- narrowType()
- narrowUint()
- never()
- NO_OP()
- nomixin()
- sealed()
- sizeOf()
- typedArray()
- typedArrayOfVec()
- typedArrayType()
- uintTypeForBits()
- uintTypeForSize()
- widenFloat()
- widenInt()
- widenType()
- widenUint()
Interfaces
Enums
Type Aliases
- Always
- ArrayLikeIterable
- ArrayValue
- AsyncPredicate
- AsyncPredicate2
- AsyncStatefulPredicate
- AsyncStatefulPredicate2
- BigIntArrayConstructor
- BigType
- BigTypedArray
- ButLast
- Comparator
- DeepArrayValue
- DeepPartial
- DeepPath
- Derefed
- DerefedKeys
- FloatArray
- FloatArrayConstructor
- FloatType
- Fn
- Fn0
- Fn0A
- Fn10
- Fn2
- Fn3
- Fn4
- Fn5
- Fn6
- Fn7
- Fn8
- Fn9
- FnA
- FnA10
- FnA2
- FnA3
- FnA4
- FnA5
- FnA6
- FnA7
- FnA8
- FnA9
- FnAny
- FnAnyA
- FnAnyT
- FnN
- FnN10
- FnN2
- FnN3
- FnN4
- FnN5
- FnN6
- FnN7
- FnN8
- FnN9
- FnO
- FnO10
- FnO2
- FnO3
- FnO4
- FnO5
- FnO6
- FnO7
- FnO8
- FnO9
- FnU
- FnU10
- FnU2
- FnU3
- FnU4
- FnU5
- FnU6
- FnU7
- FnU8
- FnU9
- Head
- IntArray
- IntArrayConstructor
- IntType
- IsEmpty
- IsOpt
- IsOptPath
- Keys
- Keys1
- Keys2
- Keys3
- Keys4
- Keys5
- Keys6
- Keys7
- Keys8
- KeysN
- Last
- Listener
- Maybe
- MaybeAsyncGenerator
- MaybeAsyncIterable
- MaybeDeref
- MaybePromise
- Nullable
- NumericArray
- NumericKeys
- NumOrString
- OptPathVal
- OptVal
- Pair
- Path
- Path0
- Path1
- Path2
- Path3
- Path4
- Path5
- Path6
- Path7
- Path8
- PathVal
- Predicate
- Predicate2
- Prepend
- Primitive
- Range
- Range0_1
- Range0_15
- Range0_23
- Range0_3
- Range0_31
- Range0_47
- Range0_63
- Range0_7
- Range1_16
- Range1_2
- Range1_24
- Range1_32
- Range1_4
- Range1_48
- Range1_64
- Range1_8
- Range16_23
- Range16_31
- Range32_47
- Range32_63
- Range4_7
- Range48_63
- Range8_15
- Replace
- Replace2
- Replace3
- Replace4
- Replace5
- Replace6
- Replace7
- Replace8
- ReplaceN
- Reverse
- Select2
- Select3
- Select4
- SomeRequired
- StatefulPredicate
- StatefulPredicate2
- StringKeys
- StringOrSym
- Tail
- Tuple
- TupleLength
- Type
- TypedArray
- TypedArrayConstructor
- TypedKeys
- UIntArray
- UIntArrayConstructor
- UintType
- Val1
- Val2
- Val3
- Val4
- Val5
- Val6
- Val7
- Val8
- ValN
- Values
- Watch
- Without
- Without2
- Without3
- Without4
- Without5
- Without6
- Without7
- Without8
- WithoutN
Variables
variable BIGINT_ARRAY_CTORS
const BIGINT_ARRAY_CTORS: Record<BigType, BigIntArrayConstructor>;
variable BIT_SHIFTS
const BIT_SHIFTS: { i8: number; u8: number; u8c: number; i16: number; u16: number; i32: number; u32: number; i64: number; u64: number; f32: number; f64: number;};
variable DEFAULT_EPS
const DEFAULT_EPS: number;
variable EVENT_ALL
const EVENT_ALL: string;
Catch-all event ID
variable EVENT_DISABLE
const EVENT_DISABLE: string;
variable EVENT_ENABLE
const EVENT_ENABLE: string;
variable FLOAT_ARRAY_CTORS
const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
variable GL2TYPE
const GL2TYPE: Record<GLType, Type>;
variable INT_ARRAY_CTORS
const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
variable SIZEOF
const SIZEOF: { u8: number; u8c: number; i8: number; u16: number; i16: number; u32: number; i32: number; i64: number; u64: number; f32: number; f64: number;};
variable TYPE2GL
const TYPE2GL: Record<Type, GLType>;
variable TYPEDARRAY_CTORS
const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
variable UINT_ARRAY_CTORS
const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
Functions
function always
always: () => boolean;
Zero-arg function always returning true.
function asGLType
asGLType: (type: GLType | Type) => GLType;
Returns suitable GLType enum of
type
.Parameter type
Example 1
import { asGLType, GLType } from "@thi.ng/api";console.log(asGLType("f32"));// 5126 (aka GLType.F32)console.log(asGLType(GLType.F32));// 5126 (aka GLType.F32)
function asInt
asInt: (...args: number[]) => number[];
Coerces given numeric args to integer values.
function asNativeType
asNativeType: (type: GLType | Type) => Type;
function asyncIdentity
asyncIdentity: <T>(x: T) => Promise<T>;
Async version of identity.
Parameter x
function configurable
configurable: (state: boolean) => MethodDecorator;
Property decorator factory. Sets
configurable
flag of PropertyDescriptor to given state.Parameter state
true, if propoerty is configurable
function deprecated
deprecated: ( msg?: string, log?: { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void }) => MethodDecorator;
Method property decorator factory. Augments original method with deprecation message (via console), shown when method is invoked. Accepts optional message arg. Throws error if assigned property is not a function.
Parameter msg
deprecation message
function deref
deref: <T>(x: MaybeDeref<T>) => T;
If
x
implements IDeref, returns its wrapped value, else returnsx
itself.Parameter x
function identity
identity: <T>(x: T) => T;
Identity function:
(x) => x
Parameter x
function IEnableMixin
IEnableMixin: (clazz: any) => any;
Mixin class decorator, injects IEnable default implementation, incl. a
_enabled
property. If the target also implements the INotify interface, IEnable.enable and IEnable.disable will automatically emit the respective events.
function IGrid1DMixin
IGrid1DMixin: (clazz: any) => any;
Default implementation for IGrid1D methods.
function IGrid2DMixin
IGrid2DMixin: (clazz: any) => any;
Default implementation for IGrid2D methods.
function IGrid3DMixin
IGrid3DMixin: (clazz: any) => any;
Default implementation for IGrid3D methods.
function IGrid4DMixin
IGrid4DMixin: (clazz: any) => any;
Default implementation for IGrid4D methods.
function inotify_dispatch
inotify_dispatch: (listeners: any[][], e: Event) => boolean;
function INotifyMixin
INotifyMixin: (clazz: any) => any;
Mixin class decorator, injects INotify default implementation, incl. a lazily instantiated
_listeners
property object, storing registered listeners.
function intTypeForBits
intTypeForBits: (x: number) => IntType;
Returns suitable IntType for given bit size (
[0,32]
range)Parameter x
function intTypeForSize
intTypeForSize: (x: number) => IntType;
Returns the smallest possible *signed* int type enum for given
x
. E.g. ifx >= -128 && x < 128
, the function returns"i8"
.Parameter x
value to classify
function isDeref
isDeref: (x: any) => x is IDeref<any>;
Returns true iff
x
implements IDeref.Parameter x
function iterable
iterable: (prop: PropertyKey) => (clazz: any) => any;
function IWatchMixin
IWatchMixin: (clazz: any) => any;
function mixin
mixin: (behaviour: any, sharedBehaviour?: any) => (clazz: any) => any;
Class behavior mixin based on: - http://raganwald.com/2015/06/26/decorators-in-es7.html
Additionally only injects/overwrites properties in target, which are NOT marked with [
@nomixin
](https://docs.thi.ng/umbrella/api/functions/nomixin.html) (i.e. those which haven't set theirconfigurable
property descriptor flag tofalse
)Parameter behaviour
to mixin
Parameter sharedBehaviour
Returns
decorator function
function narrowFloat
narrowFloat: (t: FloatType) => string;
Returns the next smaller FloatType for given type (or the same type if already the narrowest).
Parameter t
function narrowInt
narrowInt: (t: IntType | 'i64') => 'i8' | 'i16' | 'i32';
Returns the next smaller IntType for given type (or the same type if already the narrowest).
Parameter t
function narrowType
narrowType: (t: Type | BigType) => string;
function narrowUint
narrowUint: (t: UintType | 'u64') => 'u8' | 'u16' | 'u32';
Returns the next smaller UintType for given type (or the same type if already the narrowest).
Parameter t
Remarks
If type is
u8c
, returnsu8
.
function never
never: () => boolean;
Zero-arg function always returning false.
function NO_OP
NO_OP: () => void;
No-effect placeholder function.
function nomixin
nomixin: (_: any, __: string, descriptor: PropertyDescriptor) => void;
Method property decorator. Sets
configurable
flag of PropertyDescriptor tofalse
(same as@configurable(false)
). Intended to be used in combination with mixin decorators to enable partial implementations of mixed-in behaviors in target class and avoid them being overidden by mixed-in behaviour.
function sealed
sealed: (constructor: Function) => void;
Class decorator. Seals both constructor and prototype.
Parameter constructor
class ctor to seal
function sizeOf
sizeOf: (type: Type | BigType | GLType) => number;
function typedArray
typedArray: { <T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T]; <T extends Type | GLType>( type: T, src: ArrayLike<number> | ArrayBufferLike ): TypedArrayTypeMap[T]; <T extends Type | GLType>( type: T, buf: ArrayBufferLike, byteOffset: number, length?: number ): TypedArrayTypeMap[T]; <T extends BigType>(type: T, length: number): BigTypedArrayTypeMap[T]; <T extends BigType>( type: T, src: ArrayBufferLike | ArrayLike<bigint> ): BigTypedArrayTypeMap[T]; <T extends BigType>( type: T, buf: ArrayBufferLike, byteOffset: number, length?: number ): BigTypedArrayTypeMap[T];};
function typedArrayOfVec
typedArrayOfVec: { <T extends Type | GLType>( type: T, data: Iterable<ArrayLike<number>>, stride?: number ): TypedArrayTypeMap[T]; <T extends BigType>( type: T, data: Iterable<ArrayLike<bigint>>, stride?: number ): BigTypedArrayTypeMap[T];};
Constructs a typed array for given
type
and populates it with given vector values.Parameter type
Parameter data
Parameter stride
Remarks
The size of the array will be
data.length * stride
, wherestride
is the number of elements per item and defaulting to the size of the first data item/vector given.Example 1
import { typedArrayOfVec } from "@thi.ng/api";// inferred stride=2 (2d vectors)console.log(typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]]));// Float32Array(6) [ 1, 2, 3, 4, -10, 20 ]// with custom stride=4console.log(typedArrayOfVec("f32", [[1,2], [3,4], [-10,20]], 4));// Float32Array(12) [ 1, 2, 0, 0, 3,4, 0, 0, -10, 20, 0, 0 ]
function typedArrayType
typedArrayType: (x: NumericArray) => Type;
Takes an NumericArray and returns its corresponding Type ID. Standard JS arrays will default to "f64".
Parameter x
function uintTypeForBits
uintTypeForBits: (x: number) => UintType;
Returns suitable UintType for given bit size (
[0,32]
range)Parameter x
function uintTypeForSize
uintTypeForSize: (x: number) => UintType;
Returns the smallest possible *unsigned* int type enum for given
x
. E.g. ifx <= 256
, the function returns"u8"
.Parameter x
value to classify
function widenFloat
widenFloat: (t: FloatType) => string;
Returns the next larger FloatType for given type (or the same type if already the widest).
Parameter t
function widenInt
widenInt: (t: IntType) => 'i16' | 'i32' | 'i64';
Returns the next larger IntType for given type (or the same type if already the widest).
Parameter t
function widenType
widenType: (t: Type | BigType) => string;
function widenUint
widenUint: (t: UintType) => 'u16' | 'u32' | 'u64';
Returns the next larger UintType for given type (or the same type if already the widest).
Parameter t
Interfaces
interface BigTypedArrayTypeMap
interface BigTypedArrayTypeMap extends Record<BigType, BigTypedArray> {}
interface Event
interface Event<T extends string = string> extends IID<T> {}
Event type used in combination with INotify.
interface IAssoc
interface IAssoc<K, V, T> {}
Parameter K
key type
Parameter V
value type
Parameter T
return type
interface IAssocIn
interface IAssocIn<K, V, T> {}
Parameter K
key type
Parameter V
value type
Parameter T
return type
interface IBind
interface IBind<T> {}
Generic resource binding methods.
interface IBuffered
interface IBuffered<T> {}
Generic interface for types with binary backing buffers.
interface ICompare
interface ICompare<T> {}
Generic interface to compare value types.
method compare
compare: (x: T) => number;
Compares this value with given value
x
. MUST follow same contract as Comparator.Parameter x
compare value
Remarks
MUST return 0 if the type also implements
IEquiv
andequiv
returns true for samex
.Also see IHash.
interface IContains
interface IContains<T> {}
Generic interface for collection types to check if a given value is part of the collection.
method contains
contains: (x: T) => boolean;
Returns
true
ifx
is part of collection.Parameter x
value to check for
interface ICopy
interface ICopy<T> {}
Generic interface for clonable types.
method copy
copy: () => T;
Returns a copy of this instance. Shallow or deep copies are implementation specific.
interface IDeref
interface IDeref<T> {}
Generic interface for reference types (value wrappers).
method deref
deref: () => T;
Returns wrapped value.
interface IDissoc
interface IDissoc<K, V, T> extends IAssoc<K, V, T> {}
Extension of
IAssoc
for types supporting key removals.Parameter K
key type
Parameter V
value type
Parameter T
return type
method dissoc
dissoc: (key: K) => T;
interface IDissocIn
interface IDissocIn<K, V, T> extends IAssocIn<K, V, T> {}
Extension of
IAssocIn
for types supporting key removals.Parameter K
key type
Parameter V
value type
Parameter T
return type
method dissocIn
dissocIn: (key: K[]) => T;
interface IEmpty
interface IEmpty<T> {}
method empty
empty: () => T;
Returns an empty/blank instance of same type (with possibly same config, if any).
interface IEnable
interface IEnable<T> {}
Interface to provide enabled/disabled functionality. Also see
@IEnable
decorator mixinParameter T
type for enable/disable option arg
interface IEqualsDelta
interface IEqualsDelta<T> {}
Parameter T
value type
method eqDelta
eqDelta: (o: T, eps?: number) => boolean;
Returns
true
if this value equalso
with optional allowance for given toleranceeps
.Parameter o
2nd value to test
Parameter eps
tolerance (usually defaults to
DEFAULT_EPS
)
interface IEquiv
interface IEquiv {}
method equiv
equiv: (o: any) => boolean;
Returns
true
if this *value* is equivalent too
. Also see [ICompare.compare](https://docs.thi.ng/umbrella/api/interfaces/ICompare.html#compare) and [IHash.hash](https://docs.thi.ng/umbrella/api/interfaces/IHash.html#hash).Parameter o
value to check for equivalence
interface IGet
interface IGet<K, V> {}
Parameter K
key type
Parameter V
value type
method get
get: (key: K, notfound?: V) => Maybe<V>;
interface IGetIn
interface IGetIn<K, V> {}
Parameter K
key type
Parameter V
value type
method getIn
getIn: (key: K[], notfound?: V) => Maybe<V>;
interface IGrid1D
interface IGrid1D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {}
Gridlike container for 1D accessible data.
Remarks
See IGrid1DMixin for mixin implementation.
property dim
readonly dim: 1;
method getAt
getAt: (d0: number) => T;
Returns value at given position. If outside the grid's defined region, returns a suitable zero value.
Parameter d0
method getAtUnsafe
getAtUnsafe: (d0: number) => T;
Non-boundschecked version of IGrid1D.getAt. Assumes given position is valid.
Parameter d0
method includes
includes: (d0: number) => boolean;
Returns true if given position is valid (i.e. within grid bounds).
Parameter d0
method indexAt
indexAt: (d0: number) => number;
Returns index for given position. Returns negative value if outside the grid's defined region.
Parameter d0
method indexAtUnsafe
indexAtUnsafe: (d0: number) => number;
Non-boundschecked version of IGrid1D.indexAt. Assumes given position is valid.
Parameter d0
method setAt
setAt: (d0: number, value: T) => boolean;
Writes value at given position. Has no effect if outside of the defined region. Returns true, if succeeded.
Parameter d0
Parameter value
method setAtUnsafe
setAtUnsafe: (d0: number, value: T) => boolean;
Non-boundschecked version of IGrid1D.setAt. Assumes given position is valid. Returns true, if succeeded.
Parameter d0
Parameter value
interface IGrid2D
interface IGrid2D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {}
Gridlike container for 2D accessible data.
Remarks
See IGrid2DMixin for mixin implementation.
property dim
readonly dim: 2;
method getAt
getAt: (d0: number, d1: number) => T;
Returns value at given position (given in same order as IGrid2D.size and IGrid2D.stride). If outside the grid's defined region, returns a suitable zero value.
Parameter d0
Parameter d1
method getAtUnsafe
getAtUnsafe: (d0: number, d1: number) => T;
Non-boundschecked version of IGrid2D.getAt. Assumes given position is valid.
Parameter d0
Parameter d1
method includes
includes: (d0: number, d1: number) => boolean;
Returns true if given position is valid (i.e. within grid bounds).
Parameter d0
Parameter d1
method indexAt
indexAt: (d0: number, d1: number) => number;
Returns index for given position (stated in same order as IGrid2D.size and IGrid2D.stride). Returns negative value if outside the grid's defined region.
Parameter d0
Parameter d1
method indexAtUnsafe
indexAtUnsafe: (d0: number, d1: number) => number;
Non-boundschecked version of IGrid2D.indexAt. Assumes given position is valid.
Parameter d0
Parameter d1
method setAt
setAt: (d0: number, d1: number, value: T) => boolean;
Writes value at given position (given in same order as IGrid2D.size and IGrid2D.stride). Has no effect if outside of the defined region. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter value
method setAtUnsafe
setAtUnsafe: (d0: number, d1: number, value: T) => boolean;
Non-boundschecked version of IGrid2D.setAt. Assumes given position is valid. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter value
interface IGrid3D
interface IGrid3D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {}
Gridlike container for 3D accessible data.
Remarks
See IGrid3DMixin for mixin implementation.
property dim
readonly dim: 3;
method getAt
getAt: (d0: number, d1: number, d2: number) => T;
Returns value at given position (given in same order as IGrid3D.size and IGrid3D.stride). If outside the grid's defined region, returns a suitable zero value.
Parameter d0
Parameter d1
Parameter d2
method getAtUnsafe
getAtUnsafe: (d0: number, d1: number, d2: number) => T;
Non-boundschecked version of IGrid3D.getAt. Assumes given position is valid.
Parameter d0
Parameter d1
Parameter d2
method includes
includes: (d0: number, d1: number, d2: number) => boolean;
Returns true if given position is valid (i.e. within grid bounds).
Parameter d0
Parameter d1
Parameter d2
method indexAt
indexAt: (d0: number, d1: number, d2: number) => number;
Returns index for given position (stated in same order as IGrid3D.size and IGrid3D.stride). Returns negative value if outside the grid's defined region.
Parameter d0
Parameter d1
Parameter d2
method indexAtUnsafe
indexAtUnsafe: (d0: number, d1: number, d2: number) => number;
Non-boundschecked version of IGrid3D.indexAt. Assumes given position is valid.
Parameter d0
Parameter d1
Parameter d2
method setAt
setAt: (d0: number, d1: number, d2: number, value: T) => boolean;
Writes value at given position (given in same order as IGrid3D.size and IGrid3D.stride). Has no effect if outside of the defined region. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter d2
Parameter value
method setAtUnsafe
setAtUnsafe: (d0: number, d1: number, d2: number, value: T) => boolean;
Non-boundschecked version of IGrid3D.setAt. Assumes given position is valid. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter d2
Parameter value
interface IGrid4D
interface IGrid4D<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {}
Gridlike container for 4D accessible data.
Remarks
See IGrid4DMixin for mixin implementation.
property dim
readonly dim: 4;
method getAt
getAt: (d0: number, d1: number, d2: number, d3: number) => T;
Returns value at given position (given in same order as IGrid4D.size and IGrid4D.stride). If outside the grid's defined region, returns a suitable zero value.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
method getAtUnsafe
getAtUnsafe: (d0: number, d1: number, d2: number, d3: number) => T;
Non-boundschecked version of IGrid4D.getAt. Assumes given position is valid.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
method includes
includes: (d0: number, d1: number, d2: number, d3: number) => boolean;
Returns true if given position is valid (i.e. within grid bounds).
Parameter d0
Parameter d1
Parameter d2
Parameter d3
method indexAt
indexAt: (d0: number, d1: number, d2: number, d3: number) => number;
Returns index for given position (stated in same order as IGrid4D.size and IGrid4D.stride). Returns negative value if outside the grid's defined region.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
method indexAtUnsafe
indexAtUnsafe: (d0: number, d1: number, d2: number, d3: number) => number;
Non-boundschecked version of IGrid4D.indexAt. Assumes given position is valid.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
method setAt
setAt: (d0: number, d1: number, d2: number, d3: number, value: T) => boolean;
Writes value at given position (given in same order as IGrid4D.size and IGrid4D.stride). Has no effect if outside of the defined region. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
Parameter value
method setAtUnsafe
setAtUnsafe: ( d0: number, d1: number, d2: number, d3: number, value: T) => boolean;
Non-boundschecked version of IGrid4D.setAt. Assumes given position is valid. Returns true, if succeeded.
Parameter d0
Parameter d1
Parameter d2
Parameter d3
Parameter value
interface IGridND
interface IGridND<BUF extends any[] | TypedArray = any[], T = any> extends INDBase<BUF> {}
method getAt
getAt: ( ...pos: | [number] | [number, number] | [number, number, number] | [number, number, number, number]) => T;
Returns value at given position. If outside the grid's defined region, returns a suitable zero value.
Parameter pos
method getAtUnsafe
getAtUnsafe: ( ...pos: | [number] | [number, number] | [number, number, number] | [number, number, number, number]) => T;
Non-boundschecked version of IGridND.getAt. Assumes given position is valid.
Parameter pos
method includes
includes: ( ...pos: | [number] | [number, number] | [number, number, number] | [number, number, number, number]) => boolean;
Returns true if given position is valid (i.e. within grid bounds).
Parameter pos
method indexAt
indexAt: ( ...pos: | [number] | [number, number] | [number, number, number] | [number, number, number, number]) => number;
Returns index for given position. Returns negative value if outside the grid's defined region.
Parameter pos
method indexAtUnsafe
indexAtUnsafe: ( ...pos: | [number] | [number, number] | [number, number, number] | [number, number, number, number]) => number;
Non-boundschecked version of IGridND.indexAt. Assumes given position is valid.
Parameter pos
method setAt
setAt: ( ...args: | [number, T] | [number, number, T] | [number, number, number, T] | [number, number, number, number, T]) => boolean;
Writes value at given position. Has no effect if outside of the defined region. Returns true, if succeeded.
Parameter args
method setAtUnsafe
setAtUnsafe: ( ...args: | [number, T] | [number, number, T] | [number, number, number, T] | [number, number, number, number, T]) => boolean;
Non-boundschecked version of IGridND.setAt. Assumes given position is valid. Returns true, if succeeded.
Parameter args
interface IHash
interface IHash<T> {}
Interface for hashable types.
method hash
hash: () => T;
Returns a value's hash code. The contract of this function is: If
IEquiv.equiv
returnstrue
for two values, their hash codes MUST also be equal.
interface IIDGen
interface IIDGen<T> {}
Common minimal base interface for ID generators.
interface IIndexed
interface IIndexed<T> {}
Interface for collection types which can be accessed via numeric index.
method nth
nth: (i: number, notfound: T) => T;
interface IInto
interface IInto<V, T> {}
Interface for collection types supporting addition of multiple values.
method into
into: (coll: Iterable<V>) => T;
interface ILength
interface ILength {}
length
property declaration for collections to obtain their element count.
property length
readonly length: number;
interface IMeta
interface IMeta<T> {}
Generic interface for types supporting metadata. Implementations MUST exclude metadata from any comparisons, equality checks & hashing.
interface INDBase
interface INDBase<BUF extends any[] | TypedArray = any[]> {}
interface INotify
interface INotify<T extends string = string> {}
Interface to provide event emitter functionality. Also see INotifyMixin decorator mixin.
The type param
T
can be used to constrain the event type/id.
method addListener
addListener: (id: T, fn: Listener<T>, scope?: any) => boolean;
method notify
notify: (event: Event<T>) => boolean;
Broadcasts all registered listeners for given event type (in order registration) and returns true if any of them have been successfully notified.
Parameter event
Remarks
If a listener canceled the event (by setting Event.canceled), the function will stop notifying other listeners and return false. If no listeners are registered for the event, the function will also return false.
method removeListener
removeListener: (id: T, fn: Listener<T>, scope?: any) => boolean;
interface IObjectOf
interface IObjectOf<T> {}
Generic plain object with all key values of given type.
index signature
[id: string]: T;
interface IRelease
interface IRelease {}
Interface for types supported the release of internal resources.
method release
release: (opt?: any) => boolean;
interface IReset
interface IReset {}
Interface for types supporting some form of internal state reset.
method reset
reset: () => this;
interface ISeq
interface ISeq<T> {}
Lisp-like sequence abstraction for arbitrary types using
first
&next
operations only.Remarks
Unlike ES6 iterators this approach does not conflate both operations and
first()
can be called any number of times to obtain the current value (if any) from the sequence.
method first
first: () => Maybe<T>;
Returns the sequence's first value or
undefined
if there're no further values.Remarks
If the sequence is guaranteed to not include
undefined
values, a simple check forseq.first() === undefined
is sufficient to determine the end. If the sequence DOES containundefined
values, the check should useseq.next()
.
method next
next: () => Maybe<ISeq<T>>;
Returns a new sequence of the remaining elements or
undefined
if there're no further values.Remarks
In general, implementations of this interface MUST always return a new sequence instance and not mutate some internal cursor. I.e.
seq.next() !== seq
interface ISet
interface ISet<V, T> extends IInto<V, T> {}
Generic interface for set collection types.
Parameter V
value type
Parameter T
return type
interface IStack
interface IStack<V, P, S> {}
Generic interface for collections implementing stack functionality.
Parameter V
value type
Parameter P
return type for pop()
Parameter S
return type for push()
interface IToHiccup
interface IToHiccup {}
method toHiccup
toHiccup: (ctx?: any, attribs?: any, ...args: any[]) => any;
Returns a [thi.ng/hiccup](https://thi.ng/hiccup) compatible representation. The optional
ctx
arg is an arbitrary user context object passed to all hiccup components during serialization (or during DOM creation / update if used with [thi.ng/hdom](https://thi.ng/hdom)).Parameter ctx
user context object
Parameter attribs
user attribs
Parameter args
additional args
interface IWatch
interface IWatch<T> {}
Interface for types offering observers of internal value changes. Also see
@IWatch
decorator mixin.
method addWatch
addWatch: (id: string, fn: Watch<T>) => boolean;
method notifyWatches
notifyWatches: (oldState: T, newState: T) => void;
method removeWatch
removeWatch: (id: string) => boolean;
interface RangeValueMap
interface RangeValueMap {}
Type LUT of allowed range values
[0..n)
for given range sizen
.Example 1
RangeValueMap[4] -> 0 | 1 | 2 | 3
property 1
1: 0;
property 10
10: Range0_7 | 8 | 9;
property 11
11: Range0_7 | 8 | 9 | 10;
property 12
12: Range0_7 | 8 | 9 | 10 | 11;
property 13
13: Range0_7 | 8 | 9 | 10 | 11 | 12;
property 14
14: Range0_7 | 8 | 9 | 10 | 11 | 12 | 13;
property 15
15: Range0_7 | 8 | 9 | 10 | 11 | 12 | 13 | 14;
property 16
16: Range0_15;
property 17
17: Range0_15 | 16;
property 18
18: Range0_15 | 16 | 17;
property 19
19: Range0_15 | 16 | 17 | 18;
property 2
2: Range0_1;
property 20
20: Range0_15 | 16 | 17 | 18 | 19;
property 21
21: Range0_15 | 16 | 17 | 18 | 19 | 20;
property 22
22: Range0_15 | 16 | 17 | 18 | 19 | 20 | 21;
property 23
23: Range0_15 | 16 | 17 | 18 | 19 | 20 | 21 | 22;
property 24
24: Range0_15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23;
property 25
25: Exclude<Range0_31, 25 | 26 | 27 | 28 | 29 | 30 | 31>;
property 26
26: Exclude<Range0_31, 26 | 27 | 28 | 29 | 30 | 31>;
property 27
27: Exclude<Range0_31, 27 | 28 | 29 | 30 | 31>;
property 28
28: Exclude<Range0_31, 28 | 29 | 30 | 31>;
property 29
29: Exclude<Range0_31, 29 | 30 | 31>;
property 3
3: Range0_1 | 2;
property 30
30: Exclude<Range0_31, 30 | 31>;
property 31
31: Exclude<Range0_31, 31>;
property 32
32: Range0_31;
property 33
33: Range0_31 | 32;
property 34
34: Range0_31 | 32 | 33;
property 35
35: Range0_31 | 32 | 33 | 34;
property 36
36: Range0_31 | 32 | 33 | 34 | 35;
property 37
37: Range0_31 | 32 | 33 | 34 | 35 | 36;
property 38
38: Range0_31 | 32 | 33 | 34 | 35 | 36 | 37;
property 39
39: Range0_31 | 32 | 33 | 34 | 35 | 36 | 37 | 38;
property 4
4: Range0_3;
property 40
40: Range0_31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39;
property 41
41: Exclude<Range0_47, 41 | 42 | 43 | 44 | 45 | 46 | 47>;
property 42
42: Exclude<Range0_47, 42 | 43 | 44 | 45 | 46 | 47>;
property 43
43: Exclude<Range0_47, 43 | 44 | 45 | 46 | 47>;
property 44
44: Exclude<Range0_47, 44 | 45 | 46 | 47>;
property 45
45: Exclude<Range0_47, 45 | 46 | 47>;
property 46
46: Exclude<Range0_47, 46 | 47>;
property 47
47: Exclude<Range0_47, 47>;
property 48
48: Range0_47;
property 49
49: Range0_47 | 48;
property 5
5: Range0_3 | 4;
property 50
50: Range0_47 | 48 | 49;
property 51
51: Range0_47 | 48 | 49 | 50;
property 52
52: Range0_47 | 48 | 49 | 50 | 51;
property 53
53: Range0_47 | 48 | 49 | 50 | 51 | 52;
property 54
54: Range0_47 | 48 | 49 | 50 | 51 | 52 | 53;
property 55
55: Range0_47 | 48 | 49 | 50 | 51 | 52 | 53 | 54;
property 56
56: Range0_47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55;
property 57
57: Exclude<Range0_63, 57 | 58 | 59 | 60 | 61 | 62 | 63>;
property 58
58: Exclude<Range0_63, 58 | 59 | 60 | 61 | 62 | 63>;
property 59
59: Exclude<Range0_63, 59 | 60 | 61 | 62 | 63>;
property 6
6: Range0_3 | 4 | 5;
property 60
60: Exclude<Range0_63, 60 | 61 | 62 | 63>;
property 61
61: Exclude<Range0_63, 61 | 62 | 63>;
property 62
62: Exclude<Range0_63, 62 | 63>;
property 63
63: Exclude<Range0_63, 63>;
property 64
64: Range0_63;
property 7
7: Range0_3 | 4 | 5 | 6;
property 8
8: Range0_7;
property 9
9: Range0_7 | 8;
interface TypedArrayTypeMap
interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {}
property [GLType.F32]
[GLType.F32]: Float32Array;
property [GLType.I16]
[GLType.I16]: Int16Array;
property [GLType.I32]
[GLType.I32]: Int32Array;
property [GLType.I8]
[GLType.I8]: Int8Array;
property [GLType.U16]
[GLType.U16]: Uint16Array;
property [GLType.U32]
[GLType.U32]: Uint32Array;
property [GLType.U8]
[GLType.U8]: Uint8Array;
property f32
f32: Float32Array;
property f64
f64: Float64Array;
property i16
i16: Int16Array;
property i32
i32: Int32Array;
property i8
i8: Int8Array;
property u16
u16: Uint16Array;
property u32
u32: Uint32Array;
property u8
u8: Uint8Array;
property u8c
u8c: Uint8ClampedArray;
Enums
enum GLType
enum GLType { I8 = 5120, U8 = 5121, I16 = 5122, U16 = 5123, I32 = 5124, U32 = 5125, F32 = 5126,}
Type Aliases
type Always
type Always<T> = T extends undefined ? never : T;
Similar to
NonNullable
, but only excludesundefined
.
type ArrayLikeIterable
type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
type ArrayValue
type ArrayValue<T extends unknown[]> = T[0];
Returns an array's value type. Assumes array is homogeneous (only type of first element will be considered).
type AsyncPredicate
type AsyncPredicate<T> = FnA<T, boolean>;
type AsyncPredicate2
type AsyncPredicate2<T> = FnA2<T, T, boolean>;
type AsyncStatefulPredicate
type AsyncStatefulPredicate<T> = Fn0<AsyncPredicate<T>>;
type AsyncStatefulPredicate2
type AsyncStatefulPredicate2<T> = Fn0<AsyncPredicate2<T>>;
type BigIntArrayConstructor
type BigIntArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
type BigType
type BigType = 'i64' | 'u64';
type BigTypedArray
type BigTypedArray = BigInt64Array | BigUint64Array;
type ButLast
type ButLast<T extends unknown[], C extends unknown[] = []> = { 0: ButLast<Tail<T>, Prepend<Head<T>, C>>; 1: Reverse<C>;}[IsEmpty<Tail<T>>];
Extracts everything except the last element from a tuple.
type Comparator
type Comparator<T> = Fn2<T, T, number>;
Generic 2-element comparator function type alias.
Remarks
Must follow this contract and return:
- negative if
a < b
- zero ifa == b
- positive ifa > b
type DeepArrayValue
type DeepArrayValue<T> = T extends unknown[] ? DeepArrayValue<T[0]> : T extends TypedArray ? number : T;
Somewhat similar, but recursive version of ArrayValue. If
T
is an array/typedarray recursively descends into it or (if not an array) returnsT
. Assumes arrays at each level are homogeneous (only type of first elements will be considered).
type DeepPartial
type DeepPartial<T> = Partial<{ [k in keyof T]: DeepPartial<T[k]>;}>;
type DeepPath
type DeepPath<T, A, B, C, D, E, F, G, H> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? H extends Keys7<T, A, B, C, D, E, F, G> ? readonly [A, B, C, D, E, F, G, H, ...NumOrString[]] : never : never : never : never : never : never : never : never;
Semi-typechecked lookup path (depth > 8). Only the first 8 levels are checked.
type Derefed
type Derefed<T> = T extends IDeref<any> ? ReturnType<T['deref']> : T;
If
T
is a IDeref, returns its value type or elseT
.
type DerefedKeys
type DerefedKeys<T extends IObjectOf<any>, K extends keyof T = keyof T> = { [P in K]: Derefed<T[P]>;};
Constructs a type with a set of properties
K
of typeT
and attempts to resolve each given key via Derefed.Example 1
import type { DerefedKeys, IDeref } from "@thi.ng/api";interface Foo {a: IDeref<string>;b: IDeref<number>;c: { d: number };}type Foo2 = DerefedKeys<Foo>;// { a: string; b: number; c: { d: number; } }type Foo3 = DerefedKeys<Foo, "b">;// { b: number; }
type FloatArray
type FloatArray = Float32Array | Float64Array;
type FloatArrayConstructor
type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
type FloatType
type FloatType = 'f32' | 'f64';
type Fn
type Fn<A, B> = (a: A) => B;
A single arg function from A to B.
type Fn0
type Fn0<T> = () => T;
A no-arg function, returning T.
type Fn0A
type Fn0A<A> = Fn0<Promise<A>>;
type Fn10
type Fn10<A, B, C, D, E, F, G, H, I, J, K> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) => K;
A 10-arg function from A,B,C,D,E,F,G,H,I,J to K.
type Fn2
type Fn2<A, B, C> = (a: A, b: B) => C;
A 2-arg function from A,B to C.
type Fn3
type Fn3<A, B, C, D> = (a: A, b: B, c: C) => D;
A 3-arg function from A,B,C to D.
type Fn4
type Fn4<A, B, C, D, E> = (a: A, b: B, c: C, d: D) => E;
A 4-arg function from A,B,C,D to E.
type Fn5
type Fn5<A, B, C, D, E, F> = (a: A, b: B, c: C, d: D, e: E) => F;
A 5-arg function from A,B,C,D,E to F.
type Fn6
type Fn6<A, B, C, D, E, F, G> = (a: A, b: B, c: C, d: D, e: E, f: F) => G;
A 6-arg function from A,B,C,D,E,F to G.
type Fn7
type Fn7<A, B, C, D, E, F, G, H> = (a: A, b: B, c: C, d: D, e: E, f: F, g: G) => H;
A 7-arg function from A,B,C,D,E,F,G to H.
type Fn8
type Fn8<A, B, C, D, E, F, G, H, I> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) => I;
A 8-arg function from A,B,C,D,E,F,G,H to I.
type Fn9
type Fn9<A, B, C, D, E, F, G, H, I, J> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) => J;
A 9-arg function from A,B,C,D,E,F,G,H,I to J.
type FnA
type FnA<A, B> = Fn<A, Promise<B>>;
type FnA10
type FnA10<A, B, C, D, E, F, G, H, I, J, K> = Fn10< A, B, C, D, E, F, G, H, I, J, Promise<K>>;
type FnA2
type FnA2<A, B, C> = Fn2<A, B, Promise<C>>;
type FnA3
type FnA3<A, B, C, D> = Fn3<A, B, C, Promise<D>>;
type FnA4
type FnA4<A, B, C, D, E> = Fn4<A, B, C, D, Promise<E>>;
type FnA5
type FnA5<A, B, C, D, E, F> = Fn5<A, B, C, D, E, Promise<F>>;
type FnA6
type FnA6<A, B, C, D, E, F, G> = Fn6<A, B, C, D, E, F, Promise<G>>;
type FnA7
type FnA7<A, B, C, D, E, F, G, H> = Fn7<A, B, C, D, E, F, G, Promise<H>>;
type FnA8
type FnA8<A, B, C, D, E, F, G, H, I> = Fn8<A, B, C, D, E, F, G, H, Promise<I>>;
type FnA9
type FnA9<A, B, C, D, E, F, G, H, I, J> = Fn9<A, B, C, D, E, F, G, H, I, Promise<J>>;
type FnAny
type FnAny<T> = (...args: any[]) => T;
An untyped vararg arg function to type T.
type FnAnyA
type FnAnyA<T> = FnAny<Promise<T>>;
type FnAnyT
type FnAnyT<A, B> = (...args: A[]) => B;
A typed vararg arg function from A to B.
type FnN
type FnN = FnU<number>;
type FnN10
type FnN10 = FnU10<number>;
type FnN2
type FnN2 = FnU2<number>;
type FnN3
type FnN3 = FnU3<number>;
type FnN4
type FnN4 = FnU4<number>;
type FnN5
type FnN5 = FnU5<number>;
type FnN6
type FnN6 = FnU6<number>;
type FnN7
type FnN7 = FnU7<number>;
type FnN8
type FnN8 = FnU8<number>;
type FnN9
type FnN9 = FnU9<number>;
type FnO
type FnO<A, B> = (a: A, ...args: any[]) => B;
type FnO10
type FnO10<A, B, C, D, E, F, G, H, I, J, K> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J, ...args: any[]) => K;
type FnO2
type FnO2<A, B, C> = (a: A, b: B, ...args: any[]) => C;
type FnO3
type FnO3<A, B, C, D> = (a: A, b: B, c: C, ...args: any[]) => D;
type FnO4
type FnO4<A, B, C, D, E> = (a: A, b: B, c: C, d: D, ...args: any[]) => E;
type FnO5
type FnO5<A, B, C, D, E, F> = (a: A, b: B, c: C, d: D, e: E, ...args: any[]) => F;
type FnO6
type FnO6<A, B, C, D, E, F, G> = ( a: A, b: B, c: C, d: D, e: E, f: F, ...args: any[]) => G;
type FnO7
type FnO7<A, B, C, D, E, F, G, H> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, ...args: any[]) => H;
type FnO8
type FnO8<A, B, C, D, E, F, G, H, I> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, ...args: any[]) => I;
type FnO9
type FnO9<A, B, C, D, E, F, G, H, I, J> = ( a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, ...args: any[]) => J;
type FnU
type FnU<A, B = A> = Fn<A, B>;
1-arg function with arg of type A and return type B (defaults to A)
type FnU10
type FnU10<A, B = A> = Fn10<A, A, A, A, A, A, A, A, A, A, B>;
10-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU2
type FnU2<A, B = A> = Fn2<A, A, B>;
2-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU3
type FnU3<A, B = A> = Fn3<A, A, A, B>;
3-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU4
type FnU4<A, B = A> = Fn4<A, A, A, A, B>;
4-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU5
type FnU5<A, B = A> = Fn5<A, A, A, A, A, B>;
5-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU6
type FnU6<A, B = A> = Fn6<A, A, A, A, A, A, B>;
6-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU7
type FnU7<A, B = A> = Fn7<A, A, A, A, A, A, A, B>;
7-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU8
type FnU8<A, B = A> = Fn8<A, A, A, A, A, A, A, A, B>;
8-arg function with all args uniformly of type A and return type B (defaults to A)
type FnU9
type FnU9<A, B = A> = Fn9<A, A, A, A, A, A, A, A, A, B>;
9-arg function with all args uniformly of type A and return type B (defaults to A)
type Head
type Head<T extends unknown[]> = T extends [infer A, ...unknown[]] ? A : never;
Extracts the first element of a tuple.
type IntArray
type IntArray = Int8Array | Int16Array | Int32Array;
type IntArrayConstructor
type IntArrayConstructor = | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
type IntType
type IntType = 'i8' | 'i16' | 'i32';
type IsEmpty
type IsEmpty<T extends unknown[]> = T extends [] ? 1 : 0;
Returns 1 if T is empty tuple, else 0
type IsOpt
type IsOpt<T> = T extends undefined ? true : never;
Returns true if
T
includes undefined.
type IsOptPath
type IsOptPath<T, P extends unknown[]> = P extends [] ? never : IsOptR<T, Head<P>, Tail<P>>;
Returns true if given path contains any intermediate properties declared as optional in type
T
.Reference: https://stackoverflow.com/q/60869412/294515
type Keys
type Keys<T> = keyof Required<T>;
type Keys1
type Keys1<T, A extends Keys<T>> = Keys<Required<T>[A]>;
type Keys2
type Keys2<T, A extends Keys<T>, B extends Keys1<T, A>> = Keys1<Required<T>[A], B>;
type Keys3
type Keys3< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>> = Keys2<Required<T>[A], B, C>;
type Keys4
type Keys4< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>> = Keys3<Required<T>[A], B, C, D>;
type Keys5
type Keys5< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>> = Keys4<Required<T>[A], B, C, D, E>;
type Keys6
type Keys6< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>> = Keys5<Required<T>[A], B, C, D, E, F>;
type Keys7
type Keys7< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>> = Keys6<Required<T>[A], B, C, D, E, F, G>;
type Keys8
type Keys8< T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, H extends Keys7<T, A, B, C, D, E, F, G>> = Keys7<Required<T>[A], B, C, D, E, F, G, H>;
type KeysN
type KeysN<T, L extends unknown[]> = L extends [] ? Keys<T> : KeysNReducer<T, Head<L>, Tail<L>>;
Generalised version of Keys0 - Keys7.
type Last
type Last<T extends unknown[]> = { 0: Last<Tail<T>>; 1: Head<T>;}[IsEmpty<Tail<T>>];
Extracts the last element from a tuple.
type Listener
type Listener<T extends string = string> = Fn<Event<T>, void>;
Event listener for Event.
type Maybe
type Maybe<T> = T | undefined;
type MaybeAsyncGenerator
type MaybeAsyncGenerator<T> = IterableIterator<T> | AsyncIterableIterator<T>;
type MaybeAsyncIterable
type MaybeAsyncIterable<T> = Iterable<T> | AsyncIterable<T>;
type MaybeDeref
type MaybeDeref<T> = IDeref<T> | T;
type MaybePromise
type MaybePromise<T> = T | Promise<T>;
type Nullable
type Nullable<T> = T | null | undefined;
type NumericArray
type NumericArray = number[] | TypedArray;
type NumericKeys
type NumericKeys<T> = TypedKeys<T, number>;
type NumOrString
type NumOrString = number | string;
type OptPathVal
type OptPathVal<T, P extends unknown[]> = OptVal<IsOptPath<T, P>, ValN<T, P>>;
Similar to PathVal, but also takes into account if given path contains any intermediate properties declared as optional in type
T
. If that's the case, returns union ofundefined
and inferred value for path, else just the latter.Context & reference: https://stackoverflow.com/q/60869412/294515
type OptVal
type OptVal<PRED, RES> = [PRED] extends [never] ? RES : Maybe<RES>;
Returns
RES
ifPRED
isnever
, elseMaybe<RES>
type Pair
type Pair<K, V> = [K, V];
A key-value pair / tuple.
type Path
type Path = readonly NumOrString[] | NumOrString;
Unchecked lookup path for nested data structures.
type Path0
type Path0 = readonly [];
Empty lookup path.
type Path1
type Path1<T, A> = A extends Keys<T> ? readonly [A] : never;
Type checked lookup path (depth 1)
type Path2
type Path2<T, A, B> = A extends Keys<T> ? B extends Keys1<T, A> ? readonly [A, B] : never : never;
Type checked lookup path (depth 2)
type Path3
type Path3<T, A, B, C> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? readonly [A, B, C] : never : never : never;
Type checked lookup path (depth 3)
type Path4
type Path4<T, A, B, C, D> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? readonly [A, B, C, D] : never : never : never : never;
Type checked lookup path (depth 4)
type Path5
type Path5<T, A, B, C, D, E> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? readonly [A, B, C, D, E] : never : never : never : never : never;
Type checked lookup path (depth 5)
type Path6
type Path6<T, A, B, C, D, E, F> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? readonly [A, B, C, D, E, F] : never : never : never : never : never : never;
Type checked lookup path (depth 6)
type Path7
type Path7<T, A, B, C, D, E, F, G> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? readonly [A, B, C, D, E, F, G] : never : never : never : never : never : never : never;
Type checked lookup path (depth 7)
type Path8
type Path8<T, A, B, C, D, E, F, G, H> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? H extends Keys7<T, A, B, C, D, E, F, G> ? readonly [A, B, C, D, E, F, G, H] : never : never : never : never : never : never : never : never;
Type checked lookup path (depth 8)
type PathVal
type PathVal<T, P extends unknown[]> = ValN<T, P>;
Returns nested value type for given path into
T
ornever
if path is incompatible withT
.
type Predicate
type Predicate<T> = Fn<T, boolean>;
Predicate function mapping given value to true/false.
type Predicate2
type Predicate2<T> = Fn2<T, T, boolean>;
Predicate function mapping given args to true/false.
type Prepend
type Prepend<T, U extends unknown[]> = [T, ...U];
Adds an element at the start of an tuple.
type Primitive
type Primitive = NumOrString | boolean | symbol;
type Range
type Range = [number, number];
type Range0_1
type Range0_1 = 0 | 1;
type Range0_15
type Range0_15 = Range0_7 | Range8_15;
type Range0_23
type Range0_23 = Range0_15 | Range16_23;
type Range0_3
type Range0_3 = Range0_1 | 2 | 3;
type Range0_31
type Range0_31 = Range0_15 | Range16_31;
type Range0_47
type Range0_47 = Range0_31 | Range32_47;
type Range0_63
type Range0_63 = Range0_31 | Range32_63;
type Range0_7
type Range0_7 = Range0_3 | Range4_7;
type Range1_16
type Range1_16 = Range1_8 | Range8_15 | 16;
type Range1_2
type Range1_2 = 1 | 2;
type Range1_24
type Range1_24 = Range1_16 | Range16_23 | 24;
type Range1_32
type Range1_32 = Range1_16 | Range16_31 | 32;
type Range1_4
type Range1_4 = Range1_2 | 3 | 4;
type Range1_48
type Range1_48 = Range1_32 | Range32_47 | 48;
type Range1_64
type Range1_64 = Range1_32 | Range32_63 | 64;
type Range1_8
type Range1_8 = Range1_4 | Range4_7 | 8;
type Range16_23
type Range16_23 = 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23;
type Range16_31
type Range16_31 = Range16_23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31;
type Range32_47
type Range32_47 = | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47;
type Range32_63
type Range32_63 = Range32_47 | Range48_63;
type Range4_7
type Range4_7 = 4 | 5 | 6 | 7;
type Range48_63
type Range48_63 = | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63;
type Range8_15
type Range8_15 = 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
type Replace
type Replace<T, A extends Keys<T>, V> = Without<T, A> & { [id in A]: V;};
Utilities for replacing types of nested keys.
type Replace2
type Replace2