Money Ts Save

TypeScript library for type-safe and lossless encoding and manipulation of world currencies and precious metals

Project README

A porting of safe-money (Haskell)

Blog post: https://ren.zone/articles/safe-money

Features

Newtypes

Via newtype-ts

  • BigInteger
  • ExchangeRate
  • Integer
  • Natural
  • NonZeroInteger

Type aliases

  • NonZeroRational
  • PositiveRational
  • Rational

Discrete

import { Integer } from 'money-ts/lib/Integer'
import { Discrete } from 'money-ts/lib/Discrete'

declare const ix: Integer // 2
declare const iy: Integer // 3

const x = new Discrete({ dimension: 'EUR', unit: 'cent' }, ix)
const y = new Discrete({ dimension: 'EUR', unit: 'cent' }, iy)
// z: Discrete<"EUR", "cent">
const z = x.add(y)
console.log(z)
// => EUR cent 5

Dense

import * as dense from 'money-ts/lib/Dense'
import 'money-ts/lib/scale/EUR' // <= required in order to convert a discrete to a dense

const d = dense.fromDiscrete(z)
console.log(d)
// => EUR 5 / 100

Runtime types for IO validation

Via io-ts

  • BigInteger
  • Dense
  • Discrete
  • ExchangeRate
  • Integer
  • Natural
  • NonZeroInteger
  • NonZeroRational
  • PositiveRational
  • Rational

Documentation

Open Source Agenda is not affiliated with "Money Ts" Project. README Source: gcanti/money-ts
Stars
87
Open Issues
5
Last Commit
2 years ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating