@robbiemu/handy-typescript / Modules
Ƭ ArrowFunction<Params, T>: () => T | (…args: Params) => T
| Name | Type |
|---|---|
Params |
extends unknown[] |
T |
T |
Ƭ Common<T, U>: Record<Extract<keyof T, keyof U>, U[Extract<keyof T, keyof U>]>
| Name |
|---|
T |
U |
Ƭ Comparator<T>: (value: T, index?: number, array?: T[]) => boolean | (value: T, index?: number, array?: T[]) => value is T
| Name |
|---|
T |
Ƭ Constructor: Partial<(…args: any[]) => any>
Constructor - a Class
Ƭ Dictionary<T>: Object
Dictionary - key-value pairs
| Name | Description |
|---|---|
T |
value type |
▪ [key: string]: T
Ƭ DummyableFactoryResponse: Function & { originalMethod?: Function }
src/decorators/dummyable.decorator.ts:66
Ƭ FixedSizeArray<N, T, M>: { readonly [k in M]: any } & { length: N } & ReadonlyArray<T>
simple fixed-size array type for typescript
| Name | Type |
|---|---|
N |
extends number |
T |
T |
M |
extends string = "0" |
src/utility/fixed-array-size.ts:5
Ƭ Reducer<T>: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => T
| Name |
|---|
T |
▸ (previousValue, currentValue, currentIndex, array): T
| Name | Type |
|---|---|
previousValue |
any |
currentValue |
any |
currentIndex |
number |
array |
any[] |
T
Ƭ StrictConstructor: (…args: any[]) => any
• new StrictConstructor(...args): any
| Name | Type |
|---|---|
...args |
any[] |
any
• Const generators: Object
| Name | Type |
|---|---|
combinations |
<T>(set: T[], k: number) => Generator<T[], T[], undefined> |
range |
(first: number, last?: number, byFn: ArrowFunction<any, number>) => Generator<number> |
src/utility/math-generators.ts:42
▸ After(afterFunction): (_targetClass: Partial<(…args: any[]) => any>, _propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor
decorator execute code after method completes
| Name | Type | Description |
|---|---|---|
afterFunction |
Function |
method to decorate TODO - add support for accessors |
fn
▸ (_targetClass, _propertyKey, descriptor): PropertyDescriptor
| Name | Type |
|---|---|
_targetClass |
Partial<(…args: any[]) => any> |
_propertyKey |
string | symbol |
descriptor |
PropertyDescriptor |
PropertyDescriptor
▸ Before(beforeFunction): (_targetClass: Partial<(…args: any[]) => any>, _propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor
Function
Before
Description
decorator to execute code before method execution
Todo
add support for accessors
| Name | Type | Description |
|---|---|---|
beforeFunction |
Function |
method to decorate |
fn
▸ (_targetClass, _propertyKey, descriptor): PropertyDescriptor
| Name | Type |
|---|---|
_targetClass |
Partial<(…args: any[]) => any> |
_propertyKey |
string | symbol |
descriptor |
PropertyDescriptor |
PropertyDescriptor
▸ Dummyable(conf): (_targetClass: Partial<(…args: any[]) => any>, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor
decorator that can replace and reuse a method
| Name | Type | Description |
|---|---|---|
conf |
DummyableConfig |
DummyableConfig |
fn
▸ (_targetClass, propertyKey, descriptor): PropertyDescriptor
| Name | Type |
|---|---|
_targetClass |
Partial<(…args: any[]) => any> |
propertyKey |
string | symbol |
descriptor |
PropertyDescriptor |
PropertyDescriptor
src/decorators/dummyable.decorator.ts:7
▸ InterruptingBefore(before): (target: Partial<(…args: any[]) => any>, propertyKey: string, descriptor: PropertyDescriptor) => void
decorator that executes arbitrary code before the underlying method. the function executed can optionally trigger the original method after, or interrupt its execution. it may opt to replace the parameters with an AopDecoratorPayload
| Name | Type | Description |
|---|---|---|
before |
Function |
method to optionally interrup t and execute before the method TODO - add support for accessors |
fn
▸ (target, propertyKey, descriptor): void
| Name | Type |
|---|---|
target |
Partial<(…args: any[]) => any> |
propertyKey |
string |
descriptor |
PropertyDescriptor |
void
src/aop/interrupting-before.decorator.ts:11
▸ LogMethods(config?): (target: any) => any
decorator to log method calls and the paramters passed
| Name | Type | Description |
|---|---|---|
config |
LogMethodsConfig |
logging configuration |
fn
▸ (target): any
| Name | Type |
|---|---|
target |
any |
any
src/decorators/log-methods.decorator.ts:19
▸ Mixin(...classes): ClassDecorator
| Name | Type |
|---|---|
...classes |
Function[] |
ClassDecorator
src/decorators/mixin.decorator.ts:25
▸ Stateful<T>(): ClassDecorator
| Name |
|---|
T |
ClassDecorator
src/decorators/stateful.decorator.ts:27
▸ add(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
▸ assert(condition, msg?): asserts condition
assert a condition or throw
| Name | Type | Description |
|---|---|---|
condition |
any |
boolean to assert |
msg? |
string |
optional message to throw on error |
asserts condition
▸ cleanStringify(item): string
stringify possibly circular references
| Name | Type | Description |
|---|---|---|
item |
any |
value to stringify cleanly |
string
json-like string without circular references
src/utility/clean-stringify.ts:8
▸ combinations<T>(set, k): T[][]
Function
combinations
Description
derrive combinations of length k from a set
| Name |
|---|
T |
| Name | Type | Description |
|---|---|---|
set |
T[] |
elements to derrive combinations of |
k |
number |
number of combinations |
T[][]
an array of k-lemngth choices from the set
src/utility/math-lambdas.ts:29
▸ compose(...fns): () => void
Function
compose
Description
compose an ordered list of execution from current context
| Name | Type | Description |
|---|---|---|
...fns |
Function[] |
functions to execute |
fn
a function taht will call each fn in turn
▸ (): void
void
▸ copyWithoutCircularReferences(references, object): Object
recursive function to build a copy of an object with ‘###Circular###’ replacing circular references
| Name | Type | Description |
|---|---|---|
references |
any[] |
the list of references so far encountered |
object |
any |
the object copied |
Object
copy of an object without circular references
src/utility/clean-stringify.ts:21
▸ count<T>(p, c): Map<T, number>
| Name |
|---|
T |
| Name | Type |
|---|---|
p |
Map<T, number> |
c |
T |
Map<T, number>
▸ divide(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
src/utility/math-lambdas.ts:10
▸ emitPropertyChange(property): (this: StatefulSubject) => void
| Name | Type |
|---|---|
property |
string |
fn
▸ (this): void
| Name | Type |
|---|---|
this |
StatefulSubject |
void
src/decorators/stateful.decorator.ts:43
▸ factoryDummyableConfig(conf): DummyableConfig
(internal) function to generate a compliant conf body from a partial one
| Name | Type | Description |
|---|---|---|
conf |
Partial<DummyableConfig> |
Partial |
compliant Dummyable conf parameter
src/decorators/dummyable.decorator.ts:37
▸ factoryHasProperty(property): ArrowFunction<unknown[], boolean>
generate a comparator that looks for existance of a property example:
const cases = [ {a:2}, {a:3, 'dummy-data': true}, {a:4} ]
const hasDummyData = factoryHasProperty('dummy-data')
assert(cases.some(hasDummyData))
| Name | Type | Description |
|---|---|---|
property |
string |
that is required on the comparator |
ArrowFunction<unknown[], boolean>
comparator
src/comparitors/factory-has-property.ts:14
▸ factoryHasValue(property, evaluator?): ArrowFunction<unknown[], boolean>
generate a comparator that looks for existance of a value at a property example:
const cases = [ {a:2}, {a:3}, {a:4} ]
const isOdd = factoryHasValue('a', () => a%2)
assert(cases.some(isOdd))
| Name | Type | Default value | Description |
|---|---|---|---|
property |
string |
undefined |
that is required on the comparator |
evaluator |
Function |
isDefined |
that is called in the comparator, on the property, to determine the matching of the value |
ArrowFunction<unknown[], boolean>
comparator
src/comparitors/factory-has-value.ts:16
▸ is(o): (x: any) => boolean
Function
is
Description
factory pattern for creating custom “is”-type comparators
| Name | Type | Description |
|---|---|---|
o |
any |
pattern (variable) to compare to |
fn
a comparator that returns true if the input object is equal to the pattern
▸ (x): boolean
| Name | Type |
|---|---|
x |
any |
boolean
▸ isDefined(value): boolean
comparitor to find defined values
| Name | Type | Description |
|---|---|---|
value |
any |
expected to be not null or undefined |
boolean
src/comparitors/is-defined.ts:6
▸ isNullOrUndefined(value): boolean
comparitor to find not defined values
| Name | Type | Description |
|---|---|---|
value |
any |
expected to be null or undefined |
boolean
src/comparitors/is-null-or-undefined.ts:6
▸ isNumber(value): boolean
comparitor to find number values
| Name | Type | Description |
|---|---|---|
value |
any |
expected to be number |
boolean
src/comparitors/is-number.ts:6
▸ isNumeric(value): boolean
comparitor to find numeric values
| Name | Type | Description |
|---|---|---|
value |
any |
expected to be numeric |
boolean
src/comparitors/is-numeric.ts:6
▸ mean(o): number
| Name | Type |
|---|---|
o |
number[] |
number
src/utility/math-lambdas.ts:18
▸ modulo(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
src/utility/math-lambdas.ts:11
▸ multiply(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
▸ power(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
src/utility/math-lambdas.ts:12
▸ randomInt(min, max): number
| Name | Type |
|---|---|
min |
number |
max |
number |
number
▸ staticImplements<T>(): Function
simple static implementation type checking for typescript
| Name |
|---|
T |
Function
src/utility/static-implements.ts:4
▸ subtract(a, b): number
| Name | Type |
|---|---|
a |
number |
b |
number |
number
▸ sum(o): number
| Name | Type |
|---|---|
o |
number[] |
number
src/utility/math-lambdas.ts:14
▸ take<T>(num, iter): IterableIterator<T>
| Name |
|---|
T |
| Name | Type |
|---|---|
num |
number |
iter |
IterableIterator<T> |
IterableIterator<T>
▸ toCamelCase(str?): string
convert a string of whole words to camel case
| Name | Type | Default value | Description |
|---|---|---|---|
str |
string |
'' |
whole words to camel case |
string
camel cased string
src/utility/to-camel-case.ts:6
▸ zip(...iterables): Object
Method
zip usage: const zipped = zip([‘a’, ‘b’, ‘c’], [‘d’, ‘e’, ‘f’, ‘g’]); for (const x of zipped) { console.log(x); } // Output: // [‘a’, ‘d’] // [‘b’, ‘e’] // [‘c’, ‘f’]
TODO – WHAT return type is this?
Src
https://exploringjs.com/es6/ch_iteration.html
| Name | Type |
|---|---|
...iterables |
any[] |
Object
| Name | Type |
|---|---|
[iterator] |
() => any |
next |
() => { done: undefined = true; value: any[] } | { done: boolean = true; value: undefined } |