1.1.3 • Published 1 year ago
@adam-rocska/invertible v1.1.3
Invertible Functions for TS & JS
| Aspect | Badge | 
|---|---|
| Minified | |
| Minified + gzip | |
| Dependency Count | |
| Tree-shaking Support | 
A library for creating and managing invertible functions and type-safe pipelines in TypeScript.
Installation
To install the package, use npm or yarn:
npm install @adam-rocska/invertibleor
pnpm add @adam-rocska/invertibleUsage
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);
});Usefulness Ideas
- Undo-able user interface actions
 - Reversible CI pipeline steps and pipelines
 - Bidirectional data coding
 
Contributing
Contributions are welcome! Please read the contributing guidelines before submitting a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.