engineering-unit-converter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/converter.d.ts +13 -0
- package/dist/engineering-unit-converter.js +733 -0
- package/dist/engineering-unit-converter.umd.cjs +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/types.d.ts +258 -0
- package/dist/units/acceleration.d.ts +11 -0
- package/dist/units/area.d.ts +11 -0
- package/dist/units/density.d.ts +11 -0
- package/dist/units/electric-charge.d.ts +11 -0
- package/dist/units/electric-current.d.ts +11 -0
- package/dist/units/energy.d.ts +11 -0
- package/dist/units/force.d.ts +11 -0
- package/dist/units/length.d.ts +11 -0
- package/dist/units/mass-flow.d.ts +11 -0
- package/dist/units/mass.d.ts +11 -0
- package/dist/units/power.d.ts +11 -0
- package/dist/units/pressure-manometric.d.ts +11 -0
- package/dist/units/pressure.d.ts +11 -0
- package/dist/units/speed.d.ts +11 -0
- package/dist/units/standard-volumetric-flow.d.ts +11 -0
- package/dist/units/surface-tension.d.ts +11 -0
- package/dist/units/time.d.ts +11 -0
- package/dist/units/viscosity.d.ts +11 -0
- package/dist/units/voltage.d.ts +11 -0
- package/dist/units/volume.d.ts +11 -0
- package/dist/units/volumetric-flow.d.ts +11 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
engineering-unit-converter
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
A light and simple library for make all type measures conversions and manipulations.
|
|
5
|
+
Used [convert-units](https://github.com/ben-ng/convert-units) as a reference.
|
|
6
|
+
|
|
7
|
+
Installation
|
|
8
|
+
-----
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm engineering-unit-converter --save
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Usage
|
|
15
|
+
-----
|
|
16
|
+
|
|
17
|
+
`engineering-unit-converter` uses TypeScript to infer the avalaible units, I strongly recommend to use TypeScript for make the dev experience better.
|
|
18
|
+
|
|
19
|
+
Using this library is simple, the above snippet shows a example:
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { massFlow } from 'engineering-unit-converter'
|
|
24
|
+
const newValue = massFlow(65000).from('lb/day').to('kg/h')
|
|
25
|
+
console.log(newValue) //1.2284783333333333
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Available units
|
|
29
|
+
-----
|
|
30
|
+
|
|
31
|
+
- acceleration
|
|
32
|
+
- area
|
|
33
|
+
- density
|
|
34
|
+
- electricCharge
|
|
35
|
+
- electricCurrent
|
|
36
|
+
- energy
|
|
37
|
+
- force
|
|
38
|
+
- length
|
|
39
|
+
- massFlow
|
|
40
|
+
- mass
|
|
41
|
+
- power
|
|
42
|
+
- pressureManometric
|
|
43
|
+
- pressure
|
|
44
|
+
- speed
|
|
45
|
+
- standardVolumetricFlow
|
|
46
|
+
- surfaceTension
|
|
47
|
+
- time
|
|
48
|
+
- viscosity
|
|
49
|
+
- voltage
|
|
50
|
+
- volume
|
|
51
|
+
- volumetricFlow
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type MeasurementUnits, type Measurement } from './types';
|
|
2
|
+
declare class Converter<T extends Measurement> {
|
|
3
|
+
readonly _definitions: T;
|
|
4
|
+
readonly _val: number;
|
|
5
|
+
_fromUnit: MeasurementUnits<T> | null;
|
|
6
|
+
constructor(numerator: number, _definitions: T);
|
|
7
|
+
from<U extends MeasurementUnits<T>>(fromUnit: U): Converter<T>;
|
|
8
|
+
to<U extends MeasurementUnits<T>>(toUnit: U): number;
|
|
9
|
+
_getUnit(unit: MeasurementUnits<T>): number;
|
|
10
|
+
_checkUnit(unit: MeasurementUnits<T>): void;
|
|
11
|
+
}
|
|
12
|
+
declare const createConverter: <T extends Measurement>(definitions: T) => (val: number) => Converter<T>;
|
|
13
|
+
export default createConverter;
|