npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ramda-decimal

v2.3.0

Published

Ramda-centric wrapper to decimal.js

Downloads

1,168

Readme

NPM

ramda-decimal CircleCI

Ramda wrapper to Decimal.js

Use Decimal.js arbitrary precision maths in Ramda style. Immutable. Composable. Curry-able.

Drop-in replacements for most Ramda math functions.

const R = require('ramda);
const RD = require('ramda-decimal);

const annualTax = R.pipe(
    R.pluck(income),
    RD.sum,
    RD.times(TAX_RATE),
);

const format = RD.fixed(2);

console.log(format(annualTax(months)));

Liberal inputs, conservative outputs

Like Decimal.js, RD accepts Decimals, number primitives and strings that look like numbers. RD does this by calling new Decimal() on any input.

All RD functions return Decimals.

Constants

ZERO and ONE are defined as constants. Use them! They're immutable.

Parameter order

When there is a corresponding Ramda function, RD uses the same parameter order. This does mean that curried relation functions are unintuitive (in my opinion) in the same way as Ramda:

const f = RD.gt(5);
return f(6); // false: gt(5,6)

Where there is no corresponding Ramda function, we have flipped the parameters when it seems useful for point-free coding:

const formatToPennies = RD.toFixed(2);

Currying and efficiency

For brevity the documentation suggests that (for example) RD.add(a)(b) is equivalent to new Decimal(a).plus(b). The reality is a bit better than that. RD.add(a) stores any Decimal it creates for reuse. Hence in:

const addTen = RD.add(10);
const n110 = addTen(100);
const n210 = addTen(200);

... new Decimal(10) is only run once.

Mixed style

Returned values are just Decimal objects, so you are free to combine styles if you want to:

const displayTotal = RD.sum(vals).fixed(2, Decimal.ROUND_HALF_UP);

Docs

Modules

Typedefs

ramda-decimal

Ramda-style curried functions wrapping the methods of Decimal.js

DecimalLike : Decimal | number | string

A Decimal, number, or a string containing a number. That is, any valid parameter to new Decimal(...)

Kind: global typedef

.abs(n) ⇒ Decimal

Equivalent to new Decimal(n).absoluteValue()

Kind: static function

| Param | Type | | --- | --- | | n | DecimalLike |

.add(a, b) ⇒ Decimal

Equivalent to new Decimal(a).plus(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.ceil(n) ⇒ Decimal

Equivalent to new Decimal(n).ceil()

Kind: static function

| Param | Type | | --- | --- | | n | DecimalLike |

.eq(a, b) ⇒ boolean

Equivalent to new Decimal(a).equals(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.divide(a, b) ⇒ Decimal

Equivalent to new Decimal(a).dividedBy(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.divideBy(a, b) ⇒ Decimal

Equivalent to new Decimal(b).dividedBy(a)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.floor(n) ⇒ Decimal

Equivalent to new Decimal(n).floor()

Kind: static function

| Param | Type | | --- | --- | | n | DecimalLike |

.gt(a, b) ⇒ boolean

Equivalent to new Decimal(a).gt(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.gte(a, b) ⇒ boolean

Equivalent to new Decimal(a).gte(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.lt(a, b) ⇒ boolean

Equivalent to new Decimal(a).lt(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.lte(a, b) ⇒ boolean

Equivalent to new Decimal(a).lte(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.multiply(a, b) ⇒ Decimal

Equivalent to new Decimal(a).times(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.negate(a) ⇒ Decimal

Equivalent to new Decimal(a).negated()

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike |

.round(a) ⇒ Decimal

Equivalent to new Decimal(a).round()

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike |

.subtract(a, b) ⇒ Decimal

Equivalent to new Decimal(a).minus(b)

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike | | b | DecimalLike |

.toFixed(roundingMode, num) ⇒ Decimal

Equivalent to new Decimal(num).toFixed(roundingMode)

See Decimal.js docs for ROUNDING_MODE constants

Kind: static function

| Param | Type | | --- | --- | | roundingMode | num | | num | DecimalLike |

.toNumber(a) ⇒ Number

Equivalent to new Decimal(a).toNumber()

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike |

.modulo(modulus, value) ⇒ Decimal

Equivalent to new Decimal(value).modulo(modulus)

Kind: static function

| Param | Type | | --- | --- | | modulus | DecimalLike | | value | DecimalLike |

.toPower(power, value) ⇒ Decimal

Equivalent to new Decimal(value).toPower(modulus)

Kind: static function

| Param | Type | | --- | --- | | power | DecimalLike | | value | DecimalLike |

.isPositive(a) ⇒ boolean

Equivalent to new Decimal(a).isPositive()

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike |

.isNegative(a) ⇒ boolean

Equivalent to new Decimal(a).isNegative()

Kind: static function

| Param | Type | | --- | --- | | a | DecimalLike |

.dec(a) ⇒ Decimal

Decrements a Decimal or value that may be converted into Decimal

Kind: static function
Returns: Decimal - a minus 1

| Param | Type | | --- | --- | | a | DecimalLike |

.inc(a) ⇒ Decimal

Increments a Decimal or value that may be converted into Decimal

Kind: static function
Returns: Decimal - a plus 1

| Param | Type | | --- | --- | | a | DecimalLike |

.sum(a) ⇒ Decimal

Returns the sum of an array of Decimals or values that may be converted into Decimal

Kind: static function
Returns: Decimal - The sum of the values in a

| Param | Type | | --- | --- | | a | Array.<DecimalLike> |

.product(a) ⇒ Decimal

Returns the product of an array of Decimals or values that may be converted into Decimal

Kind: static function
Returns: Decimal - The product of the values in a

| Param | Type | | --- | --- | | a | Array.<DecimalLike> |

.max(a, b) ⇒ Decimal

Returns the highest of a or b

Kind: static function
Returns: Decimal - The highest of a or b

| Param | Type | | --- | --- | | a | Array.<DecimalLike> | | b | Array.<DecimalLike> |

.min(a, b) ⇒ Decimal

Returns the lowest of a or b

Kind: static function
Returns: Decimal - The lowest of a or b

| Param | Type | | --- | --- | | a | Array.<DecimalLike> | | b | Array.<DecimalLike> |


Created by Wealth Wizards Software Engineering - http://wealthwizards.com