@utiliread/primitives 1.0.0-147 → 1.0.0-148

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.
Files changed (123) hide show
  1. package/dist/index.js +120 -25
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +120 -25
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/precision-number.d.ts +10 -0
  6. package/package.json +9 -6
  7. package/src/aggregate-id.ts +2 -9
  8. package/src/breakdown-rule.spec.ts +61 -61
  9. package/src/breakdown-rule.ts +58 -58
  10. package/src/csv.spec.ts +42 -42
  11. package/src/csv.ts +8 -9
  12. package/src/cursor-navigation-state.spec.ts +194 -194
  13. package/src/cursor-navigation-state.ts +168 -168
  14. package/src/index.ts +61 -61
  15. package/src/measure-id.ts +17 -17
  16. package/src/measures/duration.ts +11 -11
  17. package/src/measures/energy.ts +13 -13
  18. package/src/measures/humidity.ts +3 -3
  19. package/src/measures/infocode.ts +3 -3
  20. package/src/measures/mass-flow.ts +19 -19
  21. package/src/measures/mass.ts +10 -10
  22. package/src/measures/noise.ts +5 -5
  23. package/src/measures/power.ts +23 -23
  24. package/src/measures/pressure.ts +9 -9
  25. package/src/measures/reactive-energy.ts +7 -7
  26. package/src/measures/reactive-power.ts +3 -3
  27. package/src/measures/temperature.ts +9 -9
  28. package/src/measures/time.ts +3 -3
  29. package/src/measures/volume-flow.ts +25 -25
  30. package/src/measures/volume.ts +3 -3
  31. package/src/medium.spec.ts +12 -12
  32. package/src/medium.ts +47 -47
  33. package/src/number-formatter.spec.ts +570 -570
  34. package/src/number-formatter.ts +126 -126
  35. package/src/optional.ts +1 -1
  36. package/src/precision-number.spec.ts +382 -382
  37. package/src/precision-number.ts +229 -229
  38. package/src/register-convention.spec.ts +52 -52
  39. package/src/register-convention.ts +70 -70
  40. package/src/register-definition.ts +23 -23
  41. package/src/register-id.ts +288 -288
  42. package/src/register-library.spec.ts +41 -41
  43. package/src/register-library.ts +64 -64
  44. package/src/register-pack.ts +5 -5
  45. package/src/register-utils.ts +6 -6
  46. package/src/registers/acoustic-noise.ts +52 -52
  47. package/src/registers/ambient-temperature.ts +52 -52
  48. package/src/registers/axioma-infocode.ts +16 -16
  49. package/src/registers/consumer.ts +17 -17
  50. package/src/registers/cooling-energy-inlet.ts +23 -23
  51. package/src/registers/cooling-energy-outlet.ts +23 -23
  52. package/src/registers/cooling-energy.ts +23 -23
  53. package/src/registers/cooling.ts +113 -113
  54. package/src/registers/device-addresses-kamdraft.ts +14 -14
  55. package/src/registers/device-addresses-msisdn.ts +14 -14
  56. package/src/registers/device-addresses-tchlr.ts +14 -14
  57. package/src/registers/device-addresses-wmbus.ts +17 -17
  58. package/src/registers/device-date-time.ts +9 -9
  59. package/src/registers/device-date.ts +9 -9
  60. package/src/registers/device-nominal-diameter.ts +9 -9
  61. package/src/registers/device-permanent-volume-flow.ts +9 -9
  62. package/src/registers/device-registers.ts +9 -9
  63. package/src/registers/device-samples.ts +37 -37
  64. package/src/registers/device-software-version.ts +8 -8
  65. package/src/registers/device-time.ts +9 -9
  66. package/src/registers/device.ts +16 -16
  67. package/src/registers/diehl-infocode.ts +44 -44
  68. package/src/registers/electrical-energy.ts +23 -23
  69. package/src/registers/energy-inlet.ts +23 -23
  70. package/src/registers/energy-outlet.ts +23 -23
  71. package/src/registers/error-operating-time.ts +23 -23
  72. package/src/registers/flow-temperature-aux.ts +52 -52
  73. package/src/registers/flow-temperature-inlet.ts +52 -52
  74. package/src/registers/flow-temperature-outlet.ts +52 -52
  75. package/src/registers/flow-temperature.ts +52 -52
  76. package/src/registers/heat-energy-inlet.ts +65 -65
  77. package/src/registers/heat-energy-outlet.ts +65 -65
  78. package/src/registers/heat-energy.ts +65 -65
  79. package/src/registers/index.ts +71 -71
  80. package/src/registers/infocode.ts +70 -70
  81. package/src/registers/kamstrup-module-type.ts +8 -8
  82. package/src/registers/kamstrup-multical-infocode.ts +58 -58
  83. package/src/registers/landis-gyr-infocode.ts +23 -23
  84. package/src/registers/landis-gyr-mbus-status.ts +23 -23
  85. package/src/registers/mass-flow-inlet.ts +52 -52
  86. package/src/registers/mass-flow-outlet.ts +52 -52
  87. package/src/registers/mass-flow.ts +52 -52
  88. package/src/registers/mass-inlet.ts +23 -23
  89. package/src/registers/mass-outlet.ts +23 -23
  90. package/src/registers/mass.ts +23 -23
  91. package/src/registers/mbus-format-string-signature.ts +8 -8
  92. package/src/registers/none.ts +8 -8
  93. package/src/registers/operating-time.ts +23 -23
  94. package/src/registers/place.ts +31 -31
  95. package/src/registers/power-inlet.ts +52 -52
  96. package/src/registers/power-outlet.ts +52 -52
  97. package/src/registers/power.ts +52 -52
  98. package/src/registers/pressure-inlet.ts +52 -52
  99. package/src/registers/pressure-outlet.ts +52 -52
  100. package/src/registers/pressure.ts +52 -52
  101. package/src/registers/radiator-temperature.ts +52 -52
  102. package/src/registers/reactive-energy.ts +23 -23
  103. package/src/registers/relative-humidity.ts +8 -8
  104. package/src/registers/remaining-battery-time.ts +23 -23
  105. package/src/registers/time-last-exact-overhearing-arrived.ts +19 -19
  106. package/src/registers/time-last-installation-mounted.ts +19 -19
  107. package/src/registers/time-last-possible-candidate-overhearing-arrived.ts +21 -21
  108. package/src/registers/time-last-sampled.ts +19 -19
  109. package/src/registers/time.ts +45 -45
  110. package/src/registers/volume-flow-inlet.ts +52 -52
  111. package/src/registers/volume-flow-outlet.ts +52 -52
  112. package/src/registers/volume-flow.ts +52 -52
  113. package/src/registers/volume-inlet.ts +23 -23
  114. package/src/registers/volume-outlet.ts +23 -23
  115. package/src/registers/volume-pulse-input-a.ts +23 -23
  116. package/src/registers/volume-pulse-input-b.ts +23 -23
  117. package/src/registers/volume.ts +23 -23
  118. package/src/repository.spec.ts +30 -30
  119. package/src/repository.ts +26 -26
  120. package/src/step.spec.ts +37 -37
  121. package/src/step.ts +45 -45
  122. package/src/time-or-rule.ts +42 -42
  123. package/src/unit-id.ts +108 -108
@@ -1,23 +1,23 @@
1
- import type { RegisterDefinition } from "../register-definition";
2
- import { units } from "../measures/volume";
3
-
4
- export const pulseInputBVolume: RegisterDefinition = {
5
- id: "pulseInputBVolume",
6
- measure: "volume",
7
- aggregate: "instant",
8
- units,
9
- };
10
-
11
- export const diffPulseInputBVolume: RegisterDefinition = {
12
- id: "diffPulseInputBVolume",
13
- measure: "volume",
14
- aggregate: "diff",
15
- units,
16
- };
17
-
18
- export const cntPulseInputBVolume: RegisterDefinition = {
19
- id: "cntPulseInputBVolume",
20
- measure: "volume",
21
- aggregate: "cnt",
22
- units: ["unitless"],
23
- };
1
+ import type { RegisterDefinition } from "../register-definition";
2
+ import { units } from "../measures/volume";
3
+
4
+ export const pulseInputBVolume: RegisterDefinition = {
5
+ id: "pulseInputBVolume",
6
+ measure: "volume",
7
+ aggregate: "instant",
8
+ units,
9
+ };
10
+
11
+ export const diffPulseInputBVolume: RegisterDefinition = {
12
+ id: "diffPulseInputBVolume",
13
+ measure: "volume",
14
+ aggregate: "diff",
15
+ units,
16
+ };
17
+
18
+ export const cntPulseInputBVolume: RegisterDefinition = {
19
+ id: "cntPulseInputBVolume",
20
+ measure: "volume",
21
+ aggregate: "cnt",
22
+ units: ["unitless"],
23
+ };
@@ -1,23 +1,23 @@
1
- import type { RegisterDefinition } from "../register-definition";
2
- import { units } from "../measures/volume";
3
-
4
- export const volume: RegisterDefinition = {
5
- id: "volume",
6
- measure: "volume",
7
- aggregate: "instant",
8
- units,
9
- };
10
-
11
- export const diffVolume: RegisterDefinition = {
12
- id: "diffVolume",
13
- measure: "volume",
14
- aggregate: "diff",
15
- units,
16
- };
17
-
18
- export const cntVolume: RegisterDefinition = {
19
- id: "cntVolume",
20
- measure: "volume",
21
- aggregate: "cnt",
22
- units: ["unitless"],
23
- };
1
+ import type { RegisterDefinition } from "../register-definition";
2
+ import { units } from "../measures/volume";
3
+
4
+ export const volume: RegisterDefinition = {
5
+ id: "volume",
6
+ measure: "volume",
7
+ aggregate: "instant",
8
+ units,
9
+ };
10
+
11
+ export const diffVolume: RegisterDefinition = {
12
+ id: "diffVolume",
13
+ measure: "volume",
14
+ aggregate: "diff",
15
+ units,
16
+ };
17
+
18
+ export const cntVolume: RegisterDefinition = {
19
+ id: "cntVolume",
20
+ measure: "volume",
21
+ aggregate: "cnt",
22
+ units: ["unitless"],
23
+ };
@@ -1,30 +1,30 @@
1
- import { Repository } from "./repository";
2
- import { expect } from "chai";
3
-
4
- describe("ctor", () => {
5
- it.only("creates", () => {
6
- expect(Repository("gpkv", "gjoel")).to.equal("gpkv/gjoel");
7
- expect(Repository("gpkv/gjoel")).to.equal("gpkv/gjoel");
8
- });
9
- it.only("throws if wrong format", () => {
10
- expect(() => Repository("invalid")).to.throw();
11
- expect(() => Repository("[object%20Object]", "dashboard")).to.throw();
12
- });
13
- });
14
-
15
- describe("isRepository", () => {
16
- it("should correctly determine if input is a Repository", () => {
17
- expect(Repository.isRepository("some/test")).to.equal(true);
18
- expect(Repository.isRepository("so-me/te-st")).to.equal(true);
19
- expect(Repository.isRepository("NOT/REPO")).to.equal(false);
20
- expect(Repository.isRepository("notarepo")).to.equal(false);
21
- });
22
- });
23
-
24
- describe("split", () => {
25
- it("splits into correct parts", () => {
26
- const { team, name } = Repository.split(Repository("gpkv", "gjoel"));
27
- expect(team).to.equal("gpkv");
28
- expect(name).to.equal("gjoel");
29
- });
30
- });
1
+ import { Repository } from "./repository";
2
+ import { expect } from "chai";
3
+
4
+ describe("ctor", () => {
5
+ it.only("creates", () => {
6
+ expect(Repository("gpkv", "gjoel")).to.equal("gpkv/gjoel");
7
+ expect(Repository("gpkv/gjoel")).to.equal("gpkv/gjoel");
8
+ });
9
+ it.only("throws if wrong format", () => {
10
+ expect(() => Repository("invalid")).to.throw();
11
+ expect(() => Repository("[object%20Object]", "dashboard")).to.throw();
12
+ });
13
+ });
14
+
15
+ describe("isRepository", () => {
16
+ it("should correctly determine if input is a Repository", () => {
17
+ expect(Repository.isRepository("some/test")).to.equal(true);
18
+ expect(Repository.isRepository("so-me/te-st")).to.equal(true);
19
+ expect(Repository.isRepository("NOT/REPO")).to.equal(false);
20
+ expect(Repository.isRepository("notarepo")).to.equal(false);
21
+ });
22
+ });
23
+
24
+ describe("split", () => {
25
+ it("splits into correct parts", () => {
26
+ const { team, name } = Repository.split(Repository("gpkv", "gjoel"));
27
+ expect(team).to.equal("gpkv");
28
+ expect(name).to.equal("gjoel");
29
+ });
30
+ });
package/src/repository.ts CHANGED
@@ -1,26 +1,26 @@
1
- // This is clearly not correct but it provides some amazing type safety
2
- export type Repository = "some/repo";
3
-
4
- export function Repository(repo: string): Repository;
5
- export function Repository(team: string, name: string): Repository;
6
- export function Repository(repoOrTeam: string, name?: string): Repository {
7
- const repo = name ? `${repoOrTeam}/${name}` : repoOrTeam;
8
- if (!Repository.isRepository(repo)) {
9
- throw new TypeError("Invalid repository format");
10
- }
11
- return repo;
12
- }
13
-
14
- export namespace Repository {
15
- export function isRepository(input: string): input is Repository {
16
- return /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(input);
17
- }
18
-
19
- export function split(repo: Repository) {
20
- const parts = repo.split("/");
21
- return {
22
- team: parts[0],
23
- name: parts[1],
24
- };
25
- }
26
- }
1
+ // This is clearly not correct but it provides some amazing type safety
2
+ export type Repository = "some/repo";
3
+
4
+ export function Repository(repo: string): Repository;
5
+ export function Repository(team: string, name: string): Repository;
6
+ export function Repository(repoOrTeam: string, name?: string): Repository {
7
+ const repo = name ? `${repoOrTeam}/${name}` : repoOrTeam;
8
+ if (!Repository.isRepository(repo)) {
9
+ throw new TypeError("Invalid repository format");
10
+ }
11
+ return repo;
12
+ }
13
+
14
+ export namespace Repository {
15
+ export function isRepository(input: string): input is Repository {
16
+ return /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(input);
17
+ }
18
+
19
+ export function split(repo: Repository) {
20
+ const parts = repo.split("/");
21
+ return {
22
+ team: parts[0],
23
+ name: parts[1],
24
+ };
25
+ }
26
+ }
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 "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
- });
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/src/step.ts CHANGED
@@ -1,45 +1,45 @@
1
- import { DateTime, Duration } from "luxon";
2
-
3
- export type Step = "hour" | "day" | "week" | "month" | "year";
4
-
5
- export enum DayOfWeek {
6
- Monday = 1,
7
- Tuesday = 2,
8
- Wednesday = 3,
9
- Thursday = 4,
10
- Friday = 5,
11
- Saturday = 6,
12
- Sunday = 7,
13
- }
14
-
15
- export namespace Step {
16
- export function startOf(
17
- dateTime: DateTime,
18
- step: Step,
19
- firstDayOfWeek?: DayOfWeek,
20
- ): DateTime {
21
- if (step === "week") {
22
- const value = dateTime
23
- .startOf("day")
24
- .set({ weekday: firstDayOfWeek ?? DayOfWeek.Monday });
25
- return value > dateTime ? value.minus({ days: 7 }) : value;
26
- } else {
27
- return dateTime.startOf(step);
28
- }
29
- }
30
-
31
- export function asDuration(step: Step, amount = 1): Duration {
32
- switch (step) {
33
- case "hour":
34
- return Duration.fromObject({ hours: amount });
35
- case "day":
36
- return Duration.fromObject({ days: amount });
37
- case "week":
38
- return Duration.fromObject({ days: 7 * amount });
39
- case "month":
40
- return Duration.fromObject({ months: amount });
41
- case "year":
42
- return Duration.fromObject({ years: amount });
43
- }
44
- }
45
- }
1
+ import { DateTime, Duration } from "luxon";
2
+
3
+ export type Step = "hour" | "day" | "week" | "month" | "year";
4
+
5
+ export enum DayOfWeek {
6
+ Monday = 1,
7
+ Tuesday = 2,
8
+ Wednesday = 3,
9
+ Thursday = 4,
10
+ Friday = 5,
11
+ Saturday = 6,
12
+ Sunday = 7,
13
+ }
14
+
15
+ export namespace Step {
16
+ export function startOf(
17
+ dateTime: DateTime,
18
+ step: Step,
19
+ firstDayOfWeek?: DayOfWeek,
20
+ ): DateTime {
21
+ if (step === "week") {
22
+ const value = dateTime
23
+ .startOf("day")
24
+ .set({ weekday: firstDayOfWeek ?? DayOfWeek.Monday });
25
+ return value > dateTime ? value.minus({ days: 7 }) : value;
26
+ } else {
27
+ return dateTime.startOf(step);
28
+ }
29
+ }
30
+
31
+ export function asDuration(step: Step, amount = 1): Duration {
32
+ switch (step) {
33
+ case "hour":
34
+ return Duration.fromObject({ hours: amount });
35
+ case "day":
36
+ return Duration.fromObject({ days: amount });
37
+ case "week":
38
+ return Duration.fromObject({ days: 7 * amount });
39
+ case "month":
40
+ return Duration.fromObject({ months: amount });
41
+ case "year":
42
+ return Duration.fromObject({ years: amount });
43
+ }
44
+ }
45
+ }
@@ -1,42 +1,42 @@
1
- import { DateTime } from "luxon";
2
-
3
- export type TimeOrRule = Date | DateTime<true> | string;
4
-
5
- export function TimeOrRule(
6
- timeOrRule: Date | DateTime<true> | string,
7
- ): TimeOrRule {
8
- return timeOrRule;
9
- }
10
-
11
- export namespace TimeOrRule {
12
- export function parse(input: string): TimeOrRule {
13
- const time = DateTime.fromISO(input, { setZone: true });
14
- return time.isValid ? time : input;
15
- }
16
-
17
- export function isTime(input: TimeOrRule): input is Date | DateTime<true> {
18
- return typeof input !== "string";
19
- }
20
-
21
- export function isRule(input: TimeOrRule): input is string {
22
- return typeof input === "string";
23
- }
24
-
25
- export function asDateTime(input: TimeOrRule): DateTime<true> | undefined {
26
- if (isRule(input)) {
27
- return;
28
- } else if (DateTime.isDateTime(input)) {
29
- return input;
30
- } else {
31
- const dateTime = DateTime.fromJSDate(input);
32
- if (!dateTime.isValid) {
33
- throw new Error("Unable to convert from Date to DateTime");
34
- }
35
- return dateTime;
36
- }
37
- }
38
-
39
- export function toJSON(input: TimeOrRule) {
40
- return isRule(input) ? input : input.toJSON();
41
- }
42
- }
1
+ import { DateTime } from "luxon";
2
+
3
+ export type TimeOrRule = Date | DateTime<true> | string;
4
+
5
+ export function TimeOrRule(
6
+ timeOrRule: Date | DateTime<true> | string,
7
+ ): TimeOrRule {
8
+ return timeOrRule;
9
+ }
10
+
11
+ export namespace TimeOrRule {
12
+ export function parse(input: string): TimeOrRule {
13
+ const time = DateTime.fromISO(input, { setZone: true });
14
+ return time.isValid ? time : input;
15
+ }
16
+
17
+ export function isTime(input: TimeOrRule): input is Date | DateTime<true> {
18
+ return typeof input !== "string";
19
+ }
20
+
21
+ export function isRule(input: TimeOrRule): input is string {
22
+ return typeof input === "string";
23
+ }
24
+
25
+ export function asDateTime(input: TimeOrRule): DateTime<true> | undefined {
26
+ if (isRule(input)) {
27
+ return;
28
+ } else if (DateTime.isDateTime(input)) {
29
+ return input;
30
+ } else {
31
+ const dateTime = DateTime.fromJSDate(input);
32
+ if (!dateTime.isValid) {
33
+ throw new Error("Unable to convert from Date to DateTime");
34
+ }
35
+ return dateTime;
36
+ }
37
+ }
38
+
39
+ export function toJSON(input: TimeOrRule) {
40
+ return isRule(input) ? input : input.toJSON();
41
+ }
42
+ }