@koine/i18n 2.0.0-beta.188 → 2.0.0-beta.189

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.
@@ -129,16 +129,13 @@ var u = createAdapter.createGenerator("js", (e)=>{
129
129
  name: o,
130
130
  ext: "ts",
131
131
  index: !1,
132
- content: ()=>{
133
- let e = "";
134
- return e += imports.ImportsCompiler.outMany("ts", s), e += functions.FunctionsCompiler.outMany("ts", i, {
132
+ content: ()=>"" + (imports.ImportsCompiler.outMany("ts", s) + functions.FunctionsCompiler.outMany("ts", i, {
135
133
  imports: !1,
136
134
  exports: "named",
137
135
  style: "function",
138
136
  comments: !0,
139
137
  pure: !0
140
- });
141
- }
138
+ }))
142
139
  }
143
140
  };
144
141
  });
@@ -125,16 +125,13 @@ var u = createGenerator("js", (e)=>{
125
125
  name: o,
126
126
  ext: "ts",
127
127
  index: !1,
128
- content: ()=>{
129
- let e = "";
130
- return e += ImportsCompiler.outMany("ts", s), e += FunctionsCompiler.outMany("ts", i, {
128
+ content: ()=>"" + (ImportsCompiler.outMany("ts", s) + FunctionsCompiler.outMany("ts", i, {
131
129
  imports: !1,
132
130
  exports: "named",
133
131
  style: "function",
134
132
  comments: !0,
135
133
  pure: !0
136
- });
137
- }
134
+ }))
138
135
  }
139
136
  };
140
137
  });
@@ -103,16 +103,13 @@ var I = createAdapter.createGenerator("js", (t)=>{
103
103
  name: i,
104
104
  ext: "ts",
105
105
  index: !1,
106
- content: ()=>{
107
- let t = "";
108
- return t += imports.ImportsCompiler.outMany("ts", d), t += functions.FunctionsCompiler.outMany("ts", u, {
106
+ content: ()=>"" + (imports.ImportsCompiler.outMany("ts", d) + functions.FunctionsCompiler.outMany("ts", u, {
109
107
  imports: !1,
110
108
  exports: "named",
111
109
  style: "function",
112
110
  comments: !0,
113
111
  pure: !0
114
- });
115
- }
112
+ }))
116
113
  }
117
114
  };
118
115
  }(t),
@@ -99,16 +99,13 @@ var I = createGenerator("js", (t)=>{
99
99
  name: i,
100
100
  ext: "ts",
101
101
  index: !1,
102
- content: ()=>{
103
- let t = "";
104
- return t += ImportsCompiler.outMany("ts", d), t += FunctionsCompiler.outMany("ts", u, {
102
+ content: ()=>"" + (ImportsCompiler.outMany("ts", d) + FunctionsCompiler.outMany("ts", u, {
105
103
  imports: !1,
106
104
  exports: "named",
107
105
  style: "function",
108
106
  comments: !0,
109
107
  pure: !0
110
- });
111
- }
108
+ }))
112
109
  }
113
110
  };
114
111
  }(t),
@@ -1,4 +1,9 @@
1
1
  export type Options = {
2
+ /**
3
+ * A valid JavaScript object key identifier on whc
4
+ *
5
+ * @default "__i18n_locale"
6
+ */
2
7
  /**
3
8
  * - When `true` it outpus each function in a separate file with a `named` and a
4
9
  * `default` export in order to fully support SWC transforms optimization (see
@@ -16,7 +16,7 @@ import type { I18n } from "../types";
16
16
  import { getLocale } from "./getLocale";
17
17
 
18
18
  /**
19
- * **For React RSC only**
19
+ * **For React Server Components only**
20
20
  *
21
21
  * For compatibility with the vanilla _js_ implementation of this function and
22
22
  * for further customization it allows passing as first argument a custom _locale_
@@ -14,7 +14,7 @@ import type { I18n } from "../types";
14
14
  import { getLocale } from "./getLocale";
15
15
 
16
16
  /**
17
- * **For React RSC only**
17
+ * **For React Server Components only**
18
18
  *
19
19
  * For compatibility with the vanilla _js_ implementation of this function and
20
20
  * for further customization it allows passing as first argument a custom _locale_
@@ -18,7 +18,7 @@ import type { I18n } from "../types";
18
18
  import { getLocale } from "./getLocale";
19
19
 
20
20
  /**
21
- * **For React RSC only**
21
+ * **For React Server Components only**
22
22
  *
23
23
  * @param {locale} By default it uses the current locale
24
24
  */
@@ -16,7 +16,7 @@ import type { I18n } from "../types";
16
16
  import { getLocale } from "./getLocale";
17
17
 
18
18
  /**
19
- * **For React RSC only**
19
+ * **For React Server Components only**
20
20
  *
21
21
  * @param {locale} By default it uses the current locale
22
22
  */
@@ -21,7 +21,7 @@ function createServerContext<T>(
21
21
  defaultValue: T,
22
22
  onSet?: (value: T) => void,
23
23
  ): [() => T, (v: T) => void] {
24
- if (process.env.NODE_ENV !== "production") {
24
+ if (process.env.NODE_ENV === "development") {
25
25
  if (Boolean(React.useState)) {
26
26
  throw new Error("createServerContext only works in RSC");
27
27
  }
@@ -38,7 +38,7 @@ function createServerContext<T>(
38
38
  };
39
39
 
40
40
  /**
41
- * **For React RSC only**
41
+ * **For React Server Components only**
42
42
  *
43
43
  * @internal
44
44
  */
@@ -58,7 +58,7 @@ import React from "react";
58
58
  import { localeServerContext } from "../internal/localeServerContext";
59
59
 
60
60
  /**
61
- * **For React RSC only**
61
+ * **For React Server Components only**
62
62
  *
63
63
  * It gets the current locale
64
64
  */
@@ -77,7 +77,7 @@ import React from "react";
77
77
  import { localeServerContext } from "../internal/localeServerContext";
78
78
 
79
79
  /**
80
- * **For React RSC only**
80
+ * **For React Server Components only**
81
81
  *
82
82
  * It sets the current locale
83
83
  */
@@ -19,7 +19,7 @@ function createServerContext<T>(
19
19
  defaultValue: T,
20
20
  onSet?: (value: T) => void,
21
21
  ): [() => T, (v: T) => void] {
22
- if (process.env.NODE_ENV !== "production") {
22
+ if (process.env.NODE_ENV === "development") {
23
23
  if (Boolean(React.useState)) {
24
24
  throw new Error("createServerContext only works in RSC");
25
25
  }
@@ -36,7 +36,7 @@ function createServerContext<T>(
36
36
  };
37
37
 
38
38
  /**
39
- * **For React RSC only**
39
+ * **For React Server Components only**
40
40
  *
41
41
  * @internal
42
42
  */
@@ -56,7 +56,7 @@ import React from "react";
56
56
  import { localeServerContext } from "../internal/localeServerContext";
57
57
 
58
58
  /**
59
- * **For React RSC only**
59
+ * **For React Server Components only**
60
60
  *
61
61
  * It gets the current locale
62
62
  */
@@ -75,7 +75,7 @@ import React from "react";
75
75
  import { localeServerContext } from "../internal/localeServerContext";
76
76
 
77
77
  /**
78
- * **For React RSC only**
78
+ * **For React Server Components only**
79
79
  *
80
80
  * It sets the current locale
81
81
  */
@@ -16,7 +16,7 @@ createGenerator.dirs = {
16
16
  internal: "internal",
17
17
  server: "server",
18
18
  test: "test"
19
- }, createGenerator.log = (e, r, t, ...n)=>e.config.logLevel > 3 ? `\nif (process.env.NODE_ENV === "development") i18nConsole(\`${r}${t ? "~" + t : ""}:\`, ${n.join(", ")})` : "";
19
+ }, createGenerator.log = (e, r, t, ...n)=>e.config.logLevel > 3 ? `\nif (process.env.NODE_ENV === "development") i18nConsole.log.first(\`${r}${t ? "~" + t : ""}:\`, ${n.join(", ")})` : "";
20
20
 
21
21
  exports.createAdapter = createAdapter;
22
22
  exports.createGenerator = createGenerator;
@@ -14,6 +14,6 @@ createGenerator.dirs = {
14
14
  internal: "internal",
15
15
  server: "server",
16
16
  test: "test"
17
- }, createGenerator.log = (e, r, t, ...n)=>e.config.logLevel > 3 ? `\nif (process.env.NODE_ENV === "development") i18nConsole(\`${r}${t ? "~" + t : ""}:\`, ${n.join(", ")})` : "";
17
+ }, createGenerator.log = (e, r, t, ...n)=>e.config.logLevel > 3 ? `\nif (process.env.NODE_ENV === "development") i18nConsole.log.first(\`${r}${t ? "~" + t : ""}:\`, ${n.join(", ")})` : "";
18
18
 
19
19
  export { createAdapter, createGenerator };
@@ -58,11 +58,11 @@ class FunctionsCompiler {
58
58
  }
59
59
  static #u(t, e) {
60
60
  let { imports: n, name: s } = t, { opts_imports: r, opts_exports: o, opts_comments: i, opts_style: a } = e, u = r && n.length ? n.map((t)=>t.$out("ts", r)).join("\n") + "\n\n" : "";
61
- return u += this.#i(t, "ts"), u += i ? this.#r(t) : "", u += this.#o(e), u += "named" === o || "both" === o ? "export " : "", "arrow" === a ? (u += `let ${s} = ${this.#e(t, !0)} => `, u += this.#a(t, e, "ts") + ";") : "function" === a && (u += `function ${s}${this.#e(t, !0)} {`, u += this.#a(t, e, "ts") + "}"), u += "default" === o || "both" === o ? "\n\nexport default " + s + ";" : "";
61
+ return u += this.#i(t, "ts") + (i ? this.#r(t) : "") + this.#o(e) + ("named" === o || "both" === o ? "export " : ""), "arrow" === a ? u += `let ${s} = ${this.#e(t, !0)} => ` + this.#a(t, e, "ts") + ";" : "function" === a && (u += `function ${s}${this.#e(t, !0)} {` + this.#a(t, e, "ts") + "}"), u += "default" === o || "both" === o ? "\n\nexport default " + s + ";" : "";
62
62
  }
63
63
  static #c(t, e) {
64
64
  let { imports: n, name: s } = t, { opts_imports: r, opts_exports: o, opts_comments: i, opts_style: a } = e, u = r && n.length ? n.map((t)=>t.$out("cjs", r)).join("\n") + "\n\n" : "";
65
- return u += this.#i(t, "cjs"), u += i ? this.#r(t) : "", u += this.#o(e), "arrow" === a ? (u += `let ${s} = ${this.#e(t, !1)} => `, u += this.#a(t, e, "cjs") + ";") : "function" === a && (u += `function ${s}${this.#e(t, !1)} {`, u += this.#a(t, e, "cjs") + "}"), u += "named" === o || "both" === o ? `\n\nexports.${s} = ${s};` : "", u += "default" === o || "both" === o ? "\n\nmodule.exports = " + s + ";" : "";
65
+ return u += this.#i(t, "cjs") + (i ? this.#r(t) : "") + this.#o(e), "arrow" === a ? u += `let ${s} = ${this.#e(t, !1)} => ` + this.#a(t, e, "cjs") + ";" : "function" === a && (u += `function ${s}${this.#e(t, !1)} {` + this.#a(t, e, "cjs") + "}"), u += ("named" === o || "both" === o ? `\n\nexports.${s} = ${s};` : "") + ("default" === o || "both" === o ? "\n\nmodule.exports = " + s + ";" : "");
66
66
  }
67
67
  $out(t, e) {
68
68
  return FunctionsCompiler.#h(this.data, t, e);
@@ -56,11 +56,11 @@ class FunctionsCompiler {
56
56
  }
57
57
  static #u(t, e) {
58
58
  let { imports: n, name: s } = t, { opts_imports: r, opts_exports: o, opts_comments: i, opts_style: a } = e, u = r && n.length ? n.map((t)=>t.$out("ts", r)).join("\n") + "\n\n" : "";
59
- return u += this.#i(t, "ts"), u += i ? this.#r(t) : "", u += this.#o(e), u += "named" === o || "both" === o ? "export " : "", "arrow" === a ? (u += `let ${s} = ${this.#e(t, !0)} => `, u += this.#a(t, e, "ts") + ";") : "function" === a && (u += `function ${s}${this.#e(t, !0)} {`, u += this.#a(t, e, "ts") + "}"), u += "default" === o || "both" === o ? "\n\nexport default " + s + ";" : "";
59
+ return u += this.#i(t, "ts") + (i ? this.#r(t) : "") + this.#o(e) + ("named" === o || "both" === o ? "export " : ""), "arrow" === a ? u += `let ${s} = ${this.#e(t, !0)} => ` + this.#a(t, e, "ts") + ";" : "function" === a && (u += `function ${s}${this.#e(t, !0)} {` + this.#a(t, e, "ts") + "}"), u += "default" === o || "both" === o ? "\n\nexport default " + s + ";" : "";
60
60
  }
61
61
  static #c(t, e) {
62
62
  let { imports: n, name: s } = t, { opts_imports: r, opts_exports: o, opts_comments: i, opts_style: a } = e, u = r && n.length ? n.map((t)=>t.$out("cjs", r)).join("\n") + "\n\n" : "";
63
- return u += this.#i(t, "cjs"), u += i ? this.#r(t) : "", u += this.#o(e), "arrow" === a ? (u += `let ${s} = ${this.#e(t, !1)} => `, u += this.#a(t, e, "cjs") + ";") : "function" === a && (u += `function ${s}${this.#e(t, !1)} {`, u += this.#a(t, e, "cjs") + "}"), u += "named" === o || "both" === o ? `\n\nexports.${s} = ${s};` : "", u += "default" === o || "both" === o ? "\n\nmodule.exports = " + s + ";" : "";
63
+ return u += this.#i(t, "cjs") + (i ? this.#r(t) : "") + this.#o(e), "arrow" === a ? u += `let ${s} = ${this.#e(t, !1)} => ` + this.#a(t, e, "cjs") + ";" : "function" === a && (u += `function ${s}${this.#e(t, !1)} {` + this.#a(t, e, "cjs") + "}"), u += ("named" === o || "both" === o ? `\n\nexports.${s} = ${s};` : "") + ("default" === o || "both" === o ? "\n\nmodule.exports = " + s + ";" : "");
64
64
  }
65
65
  $out(t, e) {
66
66
  return FunctionsCompiler.#h(this.data, t, e);
@@ -14,16 +14,16 @@ let l = (t)=>{
14
14
  }
15
15
  return utils.objectSort(r);
16
16
  }, h = (t)=>{
17
- let e = l(t), r = "", h = "", d = [], a = 'style="border-right:1px solid grey"';
17
+ let e = l(t), r = "", h = [], d = 'style="border-right:1px solid grey"';
18
18
  for(let t in e){
19
- let r = e[t];
20
- for(let e in h += `<tr><td ${a}>${t}</td>`, r){
21
- let { characters: t, words: l, url: o } = r[e];
22
- d.includes(e) || d.push(e), h += `<td><a href="${o}">${e}</a></td><td>${l}</td><td ${a}>${t}</td>`;
19
+ let l = e[t];
20
+ for(let e in r += `<tr><td ${d}>${t}</td>`, l){
21
+ let { characters: t, words: a, url: o } = l[e];
22
+ h.includes(e) || h.push(e), r += `<td><a href="${o}">${e}</a></td><td>${a}</td><td ${d}>${t}</td>`;
23
23
  }
24
- h += "</tr>";
24
+ r += "</tr>";
25
25
  }
26
- return r += "<table><thead><tr>", r += `<th ${a}>file path</th>`, r += d.map(()=>`<th>lang</th><th>words</th><th ${a}>chars</th>`).join(""), r += `</tr></thead><tbody>${h}</tbody></table>\n`;
26
+ return `<table><thead><tr><th ${d}>file path</th>` + h.map(()=>`<th>lang</th><th>words</th><th ${d}>chars</th>`).join("") + `</tr></thead><tbody>${r}</tbody></table>\n`;
27
27
  }, d = (t, e)=>{
28
28
  let r = "";
29
29
  for(let l in t){
@@ -31,10 +31,7 @@ let l = (t)=>{
31
31
  r += `<tr><th><a href="${o}">${l}</a></th><td>${h.length}</td><td>${a}</td><td>${d}</td></tr>`;
32
32
  }
33
33
  return `<table><thead><tr><th>locale</th><th>files</th><th>words</th><th>chars</th></tr></thead><tbody>${r}</tbody></table>\n`;
34
- }, a = (t, e)=>{
35
- let r = "# Summary\n";
36
- return r += "\n### By locale\n\n", r += d(t, e), r += "\n### By file path\n\n", r += h(t);
37
- };
34
+ }, a = (t, e)=>"# Summary\n" + ("\n### By locale\n\n" + d(t, e) + "\n### By file path\n\n") + h(t);
38
35
  let generateSummary = (e, l)=>a(e, utils.objectMergeWithDefaults(data.summaryDataOptions, l));
39
36
 
40
37
  exports.generateSummary = generateSummary;
@@ -12,16 +12,16 @@ let l = (t)=>{
12
12
  }
13
13
  return objectSort(r);
14
14
  }, h = (t)=>{
15
- let e = l(t), r = "", h = "", d = [], a = 'style="border-right:1px solid grey"';
15
+ let e = l(t), r = "", h = [], d = 'style="border-right:1px solid grey"';
16
16
  for(let t in e){
17
- let r = e[t];
18
- for(let e in h += `<tr><td ${a}>${t}</td>`, r){
19
- let { characters: t, words: l, url: o } = r[e];
20
- d.includes(e) || d.push(e), h += `<td><a href="${o}">${e}</a></td><td>${l}</td><td ${a}>${t}</td>`;
17
+ let l = e[t];
18
+ for(let e in r += `<tr><td ${d}>${t}</td>`, l){
19
+ let { characters: t, words: a, url: o } = l[e];
20
+ h.includes(e) || h.push(e), r += `<td><a href="${o}">${e}</a></td><td>${a}</td><td ${d}>${t}</td>`;
21
21
  }
22
- h += "</tr>";
22
+ r += "</tr>";
23
23
  }
24
- return r += "<table><thead><tr>", r += `<th ${a}>file path</th>`, r += d.map(()=>`<th>lang</th><th>words</th><th ${a}>chars</th>`).join(""), r += `</tr></thead><tbody>${h}</tbody></table>\n`;
24
+ return `<table><thead><tr><th ${d}>file path</th>` + h.map(()=>`<th>lang</th><th>words</th><th ${d}>chars</th>`).join("") + `</tr></thead><tbody>${r}</tbody></table>\n`;
25
25
  }, d = (t, e)=>{
26
26
  let r = "";
27
27
  for(let l in t){
@@ -29,10 +29,7 @@ let l = (t)=>{
29
29
  r += `<tr><th><a href="${o}">${l}</a></th><td>${h.length}</td><td>${a}</td><td>${d}</td></tr>`;
30
30
  }
31
31
  return `<table><thead><tr><th>locale</th><th>files</th><th>words</th><th>chars</th></tr></thead><tbody>${r}</tbody></table>\n`;
32
- }, a = (t, e)=>{
33
- let r = "# Summary\n";
34
- return r += "\n### By locale\n\n", r += d(t, e), r += "\n### By file path\n\n", r += h(t);
35
- };
32
+ }, a = (t, e)=>"# Summary\n" + ("\n### By locale\n\n" + d(t, e) + "\n### By file path\n\n") + h(t);
36
33
  let generateSummary = (e, l)=>a(e, objectMergeWithDefaults(summaryDataOptions, l));
37
34
 
38
35
  export { generateSummary };
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "node": "^14.18.0 || >=16.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@koine/node": "2.0.0-beta.188",
9
- "@koine/utils": "2.0.0-beta.188",
8
+ "@koine/node": "2.0.0-beta.189",
9
+ "@koine/utils": "2.0.0-beta.189",
10
10
  "comment-json": "^4.2.4",
11
11
  "consola": "^3.2.3",
12
12
  "glob": "^11.0.0",
@@ -116,5 +116,5 @@
116
116
  "module": "./index.esm.js",
117
117
  "main": "./index.cjs.js",
118
118
  "types": "./index.esm.d.ts",
119
- "version": "2.0.0-beta.188"
119
+ "version": "2.0.0-beta.189"
120
120
  }