Aspect | Badge |
---|---|
Minified | |
Minified + gzip | |
Dependency Count | |
Tree-shaking Support |
A library for creating and managing invertible functions and type-safe pipelines in TypeScript.
To install the package, use npm or yarn:
npm install @adam-rocska/invertible
or
pnpm add @adam-rocska/invertible
Simple example:
import {Invertible} from "@adam-rocska/invertible";
import {pipe} from "@adam-rocska/invertible/pipe";
test(`Simple arithmetics example`, async () => {
const increment = Invertible(
async (a: number) => a + 1,
async (a: number) => a - 1
);
const double = Invertible(
async (a: number) => a * 2,
async (a: number) => a / 2
);
expect(await increment(1)).toBe(2);
expect(await increment.inverse(2)).toBe(1);
expect(await double(2)).toBe(4);
expect(await double.inverse(4)).toBe(2);
const pipeExample = pipe(increment)
.pipe(double)
.pipe(increment)
.pipe(double);
expect(await pipeExample(1)).toBe(10);
});
- Undo-able user interface actions
- Reversible CI pipeline steps and pipelines
- Bidirectional data coding
Contributions are welcome! Please read the contributing guidelines before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.