@aidc-toolkit/core 1.0.33-beta → 1.0.35-beta

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Core Package
2
2
 
3
- **Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit contributors**
3
+ **Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit contributors**
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6
6
 
@@ -10,10 +10,6 @@ Unless required by applicable law or agreed to in writing, software distributed
10
10
 
11
11
  ## Overview
12
12
 
13
- > [!WARNING]
14
- >
15
- > **This software is in beta**, with production release is scheduled for 2025Q4. To follow the status of this and other projects, go to the AIDC Toolkit [projects](https://github.com/orgs/aidc-toolkit/projects) page.
16
-
17
13
  The AIDC Toolkit `core` package contains artefacts to support other AIDC Toolkit packages; it does not itself provide any of the functionality of the AIDC Toolkit. It is a required dependency for all AIDC Toolkit packages.
18
14
 
19
15
  ## Types and Type Helpers
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Alpha base URL. Reads from local application storage, path "config", key "resources.local", if present, otherwise
3
+ * defaults to the Vite server URL.
4
+ */
5
+ export declare const ALPHA_BASE_URL: Promise<string>;
6
+ /**
7
+ * AIDC Toolkit base URL.
8
+ */
9
+ export declare const AIDC_TOOLKIT_BASE_URL = "https://aidc-toolkit.com";
10
+ /**
11
+ * Determine the base URL for the phase based on the package version.
12
+ *
13
+ * @param version
14
+ * Package version.
15
+ *
16
+ * @param alphaBaseURL
17
+ * Alpha base URL.
18
+ *
19
+ * @param nonAlphaRelativeURL
20
+ * Non-alpha URL, relative to non-alpha base URL and optionally the pre-release identifier and version.
21
+ *
22
+ * @returns
23
+ * Fully-formed base URL for the phase.
24
+ */
25
+ export declare function baseURL(version: string, alphaBaseURL: string, nonAlphaRelativeURL?: string): string;
26
+ //# sourceMappingURL=base-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-url.d.ts","sourceRoot":"","sources":["../src/base-url.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAK1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAsBnG"}
@@ -0,0 +1,62 @@
1
+ import { LocalAppDataStorage } from "./local-app-data-storage.js";
2
+ import { parseVersion } from "./parse-version.js";
3
+ /**
4
+ * Default alpha URL (Vite development URL) if no local resources file is found.
5
+ */
6
+ const DEFAULT_ALPHA_BASE_URL = "http://localhost:5173";
7
+ /**
8
+ * Configuration path, expected to be present in development but not necessarily in production.
9
+ */
10
+ const CONFIGURATION_PATH = "config";
11
+ /**
12
+ * Key to local resources, expected to be present in development but not necessarily in production.
13
+ */
14
+ const LOCAL_RESOURCES_KEY = "resources.local";
15
+ /**
16
+ * Alpha base URL. Reads from local application storage, path "config", key "resources.local", if present, otherwise
17
+ * defaults to the Vite server URL.
18
+ */
19
+ export const ALPHA_BASE_URL = LocalAppDataStorage.then(async (LocalAppDataStorage) => new LocalAppDataStorage(CONFIGURATION_PATH).read(LOCAL_RESOURCES_KEY)).then(resources =>
20
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Fallback works regardless of type.
21
+ resources?.alphaBaseURL ?? DEFAULT_ALPHA_BASE_URL);
22
+ /**
23
+ * AIDC Toolkit base URL.
24
+ */
25
+ export const AIDC_TOOLKIT_BASE_URL = "https://aidc-toolkit.com";
26
+ /**
27
+ * Determine the base URL for the phase based on the package version.
28
+ *
29
+ * @param version
30
+ * Package version.
31
+ *
32
+ * @param alphaBaseURL
33
+ * Alpha base URL.
34
+ *
35
+ * @param nonAlphaRelativeURL
36
+ * Non-alpha URL, relative to non-alpha base URL and optionally the pre-release identifier and version.
37
+ *
38
+ * @returns
39
+ * Fully-formed base URL for the phase.
40
+ */
41
+ export function baseURL(version, alphaBaseURL, nonAlphaRelativeURL) {
42
+ const parsedVersion = parseVersion(version);
43
+ const preReleaseIdentifier = parsedVersion.preReleaseIdentifier;
44
+ let url;
45
+ if (preReleaseIdentifier === "alpha") {
46
+ // Alpha base URL is absolute.
47
+ url = alphaBaseURL;
48
+ }
49
+ else {
50
+ const relativeURL = nonAlphaRelativeURL !== undefined && nonAlphaRelativeURL !== "" ? `/${nonAlphaRelativeURL}` : "";
51
+ if (preReleaseIdentifier !== undefined) {
52
+ // Non-alpha base URL is relative to AIDC Toolkit base URL plus pre-release identifier and version.
53
+ url = `${AIDC_TOOLKIT_BASE_URL}/${preReleaseIdentifier}/v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${relativeURL}`;
54
+ }
55
+ else {
56
+ // Production base URL is relative to AIDC Toolkit base URL.
57
+ url = `${AIDC_TOOLKIT_BASE_URL}${relativeURL}`;
58
+ }
59
+ }
60
+ return url;
61
+ }
62
+ //# sourceMappingURL=base-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-url.js","sourceRoot":"","sources":["../src/base-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAEvD;;GAEG;AACH,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAEpC;;GAEG;AACH,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAS9C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAC,mBAAmB,EAAC,EAAE,CAC/E,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CACxE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACf,6GAA6G;AAC5G,SAA0C,EAAE,YAAY,IAAI,sBAAsB,CACtF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,YAAoB,EAAE,mBAA4B;IACvF,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,oBAAoB,GAAG,aAAa,CAAC,oBAAoB,CAAC;IAEhE,IAAI,GAAW,CAAC;IAEhB,IAAI,oBAAoB,KAAK,OAAO,EAAE,CAAC;QACnC,8BAA8B;QAC9B,GAAG,GAAG,YAAY,CAAC;IACvB,CAAC;SAAM,CAAC;QACJ,MAAM,WAAW,GAAG,mBAAmB,KAAK,SAAS,IAAI,mBAAmB,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAErH,IAAI,oBAAoB,KAAK,SAAS,EAAE,CAAC;YACrC,mGAAmG;YACnG,GAAG,GAAG,GAAG,qBAAqB,IAAI,oBAAoB,KAAK,aAAa,CAAC,YAAY,IAAI,aAAa,CAAC,YAAY,GAAG,WAAW,EAAE,CAAC;QACxI,CAAC;aAAM,CAAC;YACJ,4DAA4D;YAC5D,GAAG,GAAG,GAAG,qBAAqB,GAAG,WAAW,EAAE,CAAC;QACnD,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
2
+ * Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
3
3
  * contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,8 @@
17
17
  export type * from "./type.js";
18
18
  export * from "./type-helper.js";
19
19
  export * from "./logger.js";
20
+ export * from "./parse-version.js";
21
+ export * from "./base-url.js";
20
22
  export * from "./app-data.js";
21
23
  export * from "./app-data-storage.js";
22
24
  export * from "./local-app-data-storage.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,mBAAmB,WAAW,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,aAAa,CAAC;AAE5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,YAAY,CAAC;AAE3B,mBAAmB,gBAAgB,CAAC;AAEpC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,mBAAmB,WAAW,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,aAAa,CAAC;AAE5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAE9B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,YAAY,CAAC;AAE3B,mBAAmB,gBAAgB,CAAC;AAEpC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,23 @@
1
+ /*!
2
+ * Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
3
+ * contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
1
17
  export * from "./type-helper.js";
2
18
  export * from "./logger.js";
19
+ export * from "./parse-version.js";
20
+ export * from "./base-url.js";
3
21
  export * from "./app-data.js";
4
22
  export * from "./app-data-storage.js";
5
23
  export * from "./local-app-data-storage.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,cAAc,kBAAkB,CAAC;AAEjC,cAAc,aAAa,CAAC;AAE5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,YAAY,CAAC;AAI3B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,cAAc,kBAAkB,CAAC;AAEjC,cAAc,aAAa,CAAC;AAE5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAE9B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,YAAY,CAAC;AAI3B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Parsed version.
3
+ */
4
+ export interface ParsedVersion {
5
+ /**
6
+ * Major version.
7
+ */
8
+ readonly majorVersion: number;
9
+ /**
10
+ * Minor version.
11
+ */
12
+ readonly minorVersion: number;
13
+ /**
14
+ * Patch version.
15
+ */
16
+ readonly patchVersion: number;
17
+ /**
18
+ * Pre-release identifier.
19
+ */
20
+ readonly preReleaseIdentifier: string | undefined;
21
+ /**
22
+ * Date/time included with pre-release identifier.
23
+ */
24
+ readonly dateTime: string | undefined;
25
+ }
26
+ /**
27
+ * Parse version.
28
+ *
29
+ * @param version
30
+ * Version, typically from package.json.
31
+ *
32
+ * @returns
33
+ * Parsed version.
34
+ */
35
+ export declare function parseVersion(version: string): ParsedVersion;
36
+ //# sourceMappingURL=parse-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-version.d.ts","sourceRoot":"","sources":["../src/parse-version.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IAElD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAc3D"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Parse version.
3
+ *
4
+ * @param version
5
+ * Version, typically from package.json.
6
+ *
7
+ * @returns
8
+ * Parsed version.
9
+ */
10
+ export function parseVersion(version) {
11
+ const parsedVersionGroups = /^(?<majorVersion>\d+)\.(?<minorVersion>\d+)\.(?<patchVersion>\d+)(?:-(?<preReleaseIdentifier>alpha|beta)(?:\.(?<dateTime>\d{12}))?)?$/u.exec(version)?.groups;
12
+ if (parsedVersionGroups === undefined) {
13
+ throw new Error(`Invalid package version ${version}`);
14
+ }
15
+ return {
16
+ majorVersion: Number(parsedVersionGroups["majorVersion"]),
17
+ minorVersion: Number(parsedVersionGroups["minorVersion"]),
18
+ patchVersion: Number(parsedVersionGroups["patchVersion"]),
19
+ preReleaseIdentifier: parsedVersionGroups["preReleaseIdentifier"],
20
+ dateTime: parsedVersionGroups["dateTime"]
21
+ };
22
+ }
23
+ //# sourceMappingURL=parse-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-version.js","sourceRoot":"","sources":["../src/parse-version.ts"],"names":[],"mappings":"AA8BA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IACxC,MAAM,mBAAmB,GAAG,wIAAwI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE3L,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACH,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,YAAY,EAAE,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACzD,oBAAoB,EAAE,mBAAmB,CAAC,sBAAsB,CAAC;QACjE,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC;KAC5C,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aidc-toolkit/core",
3
- "version": "1.0.33-beta",
3
+ "version": "1.0.35-beta",
4
4
  "description": "Core functionality for AIDC Toolkit",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,17 +21,18 @@
21
21
  "scripts": {
22
22
  "lint": "eslint",
23
23
  "tsc-src": "tsc --project tsconfig-src.json",
24
- "build:alpha": "rimraf dist && npm run tsc-src -- --declarationMap --sourceMap",
25
- "build:beta": "npm run build:alpha",
24
+ "build:non-prod": "rimraf dist && npm run tsc-src -- --declarationMap --sourceMap",
25
+ "build:alpha": "npm run build:non-prod && tsc --project tsconfig-config.json --noEmit",
26
+ "build:beta": "npm run build:non-prod",
26
27
  "build:prod": "npm run tsc-src -- --noEmit && tsup",
27
- "build:doc": "npm run build:alpha"
28
+ "build:doc": "npm run build:non-prod"
28
29
  },
29
30
  "devDependencies": {
30
- "@aidc-toolkit/dev": "1.0.33-beta"
31
+ "@aidc-toolkit/dev": "1.0.34-beta"
31
32
  },
32
33
  "dependencies": {
33
34
  "base64-js": "^1.5.1",
34
- "i18next": "^25.7.4",
35
+ "i18next": "^25.8.0",
35
36
  "i18next-browser-languagedetector": "^8.2.0",
36
37
  "i18next-cli-language-detector": "^1.1.8",
37
38
  "tslog": "^4.10.2"
@@ -0,0 +1,79 @@
1
+ import { LocalAppDataStorage } from "./local-app-data-storage.js";
2
+ import { parseVersion } from "./parse-version.js";
3
+
4
+ /**
5
+ * Default alpha URL (Vite development URL) if no local resources file is found.
6
+ */
7
+ const DEFAULT_ALPHA_BASE_URL = "http://localhost:5173";
8
+
9
+ /**
10
+ * Configuration path, expected to be present in development but not necessarily in production.
11
+ */
12
+ const CONFIGURATION_PATH = "config";
13
+
14
+ /**
15
+ * Key to local resources, expected to be present in development but not necessarily in production.
16
+ */
17
+ const LOCAL_RESOURCES_KEY = "resources.local";
18
+
19
+ /**
20
+ * Local resources.
21
+ */
22
+ interface LocalResources {
23
+ alphaBaseURL: string;
24
+ }
25
+
26
+ /**
27
+ * Alpha base URL. Reads from local application storage, path "config", key "resources.local", if present, otherwise
28
+ * defaults to the Vite server URL.
29
+ */
30
+ export const ALPHA_BASE_URL = LocalAppDataStorage.then(async LocalAppDataStorage =>
31
+ new LocalAppDataStorage(CONFIGURATION_PATH).read(LOCAL_RESOURCES_KEY)
32
+ ).then(resources =>
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Fallback works regardless of type.
34
+ (resources as (LocalResources | undefined))?.alphaBaseURL ?? DEFAULT_ALPHA_BASE_URL
35
+ );
36
+
37
+ /**
38
+ * AIDC Toolkit base URL.
39
+ */
40
+ export const AIDC_TOOLKIT_BASE_URL = "https://aidc-toolkit.com";
41
+
42
+ /**
43
+ * Determine the base URL for the phase based on the package version.
44
+ *
45
+ * @param version
46
+ * Package version.
47
+ *
48
+ * @param alphaBaseURL
49
+ * Alpha base URL.
50
+ *
51
+ * @param nonAlphaRelativeURL
52
+ * Non-alpha URL, relative to non-alpha base URL and optionally the pre-release identifier and version.
53
+ *
54
+ * @returns
55
+ * Fully-formed base URL for the phase.
56
+ */
57
+ export function baseURL(version: string, alphaBaseURL: string, nonAlphaRelativeURL?: string): string {
58
+ const parsedVersion = parseVersion(version);
59
+ const preReleaseIdentifier = parsedVersion.preReleaseIdentifier;
60
+
61
+ let url: string;
62
+
63
+ if (preReleaseIdentifier === "alpha") {
64
+ // Alpha base URL is absolute.
65
+ url = alphaBaseURL;
66
+ } else {
67
+ const relativeURL = nonAlphaRelativeURL !== undefined && nonAlphaRelativeURL !== "" ? `/${nonAlphaRelativeURL}` : "";
68
+
69
+ if (preReleaseIdentifier !== undefined) {
70
+ // Non-alpha base URL is relative to AIDC Toolkit base URL plus pre-release identifier and version.
71
+ url = `${AIDC_TOOLKIT_BASE_URL}/${preReleaseIdentifier}/v${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${relativeURL}`;
72
+ } else {
73
+ // Production base URL is relative to AIDC Toolkit base URL.
74
+ url = `${AIDC_TOOLKIT_BASE_URL}${relativeURL}`;
75
+ }
76
+ }
77
+
78
+ return url;
79
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright © 2024-2025 Dolphin Data Development Ltd. and AIDC Toolkit
2
+ * Copyright © 2024-2026 Dolphin Data Development Ltd. and AIDC Toolkit
3
3
  * contributors
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,11 +14,15 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+
17
18
  export type * from "./type.js";
18
19
  export * from "./type-helper.js";
19
20
 
20
21
  export * from "./logger.js";
21
22
 
23
+ export * from "./parse-version.js";
24
+ export * from "./base-url.js";
25
+
22
26
  export * from "./app-data.js";
23
27
  export * from "./app-data-storage.js";
24
28
  export * from "./local-app-data-storage.js";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Parsed version.
3
+ */
4
+ export interface ParsedVersion {
5
+ /**
6
+ * Major version.
7
+ */
8
+ readonly majorVersion: number;
9
+
10
+ /**
11
+ * Minor version.
12
+ */
13
+ readonly minorVersion: number;
14
+
15
+ /**
16
+ * Patch version.
17
+ */
18
+ readonly patchVersion: number;
19
+
20
+ /**
21
+ * Pre-release identifier.
22
+ */
23
+ readonly preReleaseIdentifier: string | undefined;
24
+
25
+ /**
26
+ * Date/time included with pre-release identifier.
27
+ */
28
+ readonly dateTime: string | undefined;
29
+ }
30
+
31
+ /**
32
+ * Parse version.
33
+ *
34
+ * @param version
35
+ * Version, typically from package.json.
36
+ *
37
+ * @returns
38
+ * Parsed version.
39
+ */
40
+ export function parseVersion(version: string): ParsedVersion {
41
+ const parsedVersionGroups = /^(?<majorVersion>\d+)\.(?<minorVersion>\d+)\.(?<patchVersion>\d+)(?:-(?<preReleaseIdentifier>alpha|beta)(?:\.(?<dateTime>\d{12}))?)?$/u.exec(version)?.groups;
42
+
43
+ if (parsedVersionGroups === undefined) {
44
+ throw new Error(`Invalid package version ${version}`);
45
+ }
46
+
47
+ return {
48
+ majorVersion: Number(parsedVersionGroups["majorVersion"]),
49
+ minorVersion: Number(parsedVersionGroups["minorVersion"]),
50
+ patchVersion: Number(parsedVersionGroups["patchVersion"]),
51
+ preReleaseIdentifier: parsedVersionGroups["preReleaseIdentifier"],
52
+ dateTime: parsedVersionGroups["dateTime"]
53
+ };
54
+ }