@utiliread/primitives 1.0.0-124 → 1.0.0-126

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.
@@ -1,3 +1,4 @@
1
+ import "./medium";
1
2
  import "./repository";
2
3
  import type { Consumer, Device, DeviceSample, KamdraftDeviceAddress, MsisdnDeviceAddress, Place, TchlrDeviceAddress, WMBusDeviceAddress } from "./registers";
3
4
  import { Duration } from "./luxon-local";
@@ -1 +1,7 @@
1
1
  export type Medium = "none" | "heat" | "water" | "cooling" | "electricity" | "infrastructure" | "all";
2
+ export declare namespace Medium {
3
+ function isMedium(input: string): input is Medium;
4
+ function isMedium(input: string[]): input is Medium[];
5
+ function isMeter(medium: Medium | Medium[]): boolean;
6
+ function isFlowMeter(medium: Medium | Medium[]): boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ export type Repository = "some/repo";
2
2
  export declare function Repository(repo: string): Repository;
3
3
  export declare function Repository(team: string, name: string): Repository;
4
4
  export declare namespace Repository {
5
+ function isRepository(input: string): input is Repository;
5
6
  function split(repo: Repository): {
6
7
  team: string;
7
8
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utiliread/primitives",
3
- "version": "1.0.0-124",
3
+ "version": "1.0.0-126",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- import "./repository"; // We need this to get the Repository namespace exported
1
+ // We need these to get their namespaces exported
2
+ import "./medium";
3
+ import "./repository";
2
4
 
3
5
  import * as registers2 from "./registers";
4
6
 
@@ -0,0 +1,12 @@
1
+ import { Medium } from "./medium";
2
+ import { expect } from "chai";
3
+
4
+ describe("isMedium", () => {
5
+ it("should correctly determine if input is a medium", () => {
6
+ expect(Medium.isMedium("heat")).to.equal(true);
7
+ expect(Medium.isMedium("water")).to.equal(true);
8
+ expect(Medium.isMedium(["heat","water"])).to.equal(true);
9
+ expect(Medium.isMedium("heat,water")).to.equal(false);
10
+ expect(Medium.isMedium("notamedium")).to.equal(false);
11
+ });
12
+ });
package/src/medium.ts CHANGED
@@ -6,3 +6,42 @@ export type Medium =
6
6
  | "electricity"
7
7
  | "infrastructure"
8
8
  | "all";
9
+
10
+ export namespace Medium {
11
+ export function isMedium(input: string): input is Medium;
12
+ export function isMedium(input: string[]): input is Medium[];
13
+ export function isMedium(
14
+ input: string | string[],
15
+ ): input is Medium | Medium[] {
16
+ if (input === "none" || input === "all") {
17
+ return true;
18
+ }
19
+ const ALL_MEDIUMS: Medium[] = [
20
+ "heat",
21
+ "water",
22
+ "cooling",
23
+ "electricity",
24
+ "infrastructure",
25
+ ];
26
+ return Array.isArray(input)
27
+ ? !input.some((x) => !ALL_MEDIUMS.includes(<Medium>x))
28
+ : ALL_MEDIUMS.includes(<Medium>input);
29
+ }
30
+
31
+ export function isMeter(medium: Medium | Medium[]) {
32
+ return (
33
+ medium.includes("heat") ||
34
+ medium.includes("water") ||
35
+ medium.includes("cooling") ||
36
+ medium.includes("electricity")
37
+ );
38
+ }
39
+
40
+ export function isFlowMeter(medium: Medium | Medium[]) {
41
+ return (
42
+ medium.includes("heat") ||
43
+ medium.includes("water") ||
44
+ medium.includes("cooling")
45
+ );
46
+ }
47
+ }
@@ -11,6 +11,15 @@ describe("ctor", () => {
11
11
  });
12
12
  });
13
13
 
14
+ describe("isRepository", () => {
15
+ it("should correctly determine if input is a Repository", () => {
16
+ expect(Repository.isRepository("some/test")).to.equal(true);
17
+ expect(Repository.isRepository("so-me/te-st")).to.equal(true);
18
+ expect(Repository.isRepository("NOT/REPO")).to.equal(false);
19
+ expect(Repository.isRepository("notarepo")).to.equal(false);
20
+ });
21
+ });
22
+
14
23
  describe("split", () => {
15
24
  it("splits into correct parts", () => {
16
25
  const { team, name } = Repository.split(Repository("gpkv", "gjoel"));
package/src/repository.ts CHANGED
@@ -4,16 +4,21 @@ export type Repository = "some/repo";
4
4
  export function Repository(repo: string): Repository;
5
5
  export function Repository(team: string, name: string): Repository;
6
6
  export function Repository(repoOrTeam: string, name?: string): Repository {
7
- if (name) {
8
- return <Repository>`${repoOrTeam}/${name}`;
9
- } else if (repoOrTeam.indexOf("/") > 0) {
10
- return <Repository>repoOrTeam;
11
- } else {
7
+ const repo = name ? `${repoOrTeam}/${name}` : repoOrTeam;
8
+ if (!Repository.isRepository(repo)) {
12
9
  throw new TypeError("Invalid repository format");
13
10
  }
11
+ return repo;
14
12
  }
15
13
 
14
+ const PART_REGEX = new RegExp(/[a-z][a-z0-9-]*/);
15
+
16
16
  export namespace Repository {
17
+ export function isRepository(input: string): input is Repository {
18
+ const parts = input.split("/");
19
+ return parts.length === 2 && !parts.some((x) => !PART_REGEX.test(x));
20
+ }
21
+
17
22
  export function split(repo: Repository) {
18
23
  const parts = repo.split("/");
19
24
  return {
package/asdasd/index.js DELETED
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"mappings":"","sources":["src/registers/index.ts"],"sourcesContent":["export * from \"./acoustic-noise\";\nexport * from \"./ambient-temperature\";\nexport * from \"./consumer\";\nexport * from \"./cooling-energy-inlet\";\nexport * from \"./cooling-energy-outlet\";\nexport * from \"./cooling-energy\";\nexport * from \"./cooling\";\nexport * from \"./device-addresses-kamdraft\";\nexport * from \"./device-addresses-msisdn\";\nexport * from \"./device-addresses-tchlr\";\nexport * from \"./device-addresses-wmbus\";\nexport * from \"./device-date-time\";\nexport * from \"./device-date\";\nexport * from \"./device-nominal-diameter\";\nexport * from \"./device-permanent-volume-flow\";\nexport * from \"./device-registers\";\nexport * from \"./device-software-version\";\nexport * from \"./device-time\";\nexport * from \"./device\";\nexport * from \"./diehl-infocode\";\nexport * from \"./electrical-energy\";\nexport * from \"./energy-inlet\";\nexport * from \"./energy-outlet\";\nexport * from \"./error-operating-time\";\nexport * from \"./flow-temperature-aux\";\nexport * from \"./flow-temperature-inlet\";\nexport * from \"./flow-temperature-outlet\";\nexport * from \"./flow-temperature\";\nexport * from \"./heat-energy-inlet\";\nexport * from \"./heat-energy-outlet\";\nexport * from \"./heat-energy\";\nexport * from \"./infocode\";\nexport * from \"./kamstrup-module-type\";\nexport * from \"./kamstrup-multical-infocode\";\nexport * from \"./landis-gyr-infocode\";\nexport * from \"./landis-gyr-mbus-status\";\nexport * from \"./device-samples\";\nexport * from \"./mass-flow-inlet\";\nexport * from \"./mass-flow-outlet\";\nexport * from \"./mass-flow\";\nexport * from \"./mass-inlet\";\nexport * from \"./mass-outlet\";\nexport * from \"./mass\";\nexport * from \"./mbus-format-string-signature\";\nexport * from \"./none\";\nexport * from \"./operating-time\";\nexport * from \"./place\";\nexport * from \"./power-inlet\";\nexport * from \"./power-outlet\";\nexport * from \"./power\";\nexport * from \"./pressure-inlet\";\nexport * from \"./pressure-outlet\";\nexport * from \"./pressure\";\nexport * from \"./radiator-temperature\";\nexport * from \"./reactive-energy\";\nexport * from \"./relative-humidity\";\nexport * from \"./remaining-battery-time\";\nexport * from \"./time-last-exact-overhearing-arrived\";\nexport * from \"./time-last-installation-mounted\";\nexport * from \"./time-last-possible-candidate-overhearing-arrived\";\nexport * from \"./time-last-sampled\";\nexport * from \"./time\";\nexport * from \"./volume-flow-inlet\";\nexport * from \"./volume-flow-outlet\";\nexport * from \"./volume-flow\";\nexport * from \"./volume-inlet\";\nexport * from \"./volume-outlet\";\nexport * from \"./volume-pulse-input-a\";\nexport * from \"./volume-pulse-input-b\";\nexport * from \"./volume\";\n"],"names":[],"version":3,"file":"index.js.map"}