@olenbetong/appframe-core 2.11.6 → 2.11.8
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/dist/esm/af.common.js +63 -67
- package/dist/esm/af.common.legacy.js +67 -74
- package/dist/esm/af.common.legacy.min.js +1 -1
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +2 -2
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +67 -72
- package/dist/iife/af.common.legacy.js +71 -79
- package/dist/iife/af.common.legacy.min.js +1 -1
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +2 -2
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/SessionHandler.d.ts +1 -1
- package/es/alert.js +3 -1
- package/es/date.test.js +1 -1
- package/es/downloadBlob.js +2 -2
- package/es/downloadRequest.js +3 -3
- package/es/expose.d.ts +1 -1
- package/es/expose.js +1 -1
- package/es/expose.test.d.ts +1 -1
- package/es/expose.test.js +13 -13
- package/es/getLocalizedString.js +1 -1
- package/es/getUserImage.test.js +2 -2
- package/es/index.d.ts +11 -11
- package/es/index.js +5 -4
- package/es/invariant.test.js +2 -2
- package/es/localize.js +2 -2
- package/es/log.js +1 -1
- package/es/parseFunc.d.ts +1 -1
- package/es/parseFunc.js +1 -1
- package/es/parseFunc.test.js +2 -2
- package/es/test/setup.d.ts +0 -0
- package/es/test/setup.js +3 -0
- package/package.json +53 -53
- package/src/SessionHandler.ts +2 -2
- package/src/UserSession.ts +10 -10
- package/src/alert.ts +8 -6
- package/src/date.test.ts +1 -1
- package/src/date.ts +1 -1
- package/src/downloadBlob.ts +2 -2
- package/src/downloadRequest.ts +3 -3
- package/src/expose.test.ts +14 -15
- package/src/expose.ts +4 -4
- package/src/getLocalizedString.ts +1 -1
- package/src/getUserImage.test.ts +2 -2
- package/src/index.ts +12 -11
- package/src/invariant.test.ts +2 -2
- package/src/invariant.ts +3 -3
- package/src/localize.ts +2 -2
- package/src/log.ts +2 -2
- package/src/parseFunc.test.ts +2 -2
- package/src/parseFunc.ts +2 -2
- package/src/test/setup.ts +2 -0
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
2
|
+
"name": "@olenbetong/appframe-core",
|
|
3
|
+
"version": "2.11.8",
|
|
4
|
+
"description": "Javascript libraries to utilize the Appframe framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"./src/errorHandler.ts"
|
|
8
|
+
],
|
|
9
|
+
"main": "./es/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"default": "./es/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "./es/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"es",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"author": "Bjørnar Vister Hansen <bvh@olenbetong.no>",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/olenbetong/SynergiWeb.git"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"buildConfig": {
|
|
28
|
+
"entries": [
|
|
29
|
+
{
|
|
30
|
+
"libraryName": "af.common"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"libraryName": "af.common",
|
|
34
|
+
"outfile": "af.common.legacy",
|
|
35
|
+
"target": "safari11"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@happy-dom/global-registrator": "^15.7.3",
|
|
41
|
+
"mitt": "^3.0.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bun": "^1.1.8",
|
|
45
|
+
"chalk": "^5.3.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "pnpm run build:tsc && pnpm test && pnpm run build:esbuild && pnpm run build:replace-version",
|
|
49
|
+
"test": "vitest run --config vitest.node.config.ts",
|
|
50
|
+
"build:esbuild": "node --no-warnings ../../scripts/packages-esbuild.ts",
|
|
51
|
+
"build:replace-version": "node ./scripts/replace-version.js",
|
|
52
|
+
"build:tsc": "rm -rf ./es tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/SessionHandler.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import mitt, { Emitter, Handler } from "mitt";
|
|
1
|
+
import mitt, { type Emitter, type Handler } from "mitt";
|
|
2
2
|
|
|
3
3
|
type SessionHandlerEvent = "onExpired" | "onAuthenticated";
|
|
4
4
|
|
|
5
5
|
export default class SessionHandler {
|
|
6
|
-
private eventHandler: Emitter<{ onAuthenticated:
|
|
6
|
+
private eventHandler: Emitter<{ onAuthenticated: undefined; onExpired: undefined }> = mitt();
|
|
7
7
|
|
|
8
8
|
authenticated() {
|
|
9
9
|
this.eventHandler.emit("onAuthenticated");
|
package/src/UserSession.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import SessionHandler from "./SessionHandler.js";
|
|
2
2
|
|
|
3
3
|
export class UserSession extends SessionHandler {
|
|
4
|
-
amDesignator
|
|
4
|
+
amDesignator = "a.m.";
|
|
5
5
|
dayNames: string[] = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
6
6
|
dayNamesShort: string[] = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
7
|
-
decimalSeparator
|
|
8
|
-
domain
|
|
7
|
+
decimalSeparator = ".";
|
|
8
|
+
domain = "OB";
|
|
9
9
|
email: string | null | undefined;
|
|
10
10
|
formats: undefined | Record<string, string>;
|
|
11
11
|
groupSeparator: string | null = null;
|
|
12
|
-
integratedSecurity
|
|
13
|
-
isDeveloper
|
|
14
|
-
login
|
|
12
|
+
integratedSecurity = false;
|
|
13
|
+
isDeveloper = false;
|
|
14
|
+
login = "";
|
|
15
15
|
loginType: string | undefined;
|
|
16
16
|
monthNames: string[] = [
|
|
17
17
|
"january",
|
|
@@ -30,10 +30,10 @@ export class UserSession extends SessionHandler {
|
|
|
30
30
|
];
|
|
31
31
|
monthNamesShort: string[] = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""];
|
|
32
32
|
name: string | undefined;
|
|
33
|
-
pmDesignator
|
|
34
|
-
shortDateFormat
|
|
35
|
-
culture
|
|
36
|
-
uiculture
|
|
33
|
+
pmDesignator = "p.m.";
|
|
34
|
+
shortDateFormat = "dd.MM.yyyy";
|
|
35
|
+
culture = "en-GB";
|
|
36
|
+
uiculture = "en-GB";
|
|
37
37
|
|
|
38
38
|
constructor(userData: any) {
|
|
39
39
|
super();
|
package/src/alert.ts
CHANGED
|
@@ -18,7 +18,7 @@ if (globalThis.document && !document.querySelector("#AlertDialogTemplate")) {
|
|
|
18
18
|
document.body.append($template);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function waitForDialog(dialog: HTMLDialogElement, cancelValue
|
|
21
|
+
export function waitForDialog(dialog: HTMLDialogElement, cancelValue = "No"): Promise<string> {
|
|
22
22
|
return new Promise((resolve) => {
|
|
23
23
|
let controller = new AbortController();
|
|
24
24
|
|
|
@@ -72,7 +72,9 @@ export async function openAlertDialog({ buttons, content, className, id, title }
|
|
|
72
72
|
if (!$dialog || !$content || !$menu) throw Error("Invalid alert dialog template");
|
|
73
73
|
|
|
74
74
|
if (className) {
|
|
75
|
-
className.split(/\s+/)
|
|
75
|
+
for (const className_ of className.split(/\s+/)) {
|
|
76
|
+
$dialog?.classList.add(className_);
|
|
77
|
+
}
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
if (title) {
|
|
@@ -113,8 +115,8 @@ export async function openAlertDialog({ buttons, content, className, id, title }
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
export enum ConfirmButtons {
|
|
116
|
-
YesNo,
|
|
117
|
-
OkCancel,
|
|
118
|
+
YesNo = 0,
|
|
119
|
+
OkCancel = 1,
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
export type ConfirmOptions = {
|
|
@@ -129,11 +131,11 @@ export async function confirm(prompt: string, options: ConfirmOptions = {}): Pro
|
|
|
129
131
|
? [
|
|
130
132
|
{ label: getLocalizedString("OK"), value: "yes", primary: true },
|
|
131
133
|
{ label: getLocalizedString("Cancel"), value: "no" },
|
|
132
|
-
|
|
134
|
+
]
|
|
133
135
|
: [
|
|
134
136
|
{ label: getLocalizedString("Yes"), value: "yes", primary: true },
|
|
135
137
|
{ label: getLocalizedString("No"), value: "no" },
|
|
136
|
-
|
|
138
|
+
];
|
|
137
139
|
|
|
138
140
|
let result = await openAlertDialog({ content: prompt, buttons, className: "alert-dialog-confirm", title });
|
|
139
141
|
return result === "yes";
|
package/src/date.test.ts
CHANGED
package/src/date.ts
CHANGED
|
@@ -4,7 +4,7 @@ export function toLocalISODate(date: Date | null): string | null {
|
|
|
4
4
|
return date ? toLocalISODateTime(date).substring(0, 10) : null;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function pad(num: number, digits
|
|
7
|
+
function pad(num: number, digits = 2) {
|
|
8
8
|
return String(num).padStart(digits, "0");
|
|
9
9
|
}
|
|
10
10
|
|
package/src/downloadBlob.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function downloadBlob(blob: Blob | MediaSource, fileName: string) {
|
|
2
|
-
return new Promise<void>(
|
|
2
|
+
return new Promise<void>((resolve, reject) => {
|
|
3
3
|
try {
|
|
4
4
|
const url = URL.createObjectURL(blob);
|
|
5
5
|
const parent = document.body;
|
|
@@ -10,7 +10,7 @@ export function downloadBlob(blob: Blob | MediaSource, fileName: string) {
|
|
|
10
10
|
anchor.click();
|
|
11
11
|
parent.removeChild(anchor);
|
|
12
12
|
|
|
13
|
-
setTimeout(
|
|
13
|
+
setTimeout(() => {
|
|
14
14
|
URL.revokeObjectURL(url);
|
|
15
15
|
resolve();
|
|
16
16
|
}, 250);
|
package/src/downloadRequest.ts
CHANGED
|
@@ -32,9 +32,9 @@ export async function downloadRequest(request: Request, { fileName, signal, onPr
|
|
|
32
32
|
try {
|
|
33
33
|
const reader = response.body.getReader();
|
|
34
34
|
const stream = new ReadableStream({
|
|
35
|
-
start:
|
|
35
|
+
start: (controller) => {
|
|
36
36
|
function pump(): Promise<void> {
|
|
37
|
-
return reader.read().then(
|
|
37
|
+
return reader.read().then((read) => {
|
|
38
38
|
if (read.done) {
|
|
39
39
|
controller.close();
|
|
40
40
|
return;
|
|
@@ -53,7 +53,7 @@ export async function downloadRequest(request: Request, { fileName, signal, onPr
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
response = new Response(stream);
|
|
56
|
-
} catch
|
|
56
|
+
} catch {}
|
|
57
57
|
|
|
58
58
|
const blob = await response.blob();
|
|
59
59
|
|
package/src/expose.test.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
1
2
|
import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
|
2
3
|
|
|
3
|
-
import { describe, expect, test } from "bun:test";
|
|
4
|
-
|
|
5
4
|
import { expose } from "./expose.js";
|
|
6
5
|
|
|
7
6
|
GlobalRegistrator.register();
|
|
8
7
|
|
|
9
8
|
declare global {
|
|
10
|
-
var
|
|
9
|
+
var exposeTest: {
|
|
11
10
|
value?: string;
|
|
12
11
|
func: () => string;
|
|
13
12
|
nested: {
|
|
@@ -21,39 +20,39 @@ describe("expose", () => {
|
|
|
21
20
|
function func() {
|
|
22
21
|
return "test";
|
|
23
22
|
}
|
|
24
|
-
expose("
|
|
23
|
+
expose("exposeTest", func);
|
|
25
24
|
|
|
26
|
-
expect(globalThis.
|
|
25
|
+
expect(globalThis.exposeTest.func).toBe(func);
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
test("should expose function to global scope with nested name", () => {
|
|
30
29
|
function func() {
|
|
31
30
|
return "test";
|
|
32
31
|
}
|
|
33
|
-
expose("
|
|
32
|
+
expose("exposeTest.nested", func);
|
|
34
33
|
|
|
35
|
-
expect(globalThis.
|
|
34
|
+
expect(globalThis.exposeTest.nested.func).toBe(func);
|
|
36
35
|
});
|
|
37
36
|
|
|
38
37
|
test("should not overwrite existing without overwrite set to true", () => {
|
|
39
38
|
let value1 = "test1";
|
|
40
39
|
let value2 = "test2";
|
|
41
40
|
|
|
42
|
-
expose("
|
|
43
|
-
expect(globalThis.
|
|
41
|
+
expose("exposeTest.value", value1);
|
|
42
|
+
expect(globalThis.exposeTest.value).toBe(value1);
|
|
44
43
|
|
|
45
|
-
expose("
|
|
46
|
-
expect(globalThis.
|
|
44
|
+
expose("exposeTest.value", value2);
|
|
45
|
+
expect(globalThis.exposeTest.value).not.toBe(value2);
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
test("should overwrite existing with overwrite set to true", () => {
|
|
50
49
|
let value1 = "test1";
|
|
51
50
|
let value2 = "test2";
|
|
52
51
|
|
|
53
|
-
expose("
|
|
54
|
-
expect(globalThis.
|
|
52
|
+
expose("exposeTest.value", value1);
|
|
53
|
+
expect(globalThis.exposeTest.value).toBe(value1);
|
|
55
54
|
|
|
56
|
-
expose("
|
|
57
|
-
expect(globalThis.
|
|
55
|
+
expose("exposeTest.value", value2, { overwrite: true });
|
|
56
|
+
expect(globalThis.exposeTest.value).toBe(value2);
|
|
58
57
|
});
|
|
59
58
|
});
|
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 |
|
|
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(".")
|
|
57
|
+
console.warn(`${[name, keyName].join(".")} is already defined!`);
|
|
58
58
|
} else {
|
|
59
59
|
namespace[keyName] = value;
|
|
60
60
|
}
|
package/src/getUserImage.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe, expect, test } from "
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { getUserImage } from "./getUserImage";
|
|
3
|
+
import { getUserImage } from "./getUserImage.js";
|
|
4
4
|
|
|
5
5
|
describe("getUserImage", () => {
|
|
6
6
|
test("should return empty string when primKey is null", () => {
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
|
+
import type { alert, confirm, openAlertDialog } from "./alert.js";
|
|
1
2
|
import { UserSession } from "./UserSession.js";
|
|
2
|
-
import { 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
|
+
import type { localize } from "./localize.js";
|
|
6
7
|
import afLocalStorage from "./localStorage.js";
|
|
7
|
-
import {
|
|
8
|
-
import { getSessionData, logActivity, logError, startActivity, time } from "./log.js";
|
|
8
|
+
import type { getSessionData, logActivity, logError, startActivity, time } from "./log.js";
|
|
9
9
|
|
|
10
10
|
export { default as mitt } from "mitt";
|
|
11
|
-
export { toLocalISODate, toLocalISODateTime
|
|
11
|
+
export { toLocalDateTime, toLocalISODate, toLocalISODateTime } from "./date.js";
|
|
12
12
|
export { downloadBlob } from "./downloadBlob.js";
|
|
13
|
+
export type { DownloadItem, DownloadParameters } from "./downloadRequest.js";
|
|
13
14
|
export { downloadRequest } from "./downloadRequest.js";
|
|
14
|
-
export type { DownloadParameters, DownloadItem } from "./downloadRequest.js";
|
|
15
15
|
export { expose } from "./expose.js";
|
|
16
|
-
export { getUserImage } from "./getUserImage.js";
|
|
17
|
-
export type { getUserImageOptions } from "./getUserImage.js";
|
|
18
16
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
17
|
+
export type { getUserImageOptions } from "./getUserImage.js";
|
|
18
|
+
export { getUserImage } from "./getUserImage.js";
|
|
19
19
|
export { invariant } from "./invariant.js";
|
|
20
20
|
export { localize } from "./localize.js";
|
|
21
21
|
export { afLocalStorage as localStorage };
|
|
22
22
|
export { getSessionData, logActivity, logError, startActivity, time } from "./log.js";
|
|
23
23
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
24
24
|
export { UserSession };
|
|
25
|
-
export { getSettings, saveSettings } from "./settings.js";
|
|
26
|
-
export { alert, confirm, ConfirmButtons, openAlertDialog, waitForDialog } from "./alert.js";
|
|
27
25
|
export type { AlertDialogButton, AlertDialogOptions, AlertOptions, ConfirmOptions } from "./alert.js";
|
|
26
|
+
export { alert, ConfirmButtons, confirm, openAlertDialog, waitForDialog } from "./alert.js";
|
|
27
|
+
export { getSettings, saveSettings } from "./settings.js";
|
|
28
28
|
|
|
29
|
+
// biome-ignore lint/correctness/noInvalidUseBeforeDeclaration: this is injected build time
|
|
29
30
|
export const version = __VERSION__;
|
|
30
31
|
|
|
31
32
|
declare global {
|
package/src/invariant.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe, expect, test } from "
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { invariant } from "./invariant";
|
|
3
|
+
import { invariant } from "./invariant.js";
|
|
4
4
|
|
|
5
5
|
describe("invariant", () => {
|
|
6
6
|
test("should throw error when condition is false", () => {
|
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
|
@@ -20,11 +20,11 @@ export function localize(stringParts: TemplateStringsArray, ...args: any[]): str
|
|
|
20
20
|
"Method 'localize' must be used as a tag function",
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
let stringToLocalize = stringParts.map((s, i) => (i === stringParts.length - 1 ? s : `${s}
|
|
23
|
+
let stringToLocalize = stringParts.map((s, i) => (i === stringParts.length - 1 ? s : `${s}$${i}`)).join("");
|
|
24
24
|
let localized = getLocalizedString(stringToLocalize);
|
|
25
25
|
|
|
26
26
|
args.forEach((arg, index) => {
|
|
27
|
-
localized = localized.replace(
|
|
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
|
|
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",
|
|
@@ -31,7 +31,7 @@ export async function logActivity(activity: string, parameters: Record<string, a
|
|
|
31
31
|
console.error(`${response.status} ${response.statusText}`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
} catch
|
|
34
|
+
} catch {}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
package/src/parseFunc.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe, expect, test } from "
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { parseFunc } from "./parseFunc";
|
|
3
|
+
import { parseFunc } from "./parseFunc.js";
|
|
4
4
|
|
|
5
5
|
function testFunction(arg1: string, arg2: string) {
|
|
6
6
|
console.log(arg1, arg2);
|
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:
|
|
7
|
-
|
|
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
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Ølen Betong
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|