https://github.com/darky/klubok
Do notation pipes for Promise-based or pure functions which easy to mock
https://github.com/darky/klubok
do-notation functional-programming javascript mock pipe promise typescript unit-testing
Last synced: 5 months ago
JSON representation
Do notation pipes for Promise-based or pure functions which easy to mock
- Host: GitHub
- URL: https://github.com/darky/klubok
- Owner: darky
- Created: 2024-11-01T17:47:26.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-12-30T12:00:55.000Z (6 months ago)
- Last Synced: 2025-01-10T16:19:00.947Z (5 months ago)
- Topics: do-notation, functional-programming, javascript, mock, pipe, promise, typescript, unit-testing
- Language: TypeScript
- Homepage:
- Size: 1.09 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Klubok

Do notation pipes for Promise-based or pure functions which easy to mock
Inspired by fp-ts/Effect `bind` Do-notation, but much more small and simple
Primarly created for easy mocking of functions, which allows to write tons of unit tests## Example
```ts
import { pure, eff, klubok } from 'klubok';const catsBirthdays = klubok(
eff('cats', async ({ ids }: { ids: number[] }) => { /* fetch cats from DB */ }),pure('catsOneYearOld', ({ cats }) => cats.map(cat => ({ ...cat, age: cat.age + 1 })),
eff('saved', async ({ catsOneYearOld }) => { /* save to DB */ })
)// production usage
catsBirthdays({ ids: [1, 2, 3] })// in tests usage
catsBirthdays(
{ ids: [1, 2, 3] },{
// DB response mock
cats: () => [
{ name: 'Barsik', age: 10 },
{ name: 'Marfa', age: 7 }
]
},// call only this functions
['catsOneYearOld']) // Promise<{ ..., catsOneYearOld: [{ name: 'Barsik', age: 11 }, { name: 'Marfa', age: 8 }] }>
```
## See also
* [Klubok-Gleam](https://github.com/darky/klubok-gleam) - Gleam implementation of Klubok