@utiliread/primitives 1.0.0-94 → 1.0.0-96
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/dist/cjs/breakdown-rule.js +58 -0
- package/dist/cjs/breakdown-rule.js.map +1 -0
- package/dist/cjs/breakdown-rule.spec.js +41 -0
- package/dist/cjs/breakdown-rule.spec.js.map +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/number-formatter.spec.js +1 -1
- package/dist/cjs/number-formatter.spec.js.map +1 -1
- package/dist/cjs/precision-number.spec.js +1 -1
- package/dist/cjs/precision-number.spec.js.map +1 -1
- package/dist/cjs/register-convention.spec.js +1 -1
- package/dist/cjs/register-convention.spec.js.map +1 -1
- package/dist/cjs/register-library.spec.js +1 -1
- package/dist/cjs/register-library.spec.js.map +1 -1
- package/dist/cjs/repository.spec.js +1 -1
- package/dist/cjs/repository.spec.js.map +1 -1
- package/dist/cjs/step.spec.js +1 -1
- package/dist/cjs/step.spec.js.map +1 -1
- package/dist/esm/breakdown-rule.d.ts +20 -0
- package/dist/esm/breakdown-rule.js +54 -0
- package/dist/esm/breakdown-rule.js.map +1 -0
- package/dist/esm/breakdown-rule.spec.d.ts +1 -0
- package/dist/esm/breakdown-rule.spec.js +39 -0
- package/dist/esm/breakdown-rule.spec.js.map +1 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/number-formatter.spec.js +1 -1
- package/dist/esm/number-formatter.spec.js.map +1 -1
- package/dist/esm/precision-number.spec.js +1 -1
- package/dist/esm/precision-number.spec.js.map +1 -1
- package/dist/esm/register-convention.spec.js +1 -1
- package/dist/esm/register-convention.spec.js.map +1 -1
- package/dist/esm/register-library.spec.js +1 -1
- package/dist/esm/register-library.spec.js.map +1 -1
- package/dist/esm/repository.spec.js +1 -1
- package/dist/esm/repository.spec.js.map +1 -1
- package/dist/esm/step.spec.js +1 -1
- package/dist/esm/step.spec.js.map +1 -1
- package/package.json +3 -2
- package/src/breakdown-rule.spec.ts +44 -0
- package/src/breakdown-rule.ts +75 -0
- package/src/index.ts +10 -6
- package/src/number-formatter.spec.ts +549 -549
- package/src/precision-number.spec.ts +28 -28
- package/src/register-convention.spec.ts +52 -52
- package/src/register-library.spec.ts +41 -41
- package/src/repository.spec.ts +20 -20
- package/src/step.spec.ts +37 -37
- package/tsconfig.cjs.json +1 -0
- package/tsconfig.json +1 -1
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { PrecisionNumber } from "./precision-number";
|
|
2
|
-
import { expect } from "
|
|
3
|
-
|
|
4
|
-
describe("precision-number", () => {
|
|
5
|
-
it("should not parse ''", () => {
|
|
6
|
-
const number = PrecisionNumber.parse("");
|
|
7
|
-
expect(Number.isNaN(number.value)).to.equal(true);
|
|
8
|
-
expect(number.precision).to.equal(0);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("should parse '1'", () => {
|
|
12
|
-
const number = PrecisionNumber.parse("1");
|
|
13
|
-
expect(number.value).to.equal(1);
|
|
14
|
-
expect(number.precision).to.equal(1);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should parse '1.'", () => {
|
|
18
|
-
const number = PrecisionNumber.parse("1.");
|
|
19
|
-
expect(number.value).to.equal(1);
|
|
20
|
-
expect(number.precision).to.equal(2);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should parse '1.0'", () => {
|
|
24
|
-
const number = PrecisionNumber.parse("1.0");
|
|
25
|
-
expect(number.value).to.equal(1);
|
|
26
|
-
expect(number.precision).to.equal(2);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
1
|
+
import { PrecisionNumber } from "./precision-number";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
|
|
4
|
+
describe("precision-number", () => {
|
|
5
|
+
it("should not parse ''", () => {
|
|
6
|
+
const number = PrecisionNumber.parse("");
|
|
7
|
+
expect(Number.isNaN(number.value)).to.equal(true);
|
|
8
|
+
expect(number.precision).to.equal(0);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should parse '1'", () => {
|
|
12
|
+
const number = PrecisionNumber.parse("1");
|
|
13
|
+
expect(number.value).to.equal(1);
|
|
14
|
+
expect(number.precision).to.equal(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should parse '1.'", () => {
|
|
18
|
+
const number = PrecisionNumber.parse("1.");
|
|
19
|
+
expect(number.value).to.equal(1);
|
|
20
|
+
expect(number.precision).to.equal(2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should parse '1.0'", () => {
|
|
24
|
+
const number = PrecisionNumber.parse("1.0");
|
|
25
|
+
expect(number.value).to.equal(1);
|
|
26
|
+
expect(number.precision).to.equal(2);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { RegisterConvention } from "./register-convention";
|
|
2
|
-
import { expect } from "
|
|
3
|
-
|
|
4
|
-
describe("getAggregate", () => {
|
|
5
|
-
it("instant register is instant", () => {
|
|
6
|
-
const result = RegisterConvention.getAggregate("flowTemperature");
|
|
7
|
-
expect(result).to.equal("instant");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("avg register is avg", () => {
|
|
11
|
-
const result = RegisterConvention.getAggregate("avgFlowTemperature");
|
|
12
|
-
expect(result).to.equal("avg");
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe("toInstant", () => {
|
|
17
|
-
it("should convert instant", () => {
|
|
18
|
-
const registerId = RegisterConvention.toInstant("flowTemperature");
|
|
19
|
-
expect(registerId).to.equal("flowTemperature");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should convert aggregate", () => {
|
|
23
|
-
const registerId = RegisterConvention.toInstant("avgFlowTemperature");
|
|
24
|
-
expect(registerId).to.equal("flowTemperature");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe("toAggregate", () => {
|
|
29
|
-
it("should convert instant to aggregate", () => {
|
|
30
|
-
const registerId = RegisterConvention.toAggregate(
|
|
31
|
-
"flowTemperature",
|
|
32
|
-
"avg",
|
|
33
|
-
);
|
|
34
|
-
expect(registerId).to.equal("avgFlowTemperature");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should convert aggregate to same aggregate", () => {
|
|
38
|
-
const registerId = RegisterConvention.toAggregate(
|
|
39
|
-
"avgFlowTemperature",
|
|
40
|
-
"avg",
|
|
41
|
-
);
|
|
42
|
-
expect(registerId).to.equal("avgFlowTemperature");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should convert aggregate to other aggregate", () => {
|
|
46
|
-
const registerId = RegisterConvention.toAggregate(
|
|
47
|
-
"avgFlowTemperature",
|
|
48
|
-
"min",
|
|
49
|
-
);
|
|
50
|
-
expect(registerId).to.equal("minFlowTemperature");
|
|
51
|
-
});
|
|
52
|
-
});
|
|
1
|
+
import { RegisterConvention } from "./register-convention";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
|
|
4
|
+
describe("getAggregate", () => {
|
|
5
|
+
it("instant register is instant", () => {
|
|
6
|
+
const result = RegisterConvention.getAggregate("flowTemperature");
|
|
7
|
+
expect(result).to.equal("instant");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("avg register is avg", () => {
|
|
11
|
+
const result = RegisterConvention.getAggregate("avgFlowTemperature");
|
|
12
|
+
expect(result).to.equal("avg");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("toInstant", () => {
|
|
17
|
+
it("should convert instant", () => {
|
|
18
|
+
const registerId = RegisterConvention.toInstant("flowTemperature");
|
|
19
|
+
expect(registerId).to.equal("flowTemperature");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should convert aggregate", () => {
|
|
23
|
+
const registerId = RegisterConvention.toInstant("avgFlowTemperature");
|
|
24
|
+
expect(registerId).to.equal("flowTemperature");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("toAggregate", () => {
|
|
29
|
+
it("should convert instant to aggregate", () => {
|
|
30
|
+
const registerId = RegisterConvention.toAggregate(
|
|
31
|
+
"flowTemperature",
|
|
32
|
+
"avg",
|
|
33
|
+
);
|
|
34
|
+
expect(registerId).to.equal("avgFlowTemperature");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should convert aggregate to same aggregate", () => {
|
|
38
|
+
const registerId = RegisterConvention.toAggregate(
|
|
39
|
+
"avgFlowTemperature",
|
|
40
|
+
"avg",
|
|
41
|
+
);
|
|
42
|
+
expect(registerId).to.equal("avgFlowTemperature");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should convert aggregate to other aggregate", () => {
|
|
46
|
+
const registerId = RegisterConvention.toAggregate(
|
|
47
|
+
"avgFlowTemperature",
|
|
48
|
+
"min",
|
|
49
|
+
);
|
|
50
|
+
expect(registerId).to.equal("minFlowTemperature");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { RegisterDefinition } from ".";
|
|
2
|
-
import { RegisterLibrary } from "./register-library";
|
|
3
|
-
import { expect } from "
|
|
4
|
-
|
|
5
|
-
const volume: RegisterDefinition = {
|
|
6
|
-
id: "volume",
|
|
7
|
-
measure: "volume",
|
|
8
|
-
aggregate: "instant",
|
|
9
|
-
units: ["cubicMeter"],
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
describe("library", () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
RegisterLibrary.reset();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should get added definition", () => {
|
|
18
|
-
RegisterLibrary.add(volume);
|
|
19
|
-
const definition = RegisterLibrary.get("volume");
|
|
20
|
-
expect(definition.id).to.equal("volume");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should add all definitions in pack", () => {
|
|
24
|
-
RegisterLibrary.add({
|
|
25
|
-
someRandomKey: volume,
|
|
26
|
-
});
|
|
27
|
-
const definition = RegisterLibrary.get("volume");
|
|
28
|
-
expect(definition.id).to.equal("volume");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should throw when getting not added register", () => {
|
|
32
|
-
expect(() => RegisterLibrary.get("volume")).to.throw();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should return all definitions when invoking all()", () => {
|
|
36
|
-
RegisterLibrary.add(volume);
|
|
37
|
-
RegisterLibrary.add(volume); // Only added once.
|
|
38
|
-
const all = RegisterLibrary.all();
|
|
39
|
-
expect(all.length).to.equal(1);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
1
|
+
import { RegisterDefinition } from ".";
|
|
2
|
+
import { RegisterLibrary } from "./register-library";
|
|
3
|
+
import { expect } from "chai";
|
|
4
|
+
|
|
5
|
+
const volume: RegisterDefinition = {
|
|
6
|
+
id: "volume",
|
|
7
|
+
measure: "volume",
|
|
8
|
+
aggregate: "instant",
|
|
9
|
+
units: ["cubicMeter"],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe("library", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
RegisterLibrary.reset();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should get added definition", () => {
|
|
18
|
+
RegisterLibrary.add(volume);
|
|
19
|
+
const definition = RegisterLibrary.get("volume");
|
|
20
|
+
expect(definition.id).to.equal("volume");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should add all definitions in pack", () => {
|
|
24
|
+
RegisterLibrary.add({
|
|
25
|
+
someRandomKey: volume,
|
|
26
|
+
});
|
|
27
|
+
const definition = RegisterLibrary.get("volume");
|
|
28
|
+
expect(definition.id).to.equal("volume");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should throw when getting not added register", () => {
|
|
32
|
+
expect(() => RegisterLibrary.get("volume")).to.throw();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should return all definitions when invoking all()", () => {
|
|
36
|
+
RegisterLibrary.add(volume);
|
|
37
|
+
RegisterLibrary.add(volume); // Only added once.
|
|
38
|
+
const all = RegisterLibrary.all();
|
|
39
|
+
expect(all.length).to.equal(1);
|
|
40
|
+
});
|
|
41
|
+
});
|
package/src/repository.spec.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Repository } from "./repository";
|
|
2
|
-
import { expect } from "
|
|
3
|
-
|
|
4
|
-
describe("ctor", () => {
|
|
5
|
-
it("creates", () => {
|
|
6
|
-
expect(Repository("gpkv", "gjoel")).to.equal("gpkv/gjoel");
|
|
7
|
-
expect(Repository("gpkv/gjoel")).to.equal("gpkv/gjoel");
|
|
8
|
-
});
|
|
9
|
-
it("throws if wrong format", () => {
|
|
10
|
-
expect(() => Repository("invalid")).to.throw();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("split", () => {
|
|
15
|
-
it("splits into correct parts", () => {
|
|
16
|
-
const { team, name } = Repository.split(Repository("gpkv", "gjoel"));
|
|
17
|
-
expect(team).to.equal("gpkv");
|
|
18
|
-
expect(name).to.equal("gjoel");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
1
|
+
import { Repository } from "./repository";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
|
|
4
|
+
describe("ctor", () => {
|
|
5
|
+
it("creates", () => {
|
|
6
|
+
expect(Repository("gpkv", "gjoel")).to.equal("gpkv/gjoel");
|
|
7
|
+
expect(Repository("gpkv/gjoel")).to.equal("gpkv/gjoel");
|
|
8
|
+
});
|
|
9
|
+
it("throws if wrong format", () => {
|
|
10
|
+
expect(() => Repository("invalid")).to.throw();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("split", () => {
|
|
15
|
+
it("splits into correct parts", () => {
|
|
16
|
+
const { team, name } = Repository.split(Repository("gpkv", "gjoel"));
|
|
17
|
+
expect(team).to.equal("gpkv");
|
|
18
|
+
expect(name).to.equal("gjoel");
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/step.spec.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { DayOfWeek, Step } from "./step";
|
|
2
|
-
|
|
3
|
-
import { DateTime } from "luxon";
|
|
4
|
-
import { expect } from "
|
|
5
|
-
|
|
6
|
-
describe("startOf", () => {
|
|
7
|
-
it("returns start of day", () => {
|
|
8
|
-
const dt = DateTime.fromISO("2020-01-11T05:00:00+01:00");
|
|
9
|
-
const result = Step.startOf(dt, "day");
|
|
10
|
-
expect(+result).to.equal(
|
|
11
|
-
+DateTime.fromISO("2020-01-11T00:00:00+01:00"),
|
|
12
|
-
);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("returns previous monday from saturday", () => {
|
|
16
|
-
const dt = DateTime.fromISO("2020-01-11T05:00:00+01:00");
|
|
17
|
-
const result = Step.startOf(dt, "week", DayOfWeek.Monday);
|
|
18
|
-
expect(+result).to.equal(
|
|
19
|
-
+DateTime.fromISO("2020-01-06T00:00:00+01:00"),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("returns same monday from monday with hour", () => {
|
|
24
|
-
const dt = DateTime.fromISO("2020-01-13T05:00:00+01:00");
|
|
25
|
-
const result = Step.startOf(dt, "week", DayOfWeek.Monday);
|
|
26
|
-
expect(+result).to.equal(
|
|
27
|
-
+DateTime.fromISO("2020-01-13T00:00:00+01:00"),
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("asDuration", () => {
|
|
33
|
-
it("should return equivalent duration", () => {
|
|
34
|
-
const duration = Step.asDuration("week");
|
|
35
|
-
expect(duration.days).to.equal(7);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
1
|
+
import { DayOfWeek, Step } from "./step";
|
|
2
|
+
|
|
3
|
+
import { DateTime } from "luxon";
|
|
4
|
+
import { expect } from "chai";
|
|
5
|
+
|
|
6
|
+
describe("startOf", () => {
|
|
7
|
+
it("returns start of day", () => {
|
|
8
|
+
const dt = DateTime.fromISO("2020-01-11T05:00:00+01:00");
|
|
9
|
+
const result = Step.startOf(dt, "day");
|
|
10
|
+
expect(+result).to.equal(
|
|
11
|
+
+DateTime.fromISO("2020-01-11T00:00:00+01:00"),
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("returns previous monday from saturday", () => {
|
|
16
|
+
const dt = DateTime.fromISO("2020-01-11T05:00:00+01:00");
|
|
17
|
+
const result = Step.startOf(dt, "week", DayOfWeek.Monday);
|
|
18
|
+
expect(+result).to.equal(
|
|
19
|
+
+DateTime.fromISO("2020-01-06T00:00:00+01:00"),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("returns same monday from monday with hour", () => {
|
|
24
|
+
const dt = DateTime.fromISO("2020-01-13T05:00:00+01:00");
|
|
25
|
+
const result = Step.startOf(dt, "week", DayOfWeek.Monday);
|
|
26
|
+
expect(+result).to.equal(
|
|
27
|
+
+DateTime.fromISO("2020-01-13T00:00:00+01:00"),
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("asDuration", () => {
|
|
33
|
+
it("should return equivalent duration", () => {
|
|
34
|
+
const duration = Step.asDuration("week");
|
|
35
|
+
expect(duration.days).to.equal(7);
|
|
36
|
+
});
|
|
37
|
+
});
|
package/tsconfig.cjs.json
CHANGED