Documentation available in : https://evanliomain.github.io/taninsam
A functionnal library based on a powerfull chain mecanism.
Yes you could just use simple ESNext functions to do your transformation. If you enjoy with it, just keep it that way.
But sometime, the code don't feel linear, so you are tempted to use a library. So why this one, instead of another ?
Taninsam is:
- Write in Typescript to enforced the feature correctness
- Write in full TDD because is so easy to do it that way
- Offer a simple way for chain function
- Offer a constante way to code data transformation: no more function alias or 2 way to compose functions
- Easy to extend: just
chain
a function
Install taninsam:
npm install --save taninsam
or
yarn add taninsam
Import the librairie and start the chain:
import { chain, filter, map, sum } from 'taninsam';
// Sum square of even number in this collection
chain([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
.chain(filter(x => 0 === x % 2)) // [2, 4, 6, 8, 10]
.chain(map(x => x ** 2)) // [4, 16, 36, 64, 100]
.chain(sum()) // 220
.value();
To understand the chain function, it's as easy as this:
function chain(x) {
return {
chain: f => chain(f(x)),
value: () => x
};
}
So you can chain
as much as function you want, and called value()
at the end to get the actual value.
To extend the chain, it's as easy as to write a function:
import { chain } from 'taninsam';
chain(2)
.chain(x => x ** 2)
.chain(x => `square of 2 is ${x}`)
.value(); // 'square of 2 is 4'
yarn
Main commands to develop
- Use vscode for coding (or any other good editor that suite you)
yarn gen
: Create a new functionyarn test:watch
: Run test suite in interactive watch modeyarn commit
: Commit using conventional commit style
Additionals commands
yarn lint
: Lints codeyarn test
: Run test suite onceyarn stryker
: Run mutation testing suite onceyarn build
: Generate bundles and typings, create docsyarn start
: Runsnpm run build
in watch mode
Code source is automatically formatted and linted at each commit.
This library was bootstraped by typescript-library-starter.