New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

convert

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convert

The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46K
increased by7.05%
Maintainers
1
Weekly downloads
 
Created
Source

Convert

The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.

bundlephobia Codecov

yarn add convert
# or
npm install convert

Features

  • Full build time and runtime checks of conversions
  • Using a web framework like Next.js or Nuxt.js? You get 0-cost build-time conversions. Convert is totally side-effect free, so conversions will be precalculated at build-time, so absolutely zero conversion code is sent to clients!
  • Works in browsers and Node.js (UMD, ESModules, and CommonJS builds provided)
  • Out of the box ES5 backwards-compatibility
  • 0 dependencies
  • Supports bigints if you pass something with typeof bigint

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, volume, pressure, and temperature
convert(5).from('kilometers').to('nautical miles');
convert(12).from('pounds').to('ounces');
convert(64).from('bytes').to('KiB');
convert(10).from('atmospheres').to('kPa');
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 and are slower than convert. Benchmarks of popular unit conversion libraries, including convert are available here. Convert is the fastest, taking less than a microsecond for most conversions (that's a little bit under 2 million per second).

npm bundle size of convert

npm bundle size of uom + npm bundle size of uom-units

npm bundle size of units-converter

npm bundle size of safe-units

npm bundle size of convert-units

npm bundle size of js-quantities

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.

Keywords

FAQs

Package last updated on 24 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc