Skip to content

Commit

Permalink
speed
Browse files Browse the repository at this point in the history
  • Loading branch information
itallonet committed May 30, 2024
1 parent 50c8ab6 commit ea726d5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ const hertzToMegahertzResult = Frequency(1000, { from: "Hz", to: "MHz" });
console.log(hertzToMegahertzResult)


```

- Speed (m/s, km/h, m/h, knot, ft/s)

``` js

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

const meterPerSecondToKilometerPerHour = Speed(1000, { from: "m/s", to: "km/h" });
console.log(meterPerSecondToKilometerPerHour)


```

## Author
Expand All @@ -92,6 +104,5 @@ console.log(hertzToMegahertzResult)

## Roadmap

- Speed
- Pressure
- Digital
11 changes: 11 additions & 0 deletions RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ Frequency(1000, { from: "Hz", to: "rpm" }) execution time: 0.018ms
Frequency(1000, { from: "Hz", to: "deg/s" }) execution time: 0.015ms
Frequency(1000, { from: "Hz", to: "rad/s" }) execution time: 0.018ms

```

# Speed Test

```js

Speed(1000, { from: "m/s", to: "km/h" }) execution time: 0.087ms
Speed(1000, { from: "m/s", to: "knot" }) execution time: 0.009ms
Speed(1000, { from: "km/h", to: "knot" }) execution time: 0.009ms
Speed(1000, { from: "knot", to: "km/h" }) execution time: 0.009ms

```
19 changes: 18 additions & 1 deletion __test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Length, Area, Mass, Volume, Temperature, Time, Frequency } = require("./module")
const { Length, Area, Mass, Volume, Temperature, Time, Frequency, Speed } = require("./module")

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

console.info("Speed")

tests = [
{ from: "m/s", to: "km/h" },
{ from: "m/s", to: "knot" },
{ from: "km/h", to: "knot" },
{ from: "knot", to: "km/h" },
]

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

__test();
3 changes: 2 additions & 1 deletion module.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
Volume: require("./source/volume"),
Temperature: require("./source/temperature"),
Time: require("./source/time"),
Frequency: require("./source/frequency")
Frequency: require("./source/frequency"),
Speed: require("./source/speed")
}
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.7.0",
"version": "0.8.0",
"description": "Simple and easy to use unit converter for javascript in general",
"main": "module.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions source/speed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Converter = require("./converter");

function Speed(input, options) {
const conversionFactors = {
"m/s": 1,
"km/h": 1 / 3.6,
"m/h": 1 / 1609.344,
"knot": 1 / 1.943844,
"ft/s": 1 / 3.28084
};

return Converter(input, options, conversionFactors);
}

module.exports = Speed;

0 comments on commit ea726d5

Please sign in to comment.