umt 2.1.1 → 2.1.2
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/module/Unit/index.d.ts +1 -0
- package/module/Unit/index.js +2 -0
- package/module/Unit/index.js.map +1 -0
- package/module/Unit/unitConverterInitialization.d.ts +1 -0
- package/module/Unit/unitConverterInitialization.js +4 -0
- package/module/Unit/unitConverterInitialization.js.map +1 -0
- package/module/es5/Unit/index.d.ts +1 -0
- package/module/es5/Unit/index.js +16 -0
- package/module/es5/Unit/unitConverterInitialization.d.ts +1 -0
- package/module/es5/Unit/unitConverterInitialization.js +13 -0
- package/module/es5/index.d.ts +1 -0
- package/module/es5/index.js +11 -0
- package/module/es5/tests/unit/Unit/unitConverterInitialization.test.d.ts +1 -0
- package/module/es5/tests/unit/Unit/unitConverterInitialization.test.js +38 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/index.d.ts +1 -0
- package/module/index.js +1 -0
- package/module/index.js.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./unitConverterInitialization";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Unit/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unitConverterInitialization: <T extends { [k in K]: number; }, K extends string | number | symbol>(toBaseUnitRatios: T) => (value: number, from: keyof T, to: keyof T) => number;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { division } from "../Math/division";
|
|
2
|
+
import { multiplication } from "../Math/multiplication";
|
|
3
|
+
export const unitConverterInitialization = (toBaseUnitRatios) => (value, from, to) => multiplication(division(value, toBaseUnitRatios[from]), toBaseUnitRatios[to]);
|
|
4
|
+
//# sourceMappingURL=unitConverterInitialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unitConverterInitialization.js","sourceRoot":"","sources":["../../src/Unit/unitConverterInitialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,CAAC,MAAM,2BAA2B,GACtC,CAME,gBAAmB,EACnB,EAAE,CACJ,CAAC,KAAa,EAAE,IAAa,EAAE,EAAW,EAAE,EAAE,CAC5C,cAAc,CACZ,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC,EACvC,gBAAgB,CAAC,EAAE,CAAC,CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./unitConverterInitialization";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _unitConverterInitialization = require("./unitConverterInitialization");
|
|
7
|
+
Object.keys(_unitConverterInitialization).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _unitConverterInitialization[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _unitConverterInitialization[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unitConverterInitialization: <T extends { [k in K]: number; }, K extends string | number | symbol>(toBaseUnitRatios: T) => (value: number, from: keyof T, to: keyof T) => number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unitConverterInitialization = void 0;
|
|
7
|
+
var _division = require("@/Math/division");
|
|
8
|
+
var _multiplication = require("@/Math/multiplication");
|
|
9
|
+
var unitConverterInitialization = exports.unitConverterInitialization = function unitConverterInitialization(toBaseUnitRatios) {
|
|
10
|
+
return function (value, from, to) {
|
|
11
|
+
return (0, _multiplication.multiplication)((0, _division.division)(value, toBaseUnitRatios[from]), toBaseUnitRatios[to]);
|
|
12
|
+
};
|
|
13
|
+
};
|
package/module/es5/index.d.ts
CHANGED
package/module/es5/index.js
CHANGED
|
@@ -168,6 +168,17 @@ Object.keys(_UA).forEach(function (key) {
|
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
|
+
var _Unit = require("./Unit");
|
|
172
|
+
Object.keys(_Unit).forEach(function (key) {
|
|
173
|
+
if (key === "default" || key === "__esModule") return;
|
|
174
|
+
if (key in exports && exports[key] === _Unit[key]) return;
|
|
175
|
+
Object.defineProperty(exports, key, {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function get() {
|
|
178
|
+
return _Unit[key];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
171
182
|
var _Validate = require("./Validate");
|
|
172
183
|
Object.keys(_Validate).forEach(function (key) {
|
|
173
184
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _unitConverterInitialization = require("@/Unit/unitConverterInitialization");
|
|
4
|
+
var convertWaterUnit = (0, _unitConverterInitialization.unitConverterInitialization)({
|
|
5
|
+
L: 1,
|
|
6
|
+
mL: 1000,
|
|
7
|
+
cup: 4.227,
|
|
8
|
+
m3: 0.001
|
|
9
|
+
});
|
|
10
|
+
describe("convertWaterUnit", function () {
|
|
11
|
+
it("should correctly convert between L and mL", function () {
|
|
12
|
+
expect(convertWaterUnit(1, "L", "mL")).toBeCloseTo(1000);
|
|
13
|
+
expect(convertWaterUnit(1000, "mL", "L")).toBeCloseTo(1);
|
|
14
|
+
});
|
|
15
|
+
it("should correctly convert between L and cup", function () {
|
|
16
|
+
expect(convertWaterUnit(1, "L", "cup")).toBeCloseTo(4.227);
|
|
17
|
+
expect(convertWaterUnit(1, "cup", "L")).toBeCloseTo(0.237);
|
|
18
|
+
});
|
|
19
|
+
it("should correctly convert between L and m3", function () {
|
|
20
|
+
expect(convertWaterUnit(1, "m3", "L")).toBeCloseTo(1000);
|
|
21
|
+
expect(convertWaterUnit(1000, "L", "m3")).toBeCloseTo(1);
|
|
22
|
+
});
|
|
23
|
+
it("should handle zero values correctly", function () {
|
|
24
|
+
expect(convertWaterUnit(0, "L", "mL")).toBe(0);
|
|
25
|
+
expect(convertWaterUnit(0, "cup", "m3")).toBe(0);
|
|
26
|
+
});
|
|
27
|
+
it("should return same value when converting to same unit", function () {
|
|
28
|
+
expect(convertWaterUnit(5, "L", "L")).toBe(5);
|
|
29
|
+
expect(convertWaterUnit(100, "mL", "mL")).toBe(100);
|
|
30
|
+
});
|
|
31
|
+
it("should maintain value in round-trip conversions", function () {
|
|
32
|
+
var original = 5;
|
|
33
|
+
var roundTrip = convertWaterUnit(convertWaterUnit(original, "L", "mL"), "mL", "L");
|
|
34
|
+
expect(roundTrip).toBeCloseTo(original);
|
|
35
|
+
var cupRoundTrip = convertWaterUnit(convertWaterUnit(original, "cup", "m3"), "m3", "cup");
|
|
36
|
+
expect(cupRoundTrip).toBeCloseTo(original);
|
|
37
|
+
});
|
|
38
|
+
});
|