0.4.2 • Published 5 months ago

klubok v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Klubok

logo

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

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

0.4.2

5 months ago

0.4.1

5 months ago

0.4.0

5 months ago

0.3.3

5 months ago

0.3.2

5 months ago

0.3.1

5 months ago

0.3.0

5 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.3

6 months ago

0.1.2

7 months ago

0.1.1

8 months ago

0.1.0

9 months ago