Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
npm install convert
# or
yarn add convert
More installation examples below.
convert(5, "miles").to("km");
convertMany("4d 16h").to("minutes");
Generated API documentation for the latest version is available online.
// ESM:
import convert from "convert";
// CJS:
const { convert } = require("convert");
// 360 seconds into minutes
convert(360, "seconds").to("minutes");
// -> 6
// BigInt support
convert(20n, "hours").to("minutes");
// -> 1200n
// Format to the best unit automatically
convert(5500, "meters").to("best");
// -> { quantity: 5.5, unit: 'km', toString: () => '5.5 km' }
// You can also do length, data, volume, mass, temperature, and more
convert(5, "kilometers").to("nautical miles");
convert(12, "pounds").to("ounces");
convert(8192, "bytes").to("KiB");
convert(10, "atmospheres").to("kPa");
convert(451, "fahrenheit").to("celsius");
import { convertMany } from "convert";
const { convertMany } = require("convert");
// Convert 1 day and 8 hours into ms
convertMany("1d8h").to("ms");
import convert from "convert";
const { convert } = require("convert");
// Convert into the best unit
const duration = convert(36, "h").to("best");
// -> { quantity: 1.5, unit: 'd', toString: () => '1.5 d' }
// The toString() method means you can automatically cast the object to a string without any issues
"duration is " + duration;
// -> duration is 1.5d
// You can also specify to use a specific kind of units (metric or imperial, metric is default)
convert(3.5, "km").to("best"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "metric"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "imperial"); // -> { quantity: 2.17, unit: 'mi', toString: () => '3.5 mi' }
ms
shorthandimport { ms } from "convert";
const { ms } = require("convert");
// Convert a duration into milliseconds
ms("1d 2h 30min");
// -> 95400000
// Convert milliseconds to a string
ms(86400000);
// -> '1d'
Convert is published as convert
on npm.
npm install convert
# or
yarn add convert
And then import it in your code like this:
// CommonJS
const { convert } = require("convert");
// ESM
import convert from "convert";
Pick your favorite CDN:
<script type="module">
import convert from "https://cdn.skypack.dev/convert@5";
import convert from "https://esm.run/convert@5";
import convert from "https://cdn.jsdelivr.net/npm/convert@5";
import convert from "https://unpkg.com/convert@5";
</script>
<script src="https://cdn.jsdelivr.net/npm/convert@5/dist/index.js"></script>
<script src="https://unpkg.com/convert@5/dist/index.js"></script>
Convert is better than other unit conversion libraries because it's faster and smaller than them, while having the same features. Benchmarks of popular unit conversion libraries, including Convert are available here.
Convert is the fastest, taking less than a microsecond for all functions.
That's a little over 3 million convert()
calls per second.
FAQs
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript
The npm package convert receives a total of 28,118 weekly downloads. As such, convert popularity was classified as popular.
We found that convert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.