/convert

A small library for fully type-safe unit conversions in JavaScript & TypeScript.

Primary LanguageTypeScriptMIT LicenseMIT

Convert

bundlephobia

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

It's not ready for production release, but all the groundwork for adding in new conversions is done.

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 ES3 backwards-compatibility
  • Works in browsers and Node.js

Usage

import {convert} from 'convert';

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

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.

Thanks

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