UNPKG

@ayonli/jsext

Version:

A JavaScript extension package for building strong and modern applications.

41 lines (40 loc) 1.19 kB
/** * Performs pipe operations through a series of functions upon a value. * @module */ declare const _value: unique symbol; /** * Pipeline holds a value and allows you chain operations upon it (and the result * of the previous operation) to get the final result, similar to the Unix pipe * operator `|` in shell scripting. */ export declare class Pipeline<T> { private [_value]; constructor(value: T); get [Symbol.toStringTag](): "Pipeline"; get value(): T; /** * Calls a function using the current value as its argument and returns a * new {@link Pipeline} instance that holds the result. */ pipe<R, A extends any[] = any[]>(fn: (value: T, ...args: A) => R, ...args: A): Pipeline<R>; valueOf(): T; } /** * Constructs a {@link Pipeline} instance with the given value and performs pipe * operations upon it. * * @example * ```ts * import pipe from "@ayonli/jsext/pipe"; * * const { value } = pipe("10") * .pipe(parseInt) * .pipe(Math.pow, 2) * .pipe(v => v.toFixed(2)); * * console.log(`the value is ${value}`) // the value is 100.00 * ``` */ export default function pipe<T>(value: T): Pipeline<T>; export {};