JSPM

  • Created
  • Published
  • Downloads 44189
  • Score
    100M100P100Q133202F
  • License MIT

Package Exports

  • convert

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (convert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Convert

A small library for really easy, totally type-safe unit conversions in JavaScript & TypeScript.

bundlephobia Codecov

It's almost ready for production release, just need to add in some more conversions.

yarn add convert
# or
npm install convert

Features

  • Full build time and runtime checks of conversions
  • Treeshake-able builds available
  • 0 dependencies
  • Out of the box ES5 backwards-compatibility
  • Works in browsers and Node.js

Usage

// ESM:
import {convert} from 'convert';
// CJS:
const {convert} = require('convert');

// 360 seconds into minutes
convert(360).from('seconds').to('minutes');
// -> 6

// BigInt support
convert(20n).from('hours').to('minutes');
// -> 1200n

// We also do length, mass, data, and temperature
convert(5).from('kilometers').to('nautical miles');
convert(64).from('bytes').to('KiB');
convert(12).from('pounds').to('ounces');
convert(451).from('fahrenheit').to('celsius');

Contributing

Below is a list of commands you will probably find useful.

yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

Alternatives

All of them are bad because they aren't as small as this and many aren't as simple to use.

npm bundle size npm bundle size npm bundle size npm bundle size npm bundle size npm bundle size

Thanks

Big thanks to @Jdender, @TheAkio, @iCrawl, @p7g, @aequasi, and the TypeScript Discord server for their help in getting the typesafety working.

Thanks to @MicroDroid for fixing temperature conversion.