Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

money-ts

gcanti180MIT0.1.2TypeScript support: included

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

TypeScript, money, type-safe, newtype, newtype-ts, fp-ts

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

changelog

Changelog

Tags:

  • [New Feature]
  • [Bug Fix]
  • [Breaking Change]
  • [Documentation]
  • [Internal]
  • [Polish]
  • [Experimental]

Note: Gaps between patch versions are faulty/broken releases. Note: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

0.1.2

  • Internal
    • upgrade to latest versions, in particular `io-ts@1.1.5` (@gcanti)

0.1.1

  • New Feature
    • add more scales (@gcanti)

0.1.0

0.0.1

Initial release