@utiliread/primitives 1.0.0-93 → 1.0.0-95

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 (60) hide show
  1. package/dist/cjs/breakdown-rule.js +58 -0
  2. package/dist/cjs/breakdown-rule.js.map +1 -0
  3. package/dist/cjs/breakdown-rule.spec.js +41 -0
  4. package/dist/cjs/breakdown-rule.spec.js.map +1 -0
  5. package/dist/cjs/index.js +1 -1
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/measures/pressure.js +2 -2
  8. package/dist/cjs/measures/pressure.js.map +1 -1
  9. package/dist/cjs/number-formatter.spec.js +1 -1
  10. package/dist/cjs/number-formatter.spec.js.map +1 -1
  11. package/dist/cjs/precision-number.spec.js +1 -1
  12. package/dist/cjs/precision-number.spec.js.map +1 -1
  13. package/dist/cjs/register-convention.spec.js +1 -1
  14. package/dist/cjs/register-convention.spec.js.map +1 -1
  15. package/dist/cjs/register-library.spec.js +1 -1
  16. package/dist/cjs/register-library.spec.js.map +1 -1
  17. package/dist/cjs/repository.spec.js +1 -1
  18. package/dist/cjs/repository.spec.js.map +1 -1
  19. package/dist/cjs/step.spec.js +1 -1
  20. package/dist/cjs/step.spec.js.map +1 -1
  21. package/dist/esm/breakdown-rule.d.ts +20 -0
  22. package/dist/esm/breakdown-rule.js +54 -0
  23. package/dist/esm/breakdown-rule.js.map +1 -0
  24. package/dist/esm/breakdown-rule.spec.d.ts +1 -0
  25. package/dist/esm/breakdown-rule.spec.js +39 -0
  26. package/dist/esm/breakdown-rule.spec.js.map +1 -0
  27. package/dist/esm/index.d.ts +2 -1
  28. package/dist/esm/index.js +1 -1
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/measures/pressure.js +2 -2
  31. package/dist/esm/measures/pressure.js.map +1 -1
  32. package/dist/esm/number-formatter.spec.js +1 -1
  33. package/dist/esm/number-formatter.spec.js.map +1 -1
  34. package/dist/esm/precision-number.spec.js +1 -1
  35. package/dist/esm/precision-number.spec.js.map +1 -1
  36. package/dist/esm/register-convention.spec.js +1 -1
  37. package/dist/esm/register-convention.spec.js.map +1 -1
  38. package/dist/esm/register-library.spec.js +1 -1
  39. package/dist/esm/register-library.spec.js.map +1 -1
  40. package/dist/esm/repository.spec.js +1 -1
  41. package/dist/esm/repository.spec.js.map +1 -1
  42. package/dist/esm/step.spec.js +1 -1
  43. package/dist/esm/step.spec.js.map +1 -1
  44. package/locales/da/aggregates.json +13 -3
  45. package/locales/da/units.json +18 -0
  46. package/locales/en/aggregates.json +13 -3
  47. package/locales/en/units.json +18 -0
  48. package/package.json +3 -2
  49. package/src/breakdown-rule.spec.ts +44 -0
  50. package/src/breakdown-rule.ts +75 -0
  51. package/src/index.ts +9 -6
  52. package/src/measures/pressure.ts +2 -2
  53. package/src/number-formatter.spec.ts +549 -549
  54. package/src/precision-number.spec.ts +28 -28
  55. package/src/register-convention.spec.ts +52 -52
  56. package/src/register-library.spec.ts +41 -41
  57. package/src/repository.spec.ts +20 -20
  58. package/src/step.spec.ts +37 -37
  59. package/tsconfig.cjs.json +1 -0
  60. package/tsconfig.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { Repository } from "./repository";
2
- import { expect } from "@esm-bundle/chai";
2
+ import { expect } from "chai";
3
3
  describe("ctor", () => {
4
4
  it("creates", () => {
5
5
  expect(Repository("gpkv", "gjoel")).to.equal("gpkv/gjoel");
@@ -1 +1 @@
1
- {"version":3,"file":"repository.spec.js","sourceRoot":"","sources":["../../src/repository.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAClB,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACf,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK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AAC,CAAC;IACH,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAC9B,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACnB,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACjC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { DayOfWeek, Step } from "./step";
2
2
  import { DateTime } from "luxon";
3
- import { expect } from "@esm-bundle/chai";
3
+ import { expect } from "chai";
4
4
  describe("startOf", () => {
5
5
  it("returns start of day", () => {
6
6
  const dt = DateTime.fromISO("2020-01-11T05:00:00+01:00");
@@ -1 +1 @@
1
- {"version":3,"file":"step.spec.js","sourceRoot":"","sources":["../../src/step.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC5B,MAAM,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;QACzD,M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QAC1D,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CACpB,CAAC,QAAQ,CAAC,OAAO,CAAC,2BAA2B,CAAC,CACjD,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -2,7 +2,7 @@
2
2
  "instant": {
3
3
  "name": "Aktuel",
4
4
  "brief": "Aktuel",
5
- "symbol": "Aktuel"
5
+ "symbol": "\u2217"
6
6
  },
7
7
  "diff": {
8
8
  "name": "Forøgelse",
@@ -17,16 +17,26 @@
17
17
  "max": {
18
18
  "name": "Maksimum",
19
19
  "brief": "Maks",
20
- "symbol": "\u3208\u3209"
20
+ "symbol": "\u2308\u2309"
21
21
  },
22
22
  "avg": {
23
23
  "name": "Gennemsnit",
24
24
  "brief": "Gns",
25
- "symbol": "~"
25
+ "symbol": "\u223C"
26
26
  },
27
27
  "sum": {
28
28
  "name": "Total",
29
29
  "brief": "Sum",
30
30
  "symbol": "\u2211"
31
+ },
32
+ "cnt": {
33
+ "name": "Antal",
34
+ "brief": "Antal",
35
+ "symbol": "#"
36
+ },
37
+ "ssq": {
38
+ "name": "Kvadratsum",
39
+ "brief": "Kv.sum",
40
+ "symbol": "\u2211\u00B2"
31
41
  }
32
42
  }
@@ -255,21 +255,39 @@
255
255
  "celcius": {
256
256
  "symbol": "\u00B0C"
257
257
  },
258
+ "celcius2": {
259
+ "symbol": "\u00B0C\u00B2"
260
+ },
258
261
  "kelvin": {
259
262
  "symbol": "K"
260
263
  },
264
+ "kelvin2": {
265
+ "symbol": "K\u00B2"
266
+ },
261
267
  "fahrenheit": {
262
268
  "symbol": "F"
263
269
  },
270
+ "fahrenheit2": {
271
+ "symbol": "F\u00B2"
272
+ },
264
273
  "bar": {
265
274
  "symbol": "bar"
266
275
  },
276
+ "bar2": {
277
+ "symbol": "bar\u00B2"
278
+ },
267
279
  "pascal": {
268
280
  "symbol": "Pa"
269
281
  },
282
+ "pascal2": {
283
+ "symbol": "Pa\u00B2"
284
+ },
270
285
  "kiloPascal": {
271
286
  "symbol": "kPa"
272
287
  },
288
+ "kiloPascal2": {
289
+ "symbol": "kPa\u00B2"
290
+ },
273
291
  "decibel": {
274
292
  "symbol": "dB"
275
293
  },
@@ -2,7 +2,7 @@
2
2
  "instant": {
3
3
  "name": "Present",
4
4
  "brief": "Present",
5
- "symbol": "\u22C5"
5
+ "symbol": "\u2217"
6
6
  },
7
7
  "diff": {
8
8
  "name": "Increase",
@@ -17,16 +17,26 @@
17
17
  "max": {
18
18
  "name": "Maximum",
19
19
  "brief": "Max",
20
- "symbol": "\u3208\u3209"
20
+ "symbol": "\u2308\u2309"
21
21
  },
22
22
  "avg": {
23
23
  "name": "Average",
24
24
  "brief": "Avg",
25
- "symbol": "~"
25
+ "symbol": "\u223C"
26
26
  },
27
27
  "sum": {
28
28
  "name": "Sum",
29
29
  "brief": "Sum",
30
30
  "symbol": "\u2211"
31
+ },
32
+ "cnt": {
33
+ "name": "Count",
34
+ "brief": "Cnt",
35
+ "symbol": "#"
36
+ },
37
+ "ssq": {
38
+ "name": "Sum of squares",
39
+ "brief": "SumSq",
40
+ "symbol": "\u2211\u00B2"
31
41
  }
32
42
  }
@@ -255,21 +255,39 @@
255
255
  "celcius": {
256
256
  "symbol": "\u00B0C"
257
257
  },
258
+ "celcius2": {
259
+ "symbol": "\u00B0C\u00B2"
260
+ },
258
261
  "kelvin": {
259
262
  "symbol": "K"
260
263
  },
264
+ "kelvin2": {
265
+ "symbol": "K\u00B2"
266
+ },
261
267
  "fahrenheit": {
262
268
  "symbol": "F"
263
269
  },
270
+ "fahrenheit2": {
271
+ "symbol": "F\u00B2"
272
+ },
264
273
  "bar": {
265
274
  "symbol": "bar"
266
275
  },
276
+ "bar2": {
277
+ "symbol": "bar\u00B2"
278
+ },
267
279
  "pascal": {
268
280
  "symbol": "Pa"
269
281
  },
282
+ "pascal2": {
283
+ "symbol": "Pa\u00B2"
284
+ },
270
285
  "kiloPascal": {
271
286
  "symbol": "kPa"
272
287
  },
288
+ "kiloPascal2": {
289
+ "symbol": "kPa\u00B2"
290
+ },
273
291
  "decibel": {
274
292
  "symbol": "dB"
275
293
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utiliread/primitives",
3
- "version": "1.0.0-93",
3
+ "version": "1.0.0-95",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -27,11 +27,12 @@
27
27
  "./*.d.ts": "./dist/esm/*.d.ts"
28
28
  },
29
29
  "devDependencies": {
30
- "@esm-bundle/chai": "^4.3.4-fix.0",
30
+ "@types/chai": "^4.3.11",
31
31
  "@types/luxon": "^3.0.1",
32
32
  "@types/mocha": "^10.0.0",
33
33
  "@web/dev-server-esbuild": "^1.0.1",
34
34
  "@web/test-runner": "^0.18.0",
35
+ "chai": "^5.0.0",
35
36
  "luxon": "^3.0.4",
36
37
  "mocha": "^10.0.0",
37
38
  "prettier": "^3.1.0",
@@ -0,0 +1,44 @@
1
+ import { BreakdownRule } from "./breakdown-rule";
2
+ import { expect } from "chai";
3
+
4
+ describe("ctor", () => {
5
+ it("creates", () => {
6
+ expect(BreakdownRule({ count: 1, period: "hour"})).to.equal("1hour");
7
+ expect(BreakdownRule({ count: 2, period: "hour"})).to.equal("2hours");
8
+ expect(BreakdownRule({ origin: "", count: 1, period: "hour"})).to.equal("1hour");
9
+ expect(BreakdownRule({ origin: "", count: 2, period: "hour"})).to.equal("2hours");
10
+ expect(BreakdownRule({ origin: "day", count: 1, period: "hour"})).to.equal("day/1hour");
11
+ expect(BreakdownRule({ origin: "day", count: 2, period: "hour"})).to.equal("day/2hours");
12
+
13
+ expect(BreakdownRule(1, "hour")).to.equal("1hour");
14
+ expect(BreakdownRule(2, "hour")).to.equal("2hours");
15
+
16
+ expect(BreakdownRule("", 1, "hour")).to.equal("1hour");
17
+ expect(BreakdownRule("", 2, "hour")).to.equal("2hours");
18
+ expect(BreakdownRule("day", 1, "hour")).to.equal("day/1hour");
19
+ expect(BreakdownRule("day", 2, "hour")).to.equal("day/2hours");
20
+ });
21
+ });
22
+
23
+ describe("split", () => {
24
+ it("splits without origin", () => {
25
+ const { origin, count, period } = BreakdownRule.split("1hour");
26
+ expect(origin).to.equal("");
27
+ expect(count).to.equal(1);
28
+ expect(period).to.equal("hour");
29
+ });
30
+
31
+ it("splits with simple origin", () => {
32
+ const { origin, count, period } = BreakdownRule.split("day/1hour");
33
+ expect(origin).to.equal("day");
34
+ expect(count).to.equal(1);
35
+ expect(period).to.equal("hour");
36
+ });
37
+
38
+ it("splits with complex origin and plural count", () => {
39
+ const { origin, count, period } = BreakdownRule.split("day+PT1H_year^month/10hours");
40
+ expect(origin).to.equal("day+PT1H_year^month");
41
+ expect(count).to.equal(10);
42
+ expect(period).to.equal("hour");
43
+ });
44
+ });
@@ -0,0 +1,75 @@
1
+ import { Step } from "./step";
2
+ import { TimeOrRule } from "./time-or-rule";
3
+
4
+ export type BreakdownRule = string;
5
+ export type BreakdownPeriod = Step;
6
+
7
+ interface BreakdownRuleInit {
8
+ origin?: TimeOrRule;
9
+ count: number;
10
+ period: BreakdownPeriod;
11
+ }
12
+
13
+ export function BreakdownRule(init: BreakdownRuleInit): BreakdownRule;
14
+ export function BreakdownRule(
15
+ count: number,
16
+ period: BreakdownPeriod,
17
+ ): BreakdownRule;
18
+ export function BreakdownRule(
19
+ origin: TimeOrRule,
20
+ count: number,
21
+ period: BreakdownPeriod,
22
+ ): BreakdownRule;
23
+ export function BreakdownRule(...params: any[]): BreakdownRule {
24
+ let init: BreakdownRuleInit;
25
+ switch (params.length) {
26
+ case 1:
27
+ init = params[0];
28
+ break;
29
+ case 2:
30
+ init = {
31
+ origin: "",
32
+ count: params[0],
33
+ period: params[1],
34
+ };
35
+ break;
36
+ case 3:
37
+ init = {
38
+ origin: params[0],
39
+ count: params[1],
40
+ period: params[2],
41
+ };
42
+ break;
43
+ default:
44
+ throw new TypeError("Invalid breakdown rule format");
45
+ }
46
+ const origin = init.origin ?? "";
47
+ const periodName =
48
+ Math.abs(init.count) == 1 ? init.period : (init.period + "s");
49
+ return TimeOrRule.isRule(origin) && origin === ""
50
+ ? `${init.count}${periodName}`
51
+ : `${origin}/${init.count}${periodName}`;
52
+ }
53
+
54
+ export namespace BreakdownRule {
55
+ const regex = new RegExp(
56
+ "((.*)/)?([-+]?[0-9]+)(hour|day|week|month|year)s?",
57
+ );
58
+ export function split(rule: BreakdownRule) {
59
+ const match = regex.exec(rule);
60
+ if (!match) {
61
+ throw new Error("Invalid breakdown rule format");
62
+ }
63
+ const origin = match[2] ?? "";
64
+ const count = parseInt(match[3]);
65
+ let period = match[4];
66
+ if (period.endsWith("s")) {
67
+ period = period.substring(0, period.length - 1);
68
+ }
69
+ return {
70
+ origin: origin as TimeOrRule,
71
+ count,
72
+ period: period as BreakdownPeriod,
73
+ };
74
+ }
75
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import "./repository"; // We need this to get the Repository namespace exported
2
2
 
3
- import * as registers from "./registers"
3
+ import * as registers from "./registers";
4
4
 
5
+ import type { BreakdownPeriod, BreakdownRule } from "./breakdown-rule";
5
6
  import { DayOfWeek, Step } from "./step";
6
7
  import {
7
8
  NumberFormatter,
@@ -24,21 +25,23 @@ import type { UnitId } from "./unit-id";
24
25
 
25
26
  export {
26
27
  AggregateId,
27
- Medium,
28
+ BreakdownPeriod,
29
+ BreakdownRule,
28
30
  DayOfWeek,
31
+ invariantDecimalSeparator,
32
+ localeDecimalSeparator,
29
33
  MeasureId,
34
+ Medium,
30
35
  NumberFormatter,
36
+ Optional,
31
37
  PrecisionNumber,
32
38
  RegisterConvention,
33
39
  RegisterDefinition,
34
40
  RegisterId,
35
41
  RegisterLibrary,
42
+ registers,
36
43
  Repository,
37
44
  Step,
38
45
  TimeOrRule,
39
46
  UnitId,
40
- invariantDecimalSeparator,
41
- localeDecimalSeparator,
42
- Optional,
43
- registers,
44
47
  };
@@ -1,5 +1,5 @@
1
1
  import { UnitId } from "../unit-id";
2
2
 
3
- export const units: ReadonlyArray<UnitId> = ["bar", "pascal"];
3
+ export const units: ReadonlyArray<UnitId> = ["bar", "pascal", "kiloPascal"];
4
4
 
5
- export const sqUnits: ReadonlyArray<UnitId> = ["bar2", "pascal2"];
5
+ export const sqUnits: ReadonlyArray<UnitId> = ["bar2", "pascal2", "kiloPascal2"];