Centralize configure-able factory classes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Collection} from './Collection'
|
||||
import {InjectionAware} from '../../di'
|
||||
import {InjectionAware} from '../../di/InjectionAware'
|
||||
|
||||
export type MaybeIterationItem<T> = { done: boolean, value?: T }
|
||||
export type ChunkCallback<T> = (items: Collection<T>) => any
|
||||
|
||||
@@ -2,6 +2,8 @@ import {RequestInfo, RequestInit, Response} from 'node-fetch'
|
||||
import {unsafeESMImport} from './unsafe'
|
||||
export const fetch = (url: RequestInfo, init?: RequestInit): Promise<Response> => unsafeESMImport('node-fetch').then(({default: nodeFetch}) => nodeFetch(url, init))
|
||||
|
||||
export * from './support/operator'
|
||||
|
||||
export * from './cache/Cache'
|
||||
export * from './cache/InMemCache'
|
||||
|
||||
|
||||
27
src/util/support/operator.ts
Normal file
27
src/util/support/operator.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Apply a series of operators to a value, returning the original value.
|
||||
*
|
||||
* Helpful for values/methods that don't support chaining.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const inOneHour = () => tap(new Date, d => d.setMinutes(d.getMinutes() + 60))
|
||||
* ```
|
||||
*
|
||||
* This is equivalent to:
|
||||
*
|
||||
* ```ts
|
||||
* const inOneHour = () => {
|
||||
* const d = new Date
|
||||
* d.setMinutes(d.getMinutes() + 60)
|
||||
* return d
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param value
|
||||
* @param ops
|
||||
*/
|
||||
export function tap<T>(value: T, ...ops: ((t: T) => unknown)[]): T {
|
||||
ops.forEach(op => op(value))
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user