Skip to content

Commit

Permalink
frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
itallonet committed May 30, 2024
1 parent 761574e commit 50c8ab6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ import { Time } from "@itallonet/unit-converter";
const minuteToYearResult = Time(1000, { from: "min", to: "year" });
console.log(minuteToYearResult)


```

- Frequency (Hz, mHz, kHz, MHz, GHz, THz, rpm, deg/s, rad/s)

``` js

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

const hertzToMegahertzResult = Frequency(1000, { from: "Hz", to: "MHz" });
console.log(hertzToMegahertzResult)


```

## Author
Expand All @@ -79,7 +92,6 @@ console.log(minuteToYearResult)

## Roadmap

- Frequency
- Speed
- Pressure
- Digital
14 changes: 14 additions & 0 deletions RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,18 @@ Time(1000, { from: "ms", to: "h" }) execution time: 0.014ms
Time(1000, { from: "ms", to: "d" }) execution time: 0.031ms
Time(1000, { from: "ms", to: "year" }) execution time: 0.017ms

```

# Frequency Test

```js

Frequency(1000, { from: "Hz", to: "kHz" }) execution time: 0.106ms
Frequency(1000, { from: "Hz", to: "MHz" }) execution time: 0.018ms
Frequency(1000, { from: "Hz", to: "GHz" }) execution time: 0.017ms
Frequency(1000, { from: "Hz", to: "THz" }) execution time: 0.017ms
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

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

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

//todo
// test time
console.info("Frequency")

tests = [
{ from: "Hz", to: "kHz" },
{ from: "Hz", to: "MHz" },
{ from: "Hz", to: "GHz" },
{ from: "Hz", to: "THz" },
{ from: "Hz", to: "rpm" },
{ from: "Hz", to: "deg/s" },
{ from: "Hz", to: "rad/s" },
]

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

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

module.exports = { Length, Area, Mass, Volume, Temperature, Time }
module.exports = {
Length: require("./source/length"),
Area: require("./source/area"),
Mass: require("./source/mass"),
Volume: require("./source/volume"),
Temperature: require("./source/temperature"),
Time: require("./source/time"),
Frequency: require("./source/frequency")
}
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.6.0",
"version": "0.7.0",
"description": "Simple and easy to use unit converter for javascript in general",
"main": "module.js",
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions source/frequency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Converter = require("./converter");

function Frequency(input, options) {
const conversionFactors = {
Hz: 1,
mHz: 1e-3,
kHz: 1e3,
MHz: 1e6,
GHz: 1e9,
THz: 1e12,
rpm: 1 / 60,
"deg/s": 1 / 360,
"rad/s": 1 / (2 * Math.PI)
};

return Converter(input, options, conversionFactors);
}

module.exports = Frequency;

0 comments on commit 50c8ab6

Please sign in to comment.