@olenbetong/appframe-core 2.11.5 → 2.11.7

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.
@@ -7,7 +7,7 @@ import { expose } from "./expose.js";
7
7
  GlobalRegistrator.register();
8
8
 
9
9
  declare global {
10
- var test: {
10
+ var exposeTest: {
11
11
  value?: string;
12
12
  func: () => string;
13
13
  nested: {
@@ -21,39 +21,39 @@ describe("expose", () => {
21
21
  function func() {
22
22
  return "test";
23
23
  }
24
- expose("test", func);
24
+ expose("exposeTest", func);
25
25
 
26
- expect(globalThis.test.func).toBe(func);
26
+ expect(globalThis.exposeTest.func).toBe(func);
27
27
  });
28
28
 
29
29
  test("should expose function to global scope with nested name", () => {
30
30
  function func() {
31
31
  return "test";
32
32
  }
33
- expose("test.nested", func);
33
+ expose("exposeTest.nested", func);
34
34
 
35
- expect(globalThis.test.nested.func).toBe(func);
35
+ expect(globalThis.exposeTest.nested.func).toBe(func);
36
36
  });
37
37
 
38
38
  test("should not overwrite existing without overwrite set to true", () => {
39
39
  let value1 = "test1";
40
40
  let value2 = "test2";
41
41
 
42
- expose("test.value", value1);
43
- expect(globalThis.test.value).toBe(value1);
42
+ expose("exposeTest.value", value1);
43
+ expect(globalThis.exposeTest.value).toBe(value1);
44
44
 
45
- expose("test.value", value2);
46
- expect(globalThis.test.value).not.toBe(value2);
45
+ expose("exposeTest.value", value2);
46
+ expect(globalThis.exposeTest.value).not.toBe(value2);
47
47
  });
48
48
 
49
49
  test("should overwrite existing with overwrite set to true", () => {
50
50
  let value1 = "test1";
51
51
  let value2 = "test2";
52
52
 
53
- expose("test.value", value1);
54
- expect(globalThis.test.value).toBe(value1);
53
+ expose("exposeTest.value", value1);
54
+ expect(globalThis.exposeTest.value).toBe(value1);
55
55
 
56
- expose("test.value", value2, { overwrite: true });
57
- expect(globalThis.test.value).toBe(value2);
56
+ expose("exposeTest.value", value2, { overwrite: true });
57
+ expect(globalThis.exposeTest.value).toBe(value2);
58
58
  });
59
59
  });
package/src/expose.ts CHANGED
@@ -16,7 +16,7 @@ export type ExposeOptions = {
16
16
  */
17
17
  export function expose(
18
18
  name: object | string,
19
- value: object | Function | Function[] | string | number,
19
+ value: object | ((...args: any[]) => any) | ((...args: any[]) => any)[] | string | number,
20
20
  options: ExposeOptions = {},
21
21
  ): void {
22
22
  if (Array.isArray(value)) {
@@ -31,10 +31,10 @@ export function expose(
31
31
  }
32
32
  } else {
33
33
  let keyName: string | undefined;
34
- let namespace;
34
+ let namespace: any;
35
35
 
36
36
  if (typeof value === "function") {
37
- keyName = parseFunc(value).name;
37
+ keyName = parseFunc(value as (...args: any[]) => any).name;
38
38
  }
39
39
 
40
40
  if (typeof name === "string") {
@@ -54,7 +54,7 @@ export function expose(
54
54
 
55
55
  if (Object.hasOwn(namespace, keyName) && options?.overwrite !== true) {
56
56
  // If class is already defined, warn or show an alert
57
- console.warn([name, keyName].join(".") + " is already defined!");
57
+ console.warn(`${[name, keyName].join(".")} is already defined!`);
58
58
  } else {
59
59
  namespace[keyName] = value;
60
60
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { UserSession } from "./UserSession.js";
2
- import { alert, confirm, openAlertDialog } from "./alert.js";
2
+ import type { alert, confirm, openAlertDialog } from "./alert.js";
3
3
  import "./errorHandler.js";
4
- import { expose } from "./expose.js";
5
- import { getLocalizedString } from "./getLocalizedString.js";
4
+ import type { expose } from "./expose.js";
5
+ import type { getLocalizedString } from "./getLocalizedString.js";
6
6
  import afLocalStorage from "./localStorage.js";
7
- import { localize } from "./localize.js";
8
- import { getSessionData, logActivity, logError, startActivity, time } from "./log.js";
7
+ import type { localize } from "./localize.js";
8
+ import type { getSessionData, logActivity, logError, startActivity, time } from "./log.js";
9
9
 
10
10
  export { default as mitt } from "mitt";
11
11
  export { toLocalISODate, toLocalISODateTime, toLocalDateTime } from "./date.js";
@@ -26,6 +26,7 @@ export { getSettings, saveSettings } from "./settings.js";
26
26
  export { alert, confirm, ConfirmButtons, openAlertDialog, waitForDialog } from "./alert.js";
27
27
  export type { AlertDialogButton, AlertDialogOptions, AlertOptions, ConfirmOptions } from "./alert.js";
28
28
 
29
+ // biome-ignore lint/correctness/noInvalidUseBeforeDeclaration: <explanation>
29
30
  export const version = __VERSION__;
30
31
 
31
32
  declare global {
package/src/invariant.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Throws an error if the condition is falsy. The provided message is used as the error message.
3
3
  * A function can be provided to lazily generate the message.
4
- *
5
- * @param {any} condition
6
- * @param {string | (() => string)} [message]
4
+ *
5
+ * @param {any} condition
6
+ * @param {string | (() => string)} [message]
7
7
  * @returns {void}
8
8
  */
9
9
  export function invariant(condition: any, message?: string | (() => string)): asserts condition {
package/src/localize.ts CHANGED
@@ -24,7 +24,7 @@ export function localize(stringParts: TemplateStringsArray, ...args: any[]): str
24
24
  let localized = getLocalizedString(stringToLocalize);
25
25
 
26
26
  args.forEach((arg, index) => {
27
- localized = localized.replace("$" + index, arg);
27
+ localized = localized.replace(`$${index}`, arg);
28
28
  });
29
29
 
30
30
  return localized;
package/src/log.ts CHANGED
@@ -7,7 +7,7 @@ const article = globalThis.af?.article?.id ?? globalThis.window?.location.pathna
7
7
  * @param parameters A dictionary of parameters used when doing the activity
8
8
  * @param timeElapsed Number of milliseconds elapsed while executing
9
9
  */
10
- export async function logActivity(activity: string, parameters: Record<string, any> = {}, timeElapsed: number = 0) {
10
+ export async function logActivity(activity: string, parameters: Record<string, any> = {}, timeElapsed = 0) {
11
11
  try {
12
12
  let response = await fetch("/api/logging/log-activity", {
13
13
  method: "POST",
package/src/parseFunc.ts CHANGED
@@ -3,8 +3,8 @@ import { invariant } from "./invariant.js";
3
3
  const funcRegex =
4
4
  /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
5
5
 
6
- export function parseFunc(func: Function) {
7
- var match = func.toString().match(funcRegex);
6
+ export function parseFunc(func: (...args: any[]) => any) {
7
+ const match = func.toString().match(funcRegex);
8
8
  invariant(match, "Unable to parse function!");
9
9
  return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
10
10
  }