@olenbetong/appframe-core 2.0.4 → 2.1.1
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 +97 -197
- package/dist/esm/af.common.legacy.js +98 -191
- package/dist/esm/af.common.legacy.min.js +1 -29
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +1 -29
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +97 -195
- package/dist/iife/af.common.legacy.js +98 -191
- package/dist/iife/af.common.legacy.min.js +1 -29
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +1 -29
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/SessionHandler.d.ts +2 -7
- package/es/SessionHandler.js +34 -135
- package/es/UserSession.d.ts +1 -2
- package/es/UserSession.js +1 -2
- package/es/downloadRequest.js +1 -4
- package/es/expose.d.ts +1 -1
- package/es/expose.js +4 -5
- package/es/index.d.ts +3 -2
- package/es/index.js +4 -3
- package/es/localize.d.ts +14 -0
- package/es/localize.js +25 -0
- package/es/parseFunc.d.ts +1 -1
- package/es/parseFunc.js +1 -1
- package/es/requireNamespace.d.ts +1 -1
- package/es/requireNamespace.js +1 -7
- package/package.json +2 -2
- package/src/SessionHandler.ts +38 -156
- package/src/UserSession.ts +1 -2
- package/src/downloadRequest.ts +1 -4
- package/src/expose.ts +4 -5
- package/src/index.ts +3 -2
- package/src/localize.ts +29 -0
- package/src/parseFunc.ts +1 -1
- package/src/requireNamespace.ts +1 -5
- package/es/warn.d.ts +0 -1
- package/es/warn.js +0 -4
- package/src/warn.ts +0 -4
package/src/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import "./errorHandler.js";
|
|
2
2
|
|
|
3
|
-
import UserSession from "./UserSession.js";
|
|
3
|
+
import { UserSession } from "./UserSession.js";
|
|
4
4
|
|
|
5
5
|
export { default as mitt } from "mitt";
|
|
6
6
|
export { downloadBlob } from "./downloadBlob.js";
|
|
7
7
|
export * from "./downloadRequest.js";
|
|
8
|
-
export {
|
|
8
|
+
export { expose } from "./expose.js";
|
|
9
9
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
10
|
+
export { localize } from "./localize.js";
|
|
10
11
|
export * from "./has.js";
|
|
11
12
|
export { default as localStorage } from "./localStorage.js";
|
|
12
13
|
export { default as SessionHandler } from "./SessionHandler.js";
|
package/src/localize.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getLocalizedString } from "./getLocalizedString.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Localization function for tagged templates. Replaces the arguments
|
|
5
|
+
* with $n, where n is the index, before asking Appframe to translate
|
|
6
|
+
* the string.
|
|
7
|
+
*
|
|
8
|
+
* For example, if you call localize`Page ${2} or ${5}`, the string
|
|
9
|
+
* "Page $0 of $1" will be sent to Appframe, and for norwegian,
|
|
10
|
+
* "Side 2 av 5" will be returned.
|
|
11
|
+
*
|
|
12
|
+
* @param stringParts
|
|
13
|
+
* @param args
|
|
14
|
+
* @returns Translated string
|
|
15
|
+
*/
|
|
16
|
+
export function localize(stringParts: TemplateStringsArray, ...args: any[]): string {
|
|
17
|
+
if (!Array.isArray(stringParts) || stringParts.length !== args.length + 1) {
|
|
18
|
+
throw TypeError("Method 'localize' must be used as a tag function");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let stringToLocalize = stringParts.map((s, i) => (i === stringParts.length - 1 ? s : `${s}\$${i}`)).join("");
|
|
22
|
+
let localized = getLocalizedString(stringToLocalize);
|
|
23
|
+
|
|
24
|
+
args.forEach((arg, index) => {
|
|
25
|
+
localized = localized.replace("$" + index, arg);
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return localized;
|
|
29
|
+
}
|
package/src/parseFunc.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const funcRegex = /^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)*)\}$/;
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function parseFunc(func: Function) {
|
|
4
4
|
var match = func.toString().match(funcRegex);
|
|
5
5
|
if (match === null) {
|
|
6
6
|
throw new TypeError("Unable to parse function!");
|
package/src/requireNamespace.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Namespace from "./Namespace.js";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function requireNamespace(
|
|
4
4
|
root: any,
|
|
5
5
|
namespace: string | Array<string>
|
|
6
6
|
): any {
|
|
@@ -17,10 +17,6 @@ export default function requireNamespace(
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
return current;
|
|
20
|
-
} else {
|
|
21
|
-
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
22
20
|
}
|
|
23
|
-
} else {
|
|
24
|
-
throw new TypeError("Invalid type of parameter 'root'");
|
|
25
21
|
}
|
|
26
22
|
}
|
package/es/warn.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function warn(message: string, fallbackToAlert?: boolean): void;
|
package/es/warn.js
DELETED
package/src/warn.ts
DELETED