langsys-js-typescript 0.6.4 → 0.6.5
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/CHANGELOG.md +8 -0
- package/README.md +26 -8
- package/dist/index.js +34 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
import { IntlMessageFormat } from 'intl-messageformat';
|
|
2
2
|
|
|
3
|
+
// src/logger.ts
|
|
4
|
+
var STYLES = {
|
|
5
|
+
log: "display:inline-block;background:rgb(239,239,244);color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
|
|
6
|
+
warn: "display:inline-block;background:gold;color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
|
|
7
|
+
error: "display:inline-block;background:#e0005a;color:#fff;font-weight:bold;padding:3px 7px;border-radius:3px"
|
|
8
|
+
};
|
|
9
|
+
var supportsStyle = typeof window !== "undefined";
|
|
10
|
+
function emit(level, label, args) {
|
|
11
|
+
if (supportsStyle) {
|
|
12
|
+
console[level](`%c${label}`, STYLES[level], ...args);
|
|
13
|
+
} else {
|
|
14
|
+
console[level](`[${label}]`, ...args);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var Logger = class {
|
|
18
|
+
constructor(debugEnabled = false) {
|
|
19
|
+
this.debugEnabled = debugEnabled;
|
|
20
|
+
}
|
|
21
|
+
log(...args) {
|
|
22
|
+
if (!this.debugEnabled) return;
|
|
23
|
+
emit("log", "Langsys Debug", args);
|
|
24
|
+
}
|
|
25
|
+
warn(...args) {
|
|
26
|
+
emit("warn", "Langsys Warning", args);
|
|
27
|
+
}
|
|
28
|
+
error(...args) {
|
|
29
|
+
emit("error", "Langsys Error", args);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var logger = new Logger(false);
|
|
33
|
+
|
|
3
34
|
// src/locale.ts
|
|
4
35
|
function canonicalizeLocale(locale) {
|
|
5
36
|
if (!locale || typeof locale !== "string") return locale;
|
|
@@ -8,6 +39,9 @@ function canonicalizeLocale(locale) {
|
|
|
8
39
|
const [canonical] = Intl.getCanonicalLocales(cleaned);
|
|
9
40
|
return canonical ?? cleaned;
|
|
10
41
|
} catch {
|
|
42
|
+
if (logger.debugEnabled) logger.warn(
|
|
43
|
+
`"${locale}" is not a valid BCP 47 locale tag. Falling back to best-effort casing, which will very likely miss the catalog and render base language with no other symptom.`
|
|
44
|
+
);
|
|
11
45
|
return cleaned.split("-").map((part, i) => {
|
|
12
46
|
if (i === 0) return part.toLowerCase();
|
|
13
47
|
if (part.length === 4) return part[0].toUpperCase() + part.slice(1).toLowerCase();
|
|
@@ -51,37 +85,6 @@ function getValue(signal) {
|
|
|
51
85
|
return signal.get();
|
|
52
86
|
}
|
|
53
87
|
|
|
54
|
-
// src/logger.ts
|
|
55
|
-
var STYLES = {
|
|
56
|
-
log: "display:inline-block;background:rgb(239,239,244);color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
|
|
57
|
-
warn: "display:inline-block;background:gold;color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
|
|
58
|
-
error: "display:inline-block;background:#e0005a;color:#fff;font-weight:bold;padding:3px 7px;border-radius:3px"
|
|
59
|
-
};
|
|
60
|
-
var supportsStyle = typeof window !== "undefined";
|
|
61
|
-
function emit(level, label, args) {
|
|
62
|
-
if (supportsStyle) {
|
|
63
|
-
console[level](`%c${label}`, STYLES[level], ...args);
|
|
64
|
-
} else {
|
|
65
|
-
console[level](`[${label}]`, ...args);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
var Logger = class {
|
|
69
|
-
constructor(debugEnabled = false) {
|
|
70
|
-
this.debugEnabled = debugEnabled;
|
|
71
|
-
}
|
|
72
|
-
log(...args) {
|
|
73
|
-
if (!this.debugEnabled) return;
|
|
74
|
-
emit("log", "Langsys Debug", args);
|
|
75
|
-
}
|
|
76
|
-
warn(...args) {
|
|
77
|
-
emit("warn", "Langsys Warning", args);
|
|
78
|
-
}
|
|
79
|
-
error(...args) {
|
|
80
|
-
emit("error", "Langsys Error", args);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var logger = new Logger(false);
|
|
84
|
-
|
|
85
88
|
// src/api.ts
|
|
86
89
|
var LangsysAppAPIClass = class {
|
|
87
90
|
constructor() {
|