@sylo/money-ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.1-2 • Public • Published

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

Package Sidebar

Install

npm i @sylo/money-ts

Weekly Downloads

1

Version

0.2.1-2

License

MIT

Unpacked Size

93.5 kB

Total Files

91

Last publish

Collaborators

  • chao-putti
  • admin-futureverse
  • nick95550
  • helenpham
  • sylomatthew
  • phoebe-sylo
  • taylor_sylo
  • asapblockie
  • kingsleysylo
  • chris.czurylo
  • rafael_sylo
  • varma_sylo
  • jcsanpedro
  • jimmyc1987
  • syloadmin
  • syloread
  • darpan-patil
  • kormyen
  • minwoora
  • rupertsylo