Skip to content

A library for creating and managing invertible functions and type-safe pipelines in TypeScript.

License

Notifications You must be signed in to change notification settings

adam-rocska/invertible-typescript

Folders and files

NameName
Last commit message
Last commit date
Sep 7, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Sep 7, 2024
Sep 7, 2024
Sep 13, 2024
Feb 3, 2025
Aug 14, 2024

Repository files navigation

Invertible Functions for TS & JS

NPM Version License

Aspect Badge
Minified Minified
Minified + gzip Minified + gzip
Dependency Count Dependency Count
Tree-shaking Support 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/invertible

or

pnpm add @adam-rocska/invertible

Usage

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

  1. Undo-able user interface actions
  2. Reversible CI pipeline steps and pipelines
  3. 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.

Author

Ádám László Rocska