@web-pacotes/foundation-types
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

foundation-types

Curated package with types I believe all packages and apps need to promote safeness and reduced side effects.

npm version npm total downloads bundlephobia bundle size


How to use

The following is an example how to use the Either monad type to eliminate exceptions thrown from a division operation:

import { fold, Left, Right } from './either';

function div_numbers(x: number, y: number) {
	if (y === 0.0) {
		return Left('cannot divide number by 0!');
	}

	return Right(x / y);
}

const computation = div_numbers(2, 0);
fold(
	computation,
	(l) => console.error(l),
	(r) => console.info(`division = ${r}`)
);

Features

  • Option type (either a value is present or absent)
  • Either type (either a value or other value)
  • Lazy type (lazily computed value)
  • Error type (type safe errors)
    • IO (Read/Write) error type
    • Unknown error type
    • Wrapping/Unwrapping typed error in internal errors
    • Wrapper around try/catch to execute callbacks in a safe throwable environment

Upcoming features

New types come as I need them or as requested through an issue.


Bugs and Contributions

Found any bug (including typos) in the package? Do you have any suggestion or feature to include for future releases? Please create an issue via GitHub in order to track each contribution. Also, pull requests are very welcome!

To contribute, start by setting up your local development environment. The setup.md document will onboard you on how to do so!

Package Sidebar

Install

npm i @web-pacotes/foundation-types

Weekly Downloads

73

Version

0.0.3

License

none

Unpacked Size

76.5 kB

Total Files

48

Last publish

Collaborators

  • freitzzz