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

catalytic

v1.4.2

Published

Convert between arbitrary units with BigNumber math

Downloads

6

Readme

catalytic - a module for your unit conversion needs Build Status

Features

  • Simple, easily understood API
  • Convert to and from arbitrary units
  • Uses BigNumber for math: avoiding inexplicable floating-point math errors
  • Does not come with awareness of anything by default, you have to teach it whatever conversions you care about

Examples

var catalytic = require('catalytic')

var converter = catalytic.converter({
  baseUnitName: 'lb',
  types: [
    {id: 'id1', name: 'case (50lb)', qty: 50},
    {id: 'id2', name: 'porterhouse (1.5lb)', qty: 1.5},
    {id: 'id3', name: 'porterhouse (2lb)', qty: 2}
  ]
})

converter.convertTo(100, 'id1') // => 2
converter.convertTo(90, 'id1')  // => 1.8
converter.strConvertTo(100, 'id1') // => "2 x case (50lb)"

converter.convertFrom(2, 'id1') // => 100
converter.strConvertFrom(5, 'id1') // "250 x lb"

If you're converting from/to undefined or null, we assume you're converting from/to the base unit (i.e., not changing anything):

converter.convertTo(100) // => 100
converter.strConvertTo(100) // => "100 x lb"

converter.convertFrom(10) // => 10
converter.strConvertFrom(10) // => "10 x lb"

There's also some basic methods for easy conversion without an object:

catalytic.convertToUnitQty({count: 5, unitQty: 10}) // => 50
catalytic.convertFromUnitQty({count: 50, unitQty: 10}) // => 5

Contributing

This module is written in ES2015 and converted to node-friendly CommonJS via Babel. Tests are run with mocha.

If you're going to add a PR, please write a test too. They live in the test directory. To run all tests:

npm test

To compile the src directory to lib:

npm run build