maasglobal-prelude-ts

The maasglobal-prelude-ts npm package is a bundle of essential imports for TypeScript projects.

Usage no npm install needed!

<script type="module">
  import maasglobalPreludeTs from 'https://cdn.skypack.dev/maasglobal-prelude-ts';
</script>

README

MaaS Global Prelude for TypeScript Projects

The maasglobal-prelude-ts npm package is a bundle of essential imports for TypeScript projects.

Some convenience tools

import * as P from 'maasglobal-prelude-ts';

const x = 2;
const limit = 10;
const isOverLimit = P.ii(() => {
  if (x > limit) {
    return true;
  }
  return false;
});

Some basic tools from fp-ts

import * as P from 'maasglobal-prelude-ts';

const numbers = [1, 2, 3];
const doubled = P.pipe(
  numbers,
  P.Array_.map((x) => 2 * x),
);

const twoIsEven = P.do(P.Identity__)
  .bind('x', 2)
  .bindL('p', ({x}) => x % 2 ? 'odd' : 'even')
  .return(({x, p}) => `Number ${x} is ${p}.`);

Some basic codecs from io-ts

import * as P from 'maasglobal-prelude-ts';

const NumberArray = P.Array(P.number);
const onTheWire = JSON.stringify(NumberArray.encode([1, 2, 3]));
const atTheServer = NumberArray.decode(JSON.parse(onTheWire));