Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

convert-units

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convert-units - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

test/best.js

31

lib/index.js

@@ -99,2 +99,33 @@ var convert

/**
* Converts the unit to the best available unit.
*/
Converter.prototype.toBest = function() {
if(!this.origin)
throw new Error('.toBest must be called after .from');
var best;
/**
Looks through every possibility for the 'best' available unit.
i.e. Where the value has the fewest numbers before the decimal point,
but is still higher than 1.
*/
each(this.possibilities(), function(possibility) {
var unit = this.describe(possibility);
if (unit.system === this.origin.system) {
var result = this.to(possibility);
if (!best || (result >= 1 && result < best.val)) {
best = {
val: result,
unit: possibility,
singular: unit.singular,
plural: unit.plural
};
}
}
}.bind(this));
return best;
}
/**
* Finds the unit

@@ -101,0 +132,0 @@ */

2

package.json
{
"name": "convert-units",
"version": "0.4.0",
"version": "0.4.1",
"description": "Convert between quantities in different units",

@@ -5,0 +5,0 @@ "main": "lib",

@@ -36,2 +36,8 @@ convert-units

You can ask `convert-units` to select the best unit for you:
```js
convert(1200).from('mm').toBest()
// 1.2 Meters (the smallest unit with a value above 1)
```
You can get a list of the measurement types supported with `.measures`

@@ -38,0 +44,0 @@

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