@lambda-fn/basis
- AbstractConstructor
- AnyAbstractConstructor
- AnyConstructor
- AnyFn
- AsBoolean
- AsFactory
- AsFunction
- AsString
- Conditional
- Constructor
- Equal
- Falsy
- Fn
- Keys
- LiteralBase
- LiteralUnion
- NRecord
- Opaque
- Primitive
- Recalculate
- SRecord
- SelectByKeyValue
- SelectivePartial
- SelectiveRequired
- StrongBigint
- StrongBoolean
- StrongNumber
- StrongPropertyDescriptor
- StrongPropertyDescriptorMap
- StrongString
- URecord
- UnboundFn
- UnboundVoidFn
- UnionToIntersection
- VoidFn
- False
- Opaque
- True
- asBoolean
- asFactory
- asFunction
- asString
- assert
- assign
- bind
- contextify
- create
- defineProperties
- defineProperty
- identity
- keys
- noop
- panic
- partial
- set
Ƭ AbstractConstructor<I
, Args
>: (...args
: Args
) => I
Name | Type |
---|---|
I |
I |
Args |
extends unknown [] |
• (...args
)
Helper for create abstract constructor signatures
Name | Type |
---|---|
...args |
Args |
Ƭ AnyAbstractConstructor<I
>: (...args
: any
[]) => I
Name | Type |
---|---|
I |
any |
• (...args
)
Helper for create abstract constructor type predicates
Name | Type |
---|---|
...args |
any [] |
Ƭ AnyConstructor<I
>: (...args
: any
[]) => I
Name | Type |
---|---|
I |
any |
• (...args
)
Helper for create constructor type predicates
Name | Type |
---|---|
...args |
any [] |
Ƭ AnyFn<R
>: (...args
: any
[]) => R
Name | Type |
---|---|
R |
any |
▸ (...args
): R
Helper for create function type predicates
Name | Type |
---|---|
...args |
any [] |
R
Ƭ AsBoolean<T
>: T
extends Falsy
? false
: true
Transform any input type to true or false representation
Name |
---|
T |
Ƭ AsFactory<I
, C
>: UnboundFn
<I
, ConstructorParameters
<C
>>
Transforms constructor signature to function signature
Name | Type |
---|---|
I |
I |
C |
extends AnyConstructor <I > |
Ƭ AsFunction<T
>: () => T
Name |
---|
T |
▸ (): T
Function representation of any type
T
Ƭ AsString<T
, Default
>: T
extends Exclude
<Primitive
, symbol
> ? `${T}` : T
extends {} ? Strong
<S
, string
, Default
> : Default
String representation of any type
Name | Type |
---|---|
T |
T |
Default |
extends string = string |
Ƭ Conditional<Condition
, TrueType
, FalseType
>: Condition
extends true
? TrueType
: FalseType
Checks condition is strongly true type
returns
2nd parameter if 1st parameter is true or 3rd parameter otherwise
Name | Type |
---|---|
Condition |
extends boolean |
TrueType |
TrueType |
FalseType |
never |
Ƭ Constructor<I
, Args
>: (...args
: Args
) => I
Name | Type |
---|---|
I |
I |
Args |
extends unknown [] |
• (...args
)
Helper for create constructor signatures
Name | Type |
---|---|
...args |
Args |
Ƭ Equal<A
, B
>: A
extends B
? B
extends A
? true
: false
: false
Checks two types are representation of the some type
Name |
---|
A |
B |
Ƭ Falsy: false
| 0
| 0n
| null
| undefined
| ""
May contains all possible falsy values
Notice: NaN is falsy value but hasn't literal type and not included in this type
Ƭ Fn<R
, Args
, This
>: unknown
extends This
? (...args
: Args
) => R
: (this
: This
, ...args
: Args
) => R
Helper for create function signatures
Name | Type |
---|---|
R |
R |
Args |
extends unknown [] |
This |
unknown |
Ƭ Keys<T
>: AsString
<Exclude
<keyof T
, symbol
>>[]
Strong variant of keyof
operator
Name |
---|
T |
Ƭ LiteralBase<Literal
>: { [K in keyof PrimitiveMap]: Literal extends PrimitiveMap[K] ? PrimitiveMap[K] : never }[keyof PrimitiveMap
]
Get base type from literal type
Name | Type |
---|---|
Literal |
extends Primitive |
Ƭ LiteralUnion<Literals
, Basis
>: Literals
| Basis
& {}
Create primitive type with IDE autocompletion for most used literals
Name | Type |
---|---|
Literals |
Literals |
Basis |
extends Primitive = LiteralBase <Literals & Primitive > |
Ƭ NRecord<T
>: Record
<number
, T
>
Shorthand for Record with number keys
Name | Type |
---|---|
T |
unknown |
Ƭ Opaque<T
, Tag
>: T
& {}
Name |
---|
T |
Tag |
Ƭ Primitive: PrimitiveMap
[keyof PrimitiveMap
]
Shorthand for all primitive types union
Ƭ Recalculate<T
>: T
extends unknown
? { [K in keyof T]: T[K] } : never
Recalculates type to simple representation
Name |
---|
T |
Ƭ SRecord<T
>: Record
<string
, T
>
Shorthand for Record with string keys
Name | Type |
---|---|
T |
unknown |
Ƭ SelectByKeyValue<T
, Key
, Value
>: Recalculate
<T
& { [_ in Key]: Value }>
Selects variants of union by key-value pair
Name | Type |
---|---|
T |
T |
Key |
extends keyof T |
Value |
extends T [Key ] |
Ƭ SelectivePartial<T
, K
>: Recalculate
<Required
<Pick
<T
, Exclude
<keyof T
, K
>>> & Partial
<Pick
<T
, K
>>>
Makes some keys of type optional
Name | Type |
---|---|
T |
T |
K |
extends keyof T |
Ƭ SelectiveRequired<T
, K
>: Recalculate
<Required
<Pick
<T
, K
>> & Partial
<Pick
<T
, Exclude
<keyof T
, K
>>>>
Makes some keys of type required
Name | Type |
---|---|
T |
T |
K |
extends keyof T |
Ƭ StrongBigint<Input
>: Strong
<Input
, bigint
, 0n
>
Checks input type is bigint
returns
input type if it is bigint or 0n otherwise
Name |
---|
Input |
Ƭ StrongBoolean<Input
>: Strong
<Input
, boolean
, false
>
Checks input type is boolean
returns
input type if it is boolean or false otherwise
Name |
---|
Input |
Ƭ StrongNumber<Input
>: Strong
<Input
, number
, 0
>
Checks input type is number
returns
input type if it is number or 0 otherwise
Name |
---|
Input |
Ƭ StrongPropertyDescriptor<T
, K
>: {} | {} | {}
Strong variant of PropertyDescriptor
Name | Type |
---|---|
T |
T |
K |
extends keyof T |
Ƭ StrongPropertyDescriptorMap<T
>: { [K in keyof T]?: StrongPropertyDescriptor<T, K> }
Strong variant of PropertyDescriptorMap
Name |
---|
T |
Ƭ StrongString<Input
>: Strong
<Input
, string
, AsString
<Input
, ""
>>
Checks input type is string
returns
input type if it is string or '' otherwise
Name |
---|
Input |
Ƭ URecord<T
>: Record
<PropertyKey
, T
>
Shorthand for Record with any possible keys
Name | Type |
---|---|
T |
unknown |
Ƭ UnboundFn<R
, Args
>: Fn
<R
, Args
, void
>
Helper for create unbound (this: void)
function signatures
Name | Type |
---|---|
R |
R |
Args |
extends unknown [] |
Ƭ UnboundVoidFn<Args
>: Fn
<void
, Args
, void
>
Helper for create unbound (this: void)
function signatures that returns void
Name | Type |
---|---|
Args |
extends unknown [] |
Ƭ UnionToIntersection<U
>: U
extends unknown
? Fn
<unknown
, [U
]> : never
extends Fn
<unknown
, [infer I]> ? I
: never
Transforms union of types to intersection of that types
Name |
---|
U |
Ƭ VoidFn<Args
, This
>: Fn
<void
, Args
, This
>
Helper for create function signatures that returns void
Name | Type |
---|---|
Args |
extends unknown [] |
This |
unknown |
▸ False(): false
Functional representation of false
false
always false
▸ Opaque<T
, Tag
>(): OpaqueFactory
<T
, Tag
>
Create wrapper for attach opaque type to value
Name |
---|
T |
Tag |
OpaqueFactory
<T
, Tag
>
▸ True(): true
Functional representation of true
true
always true
▸ asBoolean<T
>(value
): AsBoolean
<T
>
Transform any value to boolean representation with strong types
Notice: for NaN it returns false with type true
see
Falsy
Name |
---|
T |
Name | Type | Description |
---|---|---|
value |
T |
Any value to transform |
AsBoolean
<T
>
true of false
▸ asFactory<I
, C
>(constructor
): AsFactory
<I
, C
>
Transforms constructor to factory
example
class A {}
const createA = asFactory(A);
// Valid and returns instance of A
const a = createA();
Name | Type |
---|---|
I |
I |
C |
extends AnyConstructor <I > |
Name | Type | Description |
---|---|---|
constructor |
C |
Any non abstract constructor |
AsFactory
<I
, C
>
Function with some params but callable without new operator
▸ asFunction<T
>(value
): AsFunction
<T
>
Transforms any value to function that always returns this value
Name |
---|
T |
Name | Type |
---|---|
value |
T |
AsFunction
<T
>
▸ asString<T
>(value
): AsString
<T
, string
>
Convert any value to string representation with strong types
Name |
---|
T |
Name | Type |
---|---|
value |
T |
AsString
<T
, string
>
▸ assert(condition
, message
, errorConstructor?
): asserts condition
Asserts condition is true
throws
Error if condition is false
Name | Type | Description |
---|---|---|
condition |
boolean |
Condition |
message |
string |
- |
errorConstructor? |
ErrorConstructor |
- |
asserts condition
▸ assert(condition
, error
): asserts condition
Asserts condition is true
throws
Error if condition is false
Name | Type | Description |
---|---|---|
condition |
boolean |
Condition |
error |
Error |
- |
asserts condition
▸ assign<Target
, Sources
>(target
, ...sources
): UnionToIntersection
<Target
| Sources
[number
]>
Object.assign
with strong types
Name | Type |
---|---|
Target |
Target |
Sources |
extends URecord <unknown >[] |
Name | Type |
---|---|
target |
Target |
...sources |
Sources |
UnionToIntersection
<Target
| Sources
[number
]>
▸ bind<R
, Args
, This
>(f
, thisArg
): (...args
: Args
) => R
Wrap function to unbounded variant
Name | Type |
---|---|
R |
R |
Args |
extends unknown [] |
This |
This |
Name | Type | Description |
---|---|---|
f |
Fn <R , Args , This > |
Any function |
thisArg |
This |
Context (this ) for function f |
fn
Unbounded function
▸ (...args
): R
Name | Type |
---|---|
...args |
Args |
R
▸ contextify<R
, Args
, This
>(f
): Fn
<R
, Args
, This
>
Wrap function to bounded variant
example
const originalMethod = SomeClass.prototype.method;
SomeClass.prototype.method = contextify((self: SomeClass, arg: string) => {
// ... some patch ...
return originalMethod.call(self, arg);
});
Name | Type |
---|---|
R |
R |
Args |
extends unknown [] |
This |
This |
Name | Type | Description |
---|---|---|
f |
(...args : [This , ...Args[]]) => R |
Any function |
Fn
<R
, Args
, This
>
Function that calls original function with this as 1st argument
▸ create<I
, C
>(constructor
, ...args
): I
Helper for create instance from constructor
Name | Type |
---|---|
I |
I |
C |
extends AnyConstructor <I > |
Name | Type | Description |
---|---|---|
constructor |
C |
Any non abstract constructor |
...args |
ConstructorParameters <C > |
constructor arguments |
I
created instance
▸ defineProperties<T
>(target
, properties
): T
Object.defineProperties
with strong types
Name |
---|
T |
Name | Type |
---|---|
target |
T |
properties |
StrongPropertyDescriptorMap <T > |
T
▸ defineProperty<T
, K
>(target
, property
, descriptor
): T
Object.defineProperty
with strong types
Name | Type |
---|---|
T |
T |
K |
extends string | number | symbol |
Name | Type |
---|---|
target |
T |
property |
K |
descriptor |
StrongPropertyDescriptor <T , K > |
T
▸ identity<T
>(value
): T
Returns argument
Name |
---|
T |
Name | Type |
---|---|
value |
T |
T
▸ keys<T
>(target
, includeNonEnumerable?
): Keys
<T
>
Object.keys
/ Object.getOwnPropertyNames
with strong types
Name |
---|
T |
Name | Type | Default value | Description |
---|---|---|---|
target |
T |
undefined |
Any object |
includeNonEnumerable |
boolean |
false |
Set it to true for include non enumerable keys |
Keys
<T
>
Keys array
▸ noop(): void
It's doing nothing
void
▸ panic(message
, errorConstructor?
): never
Shorthand for throw error
Name | Type |
---|---|
message |
string |
errorConstructor? |
ErrorConstructor |
never
▸ panic(error
): never
Shorthand for throw error
Name | Type |
---|---|
error |
Error |
never
▸ partial<R
, A1
, A2
, This
>(f
, ...args1
): Fn
<R
, A2
, This
>
Partial application
Name | Type |
---|---|
R |
R |
A1 |
extends unknown [] |
A2 |
extends unknown [] |
This |
unknown |
Name | Type | Description |
---|---|---|
f |
Fn <R , [...A1[], ...A2[]], This > |
Any function |
...args1 |
A1 |
1st part of function arguments |
Fn
<R
, A2
, This
>
Function with 2nd part of function arguments
▸ set<T
, K
>(target
, key
, value
): T
Helper for set property to object
Name | Type |
---|---|
T |
extends EmptyObject |
K |
extends string | number | symbol |
Name | Type | Description |
---|---|---|
target |
T |
Any object |
key |
K |
Object property key |
value |
T [K ] |
Property value |
T
target