@erickmeikoki/workspace
v1.0.0
Published
[](https://badge.fury.io/js/ts-pipeline) [](https://github.com/erickmeikoki/ts-pipeline/actions) [
.pipe(s => s.trim())
.pipe(s => s.toUpperCase())
.pipe(s => s + "!")
.valueOf(); // "HELLO!"With Built-in Utility Functions
import { pipeline, trim, toUpperCase, append } from 'ts-pipeline';
const result = pipeline(" hello world ")
.pipe(trim)
.pipe(toUpperCase)
.pipe(append("!"))
.valueOf(); // "HELLO WORLD!"Using String Prototype Extension
import 'ts-pipeline'; // Import for side effects to extend prototypes
const result = " method chaining is cool "
.pipe(trim)
.pipe(toUpperCase)
.pipe(s => s + "!!!")
.valueOf(); // "METHOD CHAINING IS COOL!!!"Using the Helper Function
import { _ } from 'ts-pipeline';
const result = _("typescript")
.pipe(s => s.toUpperCase())
.pipe(s => s + " is awesome!")
.valueOf(); // "TYPESCRIPT is awesome!"Working with Numbers
import { pipeline } from 'ts-pipeline';
const result = pipeline(5)
.pipe(n => n * 2)
.pipe(n => n + 10)
.pipe(n => n ** 2)
.valueOf(); // 400Working with Arrays
import { pipeline, map, filter, reduce } from 'ts-pipeline';
const result = pipeline([1, 2, 3, 4, 5])
.pipe(filter(n => n % 2 === 0))
.pipe(map(n => n * 3))
.pipe(reduce((sum, n) => sum + n, 0))
.valueOf(); // 18Available Utility Functions
| Function | Description |
|----------|-------------|
| toUpperCase | Converts a string to uppercase |
| toLowerCase | Converts a string to lowercase |
| trim | Removes whitespace from both ends of a string |
| reverse | Reverses a string |
| split(separator) | Splits a string by the given separator |
| join(separator) | Joins an array with the given separator |
| map(fn) | Maps an array using the provided function |
| filter(predicate) | Filters an array using the provided predicate |
| reduce(fn, initialValue) | Reduces an array using the provided function and initial value |
| compose(...fns) | Composes multiple functions into a single function |
| tap(label) | Logs the current value in the pipeline (useful for debugging) |
| toString | Converts any value to a string |
| toNumber | Converts a string to a number |
| append(suffix) | Appends a string to the input |
| prepend(prefix) | Prepends a string to the input |
API Reference
pipeline<T>(value: T): Pipeline<T>
Creates a pipeline with the given value.
pipeline<T, R>(value: T, fn: PipelineFunction<T, R>): Pipeline<R>
Creates a pipeline with the given value and applies the function.
_<T>(value: T): Pipeline<T>
Helper function to make using the pipeline more intuitive.
Pipeline<T> Interface
pipe<R>(fn: PipelineFunction<T, R>): Pipeline<R>- Apply a function to the current valuevalueOf(): T- Get the current value from the PipelinetoString(): string- Convert the pipeline to a string
License
MIT
