Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@eomm/convert-units
Advanced tools
A handy utility for converting between quantities in different units.
npm install @eomm/convert-units
@eomm/convert-units
has a simple chained API that is easy to read.
Here's how you move between the metric units for volume:
var convert = require('@eomm/convert-units')
convert(1).from('l').to('ml')
// 1000
Jump from imperial to metric units the same way:
convert(1).from('lb').to('kg')
// 0.4536... (tested to 4 significant figures)
Just be careful not to ask for an impossible conversion:
convert(1).from('oz').to('fl-oz')
// throws -- you can't go from mass to volume!
You can ask convert-units
to select the best unit for you. You can also optionally explicitly exclude orders of magnitude or specify a cut off number for selecting the best representation.
convert(12000).from('mm').toBest()
// 12 Meters (the smallest unit with a value above 1)
convert(12000).from('mm').toBest({ exclude: ['m'] })
// 1200 Centimeters (the smallest unit excluding meters)
convert(900).from('mm').toBest({ cutOffNumber: 10 });
// 90 Centimeters (the smallest unit with a value equal to or above 10)
convert(1000).from('mm').toBest({ cutOffNumber: 10 })
// 100 Centimeters (the smallest unit with a value equal to or above 10)
You can get a list of the measurement types supported with .measures
convert().measures()
// [ 'length', 'mass', 'volume' ]
If you ever want to know the possible conversions for a unit, just use .possibilities
convert().from('l').possibilities()
// [ 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ]
convert().from('kg').possibilities()
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]
You can also get the possible conversions for a measure:
convert().possibilities('mass')
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't' ]
You can also get the all the available units:
convert().possibilities()
// [ 'mm', 'cm', 'm', 'in', 'ft-us', 'ft', 'mi', 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't', 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal', 'ea', 'dz' ];
To get a detailed description of a unit, use describe
convert().describe('kg')
/*
{
abbr: 'kg'
, measure: 'mass'
, system: 'metric'
, singular: 'Kilogram'
, plural: 'Kilograms'
}
*/
To get detailed descriptions of all units, use list
.
convert().list()
/*
[{
abbr: 'kg'
, measure: 'mass'
, system: 'metric'
, singular: 'Kilogram'
, plural: 'Kilograms'
}, ...]
*/
You can also get detailed descriptions of all units for a measure:
convert().list('mass')
/*
[{
abbr: 'kg'
, measure: 'mass'
, system: 'metric'
, singular: 'Kilogram'
, plural: 'Kilograms'
}, ...]
*/
This project has been forked from ben-ng/convert-units. All the credits before the commit d950cd1 goes to the ben-ng/convert-units project contributors. After, the project will be maintained by the me (Eomm).
Licensed under MIT.
FAQs
Convert between quantities in different units
The npm package @eomm/convert-units receives a total of 0 weekly downloads. As such, @eomm/convert-units popularity was classified as not popular.
We found that @eomm/convert-units demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.