diff --git a/README.md b/README.md index 38f3b05..a106e5e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -92,6 +104,5 @@ console.log(hertzToMegahertzResult) ## Roadmap -- Speed - Pressure - Digital \ No newline at end of file diff --git a/RESULTS.md b/RESULTS.md index 115c7e8..b5650ec 100644 --- a/RESULTS.md +++ b/RESULTS.md @@ -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 + ``` \ No newline at end of file diff --git a/__test.js b/__test.js index 55a6142..0667f1f 100644 --- a/__test.js +++ b/__test.js @@ -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!") @@ -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(); \ No newline at end of file diff --git a/module.js b/module.js index ea52acd..643cade 100644 --- a/module.js +++ b/module.js @@ -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") } \ No newline at end of file diff --git a/package.json b/package.json index 275bf81..665f285 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/source/speed.js b/source/speed.js new file mode 100644 index 0000000..bfc3256 --- /dev/null +++ b/source/speed.js @@ -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;