MicroDroid / convert

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

Home Page:https://www.npmjs.com/package/convert

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert

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

bundlephobia

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

* Some conversions are just totally wrong. Please don't use this (yet).

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

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.

About

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

https://www.npmjs.com/package/convert

License:MIT License


Languages

Language:TypeScript 95.9%Language:JavaScript 4.1%