Skip to content

Commit

Permalink
volume
Browse files Browse the repository at this point in the history
  • Loading branch information
itallonet committed May 30, 2024
1 parent 78ec0e6 commit 5944c09
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,24 @@ console.log(gramToKiloResult)

```


- Volume (mm3, cm3, ml, l, kl, m3, km3, tsp, Tbs, in3, fl-oz, cup, pnt, qt, gal, ft3, yd3)

``` js

import { Volume } from "@itallonet/unit-converter";

const milliliterToLiterResult = Mass(1000, { from: "ml", to: "l" });
console.log(milliliterToLiterResult)

```

## Author

- [@itallonet](https://www.github.com/itallonet)

## Roadmap

- Volume
- Temperature
- Time
- Frequency
Expand Down
14 changes: 14 additions & 0 deletions RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ Mass(1000, { from: "t", to: "oz" }) execution time: 0.013ms
Mass(1000, { from: "oz", to: "g" }) execution time: 0.006ms
Mass(1000, { from: "g", to: "oz" }) execution time: 0.006ms

```

# Volume Test

```js

Volume(1000, { from: "ml", to: "l" }) execution time: 0.066ms
Volume(1000, { from: "ml", to: "cm3" }) execution time: 0.013ms
Volume(1000, { from: "ml", to: "m3" }) execution time: 0.013ms
Volume(1000, { from: "ml", to: "ft3" }) execution time: 0.017ms
Volume(1000, { from: "ml", to: "in3" }) execution time: 0.013ms
Volume(1000, { from: "ml", to: "gal" }) execution time: 0.015ms
Volume(1000, { from: "ml", to: "fl-oz" }) execution time: 0.014ms

```
23 changes: 21 additions & 2 deletions __test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Length, Area, Mass } = require("./module")
const { Length, Area, Mass, Volume } = require("./module")

const __test = () => {
console.info("Init tests!")
Expand Down Expand Up @@ -56,7 +56,6 @@ const __test = () => {
console.log(`Area(1000, { from: "${test.from}", to: "${test.to}" }) = ${result}`);
});

// todo
console.info("Mass")

tests = [
Expand All @@ -82,6 +81,26 @@ const __test = () => {
console.timeEnd(label);
console.log(`Mass(1000, { from: "${test.from}", to: "${test.to}" }) = ${result}`);
});

console.info("Volume")

tests = [
{ from: "ml", to: "l" },
{ from: "ml", to: "cm3" },
{ from: "ml", to: "m3" },
{ from: "ml", to: "ft3" },
{ from: "ml", to: "in3" },
{ from: "ml", to: "gal" },
{ from: "ml", to: "fl-oz" },
]

tests.forEach((test) => {
const label = `Volume(1000, { from: "${test.from}", to: "${test.to}" }) execution time`;
console.time(label);
const result = Volume(1000, test);
console.timeEnd(label);
console.log(`Volume(1000, { from: "${test.from}", to: "${test.to}" }) = ${result}`);
});
}

__test();
4 changes: 2 additions & 2 deletions module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Length = require("./source/length"), Area = require("./source/area"),
Mass = require("./source/mass");
Mass = require("./source/mass"), Volume = require("./source/volume");

module.exports = { Length, Area, Mass }
module.exports = { Length, Area, Mass, Volume }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itallonet/unit-converter",
"version": "0.3.0",
"version": "0.4.0",
"description": "Simple and easy to use unit converter for javascript in general",
"main": "module.js",
"scripts": {
Expand Down
27 changes: 27 additions & 0 deletions source/volume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Converter = require("./converter");

function Volume(input, options) {
const conversionFactors = {
mm3: 1,
cm3: 1000,
ml: 1000,
l: 1000000,
kl: 1000000000,
m3: 1000000000,
km3: 1e+18,
tsp: 4928.92,
Tbs: 14786.8,
in3: 16387.064,
"fl-oz": 29573.53,
cup: 236588.24,
pnt: 473176.47,
qt: 946352.94,
gal: 3785411.78,
ft3: 2.83168466e+10,
yd3: 7.64554858e+11
};

return Converter(input, options, conversionFactors);
}

module.exports = Volume;

0 comments on commit 5944c09

Please sign in to comment.