@utiliread/primitives 1.0.0-103 → 1.0.0-105

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 (67) hide show
  1. package/dist/cjs/breakdown-rule.js +2 -3
  2. package/dist/cjs/breakdown-rule.js.map +1 -1
  3. package/dist/cjs/breakdown-rule.spec.js.map +1 -1
  4. package/dist/cjs/measures/energy.js +1 -0
  5. package/dist/cjs/measures/energy.js.map +1 -1
  6. package/dist/cjs/measures/pressure.js +5 -1
  7. package/dist/cjs/measures/pressure.js.map +1 -1
  8. package/dist/cjs/register-convention.js +2 -2
  9. package/dist/cjs/register-convention.js.map +1 -1
  10. package/dist/cjs/register-utils.js +1 -2
  11. package/dist/cjs/register-utils.js.map +1 -1
  12. package/dist/cjs/registers/index.js +4 -2
  13. package/dist/cjs/registers/index.js.map +1 -1
  14. package/dist/cjs/registers/nominalDiameter.js +11 -0
  15. package/dist/cjs/registers/nominalDiameter.js.map +1 -0
  16. package/dist/cjs/registers/permanentVolumeFlow.js +11 -0
  17. package/dist/cjs/registers/permanentVolumeFlow.js.map +1 -0
  18. package/dist/cjs/repository.js +1 -2
  19. package/dist/cjs/repository.js.map +1 -1
  20. package/dist/cjs/time-or-rule.js +1 -2
  21. package/dist/cjs/time-or-rule.js.map +1 -1
  22. package/dist/esm/breakdown-rule.js +1 -1
  23. package/dist/esm/breakdown-rule.js.map +1 -1
  24. package/dist/esm/breakdown-rule.spec.js.map +1 -1
  25. package/dist/esm/measures/energy.js +1 -0
  26. package/dist/esm/measures/energy.js.map +1 -1
  27. package/dist/esm/measures/pressure.js +5 -1
  28. package/dist/esm/measures/pressure.js.map +1 -1
  29. package/dist/esm/register-id.d.ts +1 -1
  30. package/dist/esm/registers/index.d.ts +4 -2
  31. package/dist/esm/registers/index.js +4 -2
  32. package/dist/esm/registers/index.js.map +1 -1
  33. package/dist/esm/registers/nominalDiameter.d.ts +2 -0
  34. package/dist/esm/registers/nominalDiameter.js +8 -0
  35. package/dist/esm/registers/nominalDiameter.js.map +1 -0
  36. package/dist/esm/registers/permanentVolumeFlow.d.ts +2 -0
  37. package/dist/esm/registers/permanentVolumeFlow.js +8 -0
  38. package/dist/esm/registers/permanentVolumeFlow.js.map +1 -0
  39. package/dist/esm/time-or-rule.js.map +1 -1
  40. package/dist/esm/unit-id.d.ts +1 -1
  41. package/locales/da/aggregates.json +1 -1
  42. package/locales/da/measures.json +1 -1
  43. package/locales/da/mediums.json +1 -1
  44. package/locales/da/registers.json +9 -1
  45. package/locales/da/units.json +4 -1
  46. package/locales/en/aggregates.json +1 -1
  47. package/locales/en/measures.json +1 -1
  48. package/locales/en/mediums.json +1 -1
  49. package/locales/en/registers.json +9 -1
  50. package/locales/en/units.json +4 -1
  51. package/package.json +2 -2
  52. package/src/breakdown-rule.spec.ts +61 -63
  53. package/src/breakdown-rule.ts +58 -60
  54. package/src/measures/energy.ts +1 -0
  55. package/src/measures/pressure.ts +5 -1
  56. package/src/number-formatter.spec.ts +549 -549
  57. package/src/precision-number.spec.ts +28 -28
  58. package/src/register-convention.spec.ts +52 -52
  59. package/src/register-id.ts +2 -0
  60. package/src/register-library.spec.ts +41 -41
  61. package/src/registers/index.ts +4 -2
  62. package/src/registers/nominalDiameter.ts +9 -0
  63. package/src/registers/permanentVolumeFlow.ts +9 -0
  64. package/src/repository.spec.ts +20 -20
  65. package/src/step.spec.ts +37 -37
  66. package/src/time-or-rule.ts +42 -44
  67. package/src/unit-id.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utiliread/primitives",
3
- "version": "1.0.0-103",
3
+ "version": "1.0.0-105",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  "luxon": "^3.0.4",
37
37
  "mocha": "^10.0.0",
38
38
  "prettier": "^3.1.0",
39
- "rimraf": "^5.0.1",
39
+ "rimraf": "^6.0.1",
40
40
  "typescript": "^5.1.6"
41
41
  },
42
42
  "peerDependencies": {
@@ -1,63 +1,61 @@
1
- import { BreakdownRule } from "./breakdown-rule";
2
- import { DateTime } from "luxon";
3
- import { TimeOrRule } from ".";
4
- import { expect } from "chai";
5
-
6
- describe("ctor", () => {
7
- it("creates", () => {
8
- expect(
9
- BreakdownRule({ origin: "", count: 1, period: "hour" }),
10
- ).to.equal("/1hour");
11
- expect(
12
- BreakdownRule({ origin: "", count: 2, period: "hour" }),
13
- ).to.equal("/2hours");
14
- expect(
15
- BreakdownRule({ origin: "day", count: 1, period: "hour" }),
16
- ).to.equal("day/1hour");
17
- expect(
18
- BreakdownRule({ origin: "day", count: 2, period: "hour" }),
19
- ).to.equal("day/2hours");
20
-
21
- expect(BreakdownRule("", 1, "hour")).to.equal("/1hour");
22
- expect(BreakdownRule("", 2, "hour")).to.equal("/2hours");
23
- expect(BreakdownRule("day", 1, "hour")).to.equal("day/1hour");
24
- expect(BreakdownRule("day", 2, "hour")).to.equal("day/2hours");
25
- });
26
- });
27
-
28
- describe("split", () => {
29
- it("splits without origin", () => {
30
- const { origin, count, period } = BreakdownRule.split("/1hour");
31
- expect(origin).to.equal("");
32
- expect(count).to.equal(1);
33
- expect(period).to.equal("hour");
34
- });
35
-
36
- it("splits with simple origin", () => {
37
- const { origin, count, period } = BreakdownRule.split("day/1hour");
38
- expect(origin).to.equal("day");
39
- expect(count).to.equal(1);
40
- expect(period).to.equal("hour");
41
- });
42
-
43
- it("splits with complex origin and plural count", () => {
44
- const { origin, count, period } = BreakdownRule.split(
45
- "day+PT1H_year^month/10hours",
46
- );
47
- expect(origin).to.equal("day+PT1H_year^month");
48
- expect(count).to.equal(10);
49
- expect(period).to.equal("hour");
50
- });
51
-
52
- it("splits with time origin", () => {
53
- const { origin, count, period } = BreakdownRule.split(
54
- "2024-01-25T00:00:00.000+01:00/1hour",
55
- );
56
- expect(TimeOrRule.isTime(origin)).to.equal(true);
57
- expect(+origin).to.equal(
58
- +DateTime.local(2024, 1, 25),
59
- );
60
- expect(count).to.equal(1);
61
- expect(period).to.equal("hour");
62
- });
63
- });
1
+ import { BreakdownRule } from "./breakdown-rule";
2
+ import { DateTime } from "luxon";
3
+ import { TimeOrRule } from ".";
4
+ import { expect } from "chai";
5
+
6
+ describe("ctor", () => {
7
+ it("creates", () => {
8
+ expect(
9
+ BreakdownRule({ origin: "", count: 1, period: "hour" }),
10
+ ).to.equal("/1hour");
11
+ expect(
12
+ BreakdownRule({ origin: "", count: 2, period: "hour" }),
13
+ ).to.equal("/2hours");
14
+ expect(
15
+ BreakdownRule({ origin: "day", count: 1, period: "hour" }),
16
+ ).to.equal("day/1hour");
17
+ expect(
18
+ BreakdownRule({ origin: "day", count: 2, period: "hour" }),
19
+ ).to.equal("day/2hours");
20
+
21
+ expect(BreakdownRule("", 1, "hour")).to.equal("/1hour");
22
+ expect(BreakdownRule("", 2, "hour")).to.equal("/2hours");
23
+ expect(BreakdownRule("day", 1, "hour")).to.equal("day/1hour");
24
+ expect(BreakdownRule("day", 2, "hour")).to.equal("day/2hours");
25
+ });
26
+ });
27
+
28
+ describe("split", () => {
29
+ it("splits without origin", () => {
30
+ const { origin, count, period } = BreakdownRule.split("/1hour");
31
+ expect(origin).to.equal("");
32
+ expect(count).to.equal(1);
33
+ expect(period).to.equal("hour");
34
+ });
35
+
36
+ it("splits with simple origin", () => {
37
+ const { origin, count, period } = BreakdownRule.split("day/1hour");
38
+ expect(origin).to.equal("day");
39
+ expect(count).to.equal(1);
40
+ expect(period).to.equal("hour");
41
+ });
42
+
43
+ it("splits with complex origin and plural count", () => {
44
+ const { origin, count, period } = BreakdownRule.split(
45
+ "day+PT1H_year^month/10hours",
46
+ );
47
+ expect(origin).to.equal("day+PT1H_year^month");
48
+ expect(count).to.equal(10);
49
+ expect(period).to.equal("hour");
50
+ });
51
+
52
+ it("splits with time origin", () => {
53
+ const { origin, count, period } = BreakdownRule.split(
54
+ "2024-01-25T00:00:00.000+01:00/1hour",
55
+ );
56
+ expect(TimeOrRule.isTime(origin)).to.equal(true);
57
+ expect(+origin).to.equal(+DateTime.local(2024, 1, 25));
58
+ expect(count).to.equal(1);
59
+ expect(period).to.equal("hour");
60
+ });
61
+ });
@@ -1,60 +1,58 @@
1
- import { TimeOrRule } from "./time-or-rule";
2
-
3
- export type BreakdownRule = string;
4
- export type BreakdownPeriod = "hour" | "day" | "week" | "month" | "year";
5
-
6
- interface BreakdownRuleInit {
7
- origin: TimeOrRule;
8
- count: number;
9
- period: BreakdownPeriod;
10
- }
11
-
12
- export function BreakdownRule(init: BreakdownRuleInit): BreakdownRule;
13
- export function BreakdownRule(
14
- origin: TimeOrRule,
15
- count: number,
16
- period: BreakdownPeriod,
17
- ): BreakdownRule;
18
- export function BreakdownRule(...params: any[]): BreakdownRule {
19
- let init: BreakdownRuleInit;
20
- switch (params.length) {
21
- case 1:
22
- init = params[0];
23
- break;
24
- case 3:
25
- init = {
26
- origin: params[0],
27
- count: params[1],
28
- period: params[2],
29
- };
30
- break;
31
- default:
32
- throw new TypeError("Invalid breakdown rule format");
33
- }
34
- const periodName =
35
- Math.abs(init.count) == 1 ? init.period : (init.period + "s");
36
- return `${init.origin}/${init.count}${periodName}`;
37
- }
38
-
39
- export namespace BreakdownRule {
40
- const regex = new RegExp(
41
- "(.*)/([-+]?[0-9]+)(hour|day|week|month|year)s?",
42
- );
43
- export function split(rule: BreakdownRule) {
44
- const match = regex.exec(rule);
45
- if (!match) {
46
- throw new Error("Invalid breakdown rule format");
47
- }
48
- const origin = match[1];
49
- const count = parseInt(match[2]);
50
- let period = match[3];
51
- if (period.endsWith("s")) {
52
- period = period.substring(0, period.length - 1);
53
- }
54
- return {
55
- origin: TimeOrRule.parse(origin),
56
- count,
57
- period: period as BreakdownPeriod,
58
- };
59
- }
60
- }
1
+ import { TimeOrRule } from "./time-or-rule";
2
+
3
+ export type BreakdownRule = string;
4
+ export type BreakdownPeriod = "hour" | "day" | "week" | "month" | "year";
5
+
6
+ interface BreakdownRuleInit {
7
+ origin: TimeOrRule;
8
+ count: number;
9
+ period: BreakdownPeriod;
10
+ }
11
+
12
+ export function BreakdownRule(init: BreakdownRuleInit): BreakdownRule;
13
+ export function BreakdownRule(
14
+ origin: TimeOrRule,
15
+ count: number,
16
+ period: BreakdownPeriod,
17
+ ): BreakdownRule;
18
+ export function BreakdownRule(...params: any[]): BreakdownRule {
19
+ let init: BreakdownRuleInit;
20
+ switch (params.length) {
21
+ case 1:
22
+ init = params[0];
23
+ break;
24
+ case 3:
25
+ init = {
26
+ origin: params[0],
27
+ count: params[1],
28
+ period: params[2],
29
+ };
30
+ break;
31
+ default:
32
+ throw new TypeError("Invalid breakdown rule format");
33
+ }
34
+ const periodName =
35
+ Math.abs(init.count) == 1 ? init.period : init.period + "s";
36
+ return `${init.origin}/${init.count}${periodName}`;
37
+ }
38
+
39
+ export namespace BreakdownRule {
40
+ const regex = new RegExp("(.*)/([-+]?[0-9]+)(hour|day|week|month|year)s?");
41
+ export function split(rule: BreakdownRule) {
42
+ const match = regex.exec(rule);
43
+ if (!match) {
44
+ throw new Error("Invalid breakdown rule format");
45
+ }
46
+ const origin = match[1];
47
+ const count = parseInt(match[2]);
48
+ let period = match[3];
49
+ if (period.endsWith("s")) {
50
+ period = period.substring(0, period.length - 1);
51
+ }
52
+ return {
53
+ origin: TimeOrRule.parse(origin),
54
+ count,
55
+ period: period as BreakdownPeriod,
56
+ };
57
+ }
58
+ }
@@ -9,4 +9,5 @@ export const units: ReadonlyArray<UnitId> = [
9
9
  "calorie",
10
10
  "kiloCalorie",
11
11
  "megaCalorie",
12
+ "gigaCalorie",
12
13
  ];
@@ -2,4 +2,8 @@ import { UnitId } from "../unit-id";
2
2
 
3
3
  export const units: ReadonlyArray<UnitId> = ["bar", "pascal", "kiloPascal"];
4
4
 
5
- export const sqUnits: ReadonlyArray<UnitId> = ["bar2", "pascal2", "kiloPascal2"];
5
+ export const sqUnits: ReadonlyArray<UnitId> = [
6
+ "bar2",
7
+ "pascal2",
8
+ "kiloPascal2",
9
+ ];