kotori 5.0.4 → 5.0.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/dist/index.cjs CHANGED
@@ -16,11 +16,7 @@ const kotori = (props) => {
16
16
  listeners.delete(listener);
17
17
  };
18
18
  };
19
- const t = (dict, ...args) => {
20
- let locale = dict().translation[language] || "";
21
- for (const objKey in args[0]) locale = locale.replace(new RegExp(`\\{\\{\\s*${objKey}\\s*\\}\\}`, "g"), () => String(args[0]?.[objKey]));
22
- return locale;
23
- };
19
+ const t = (dict, ...args) => (dict().translation[language] || "").replace(/\{\{\s*([\w-]+)\s*\}\}/g, (_, key) => String(args[0]?.[key]));
24
20
  return {
25
21
  setLanguage,
26
22
  t,
package/dist/index.d.cts CHANGED
@@ -16,7 +16,7 @@ declare const kotori: <const PrimaryTag extends AllTags, const SecondaryTags ext
16
16
  t: <Dict extends () => Readonly<{
17
17
  translation: Record<PrimaryTag | SecondaryTags, string>;
18
18
  [_args]?: Record<string, string | number>;
19
- }>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string | Record<PrimaryTag | SecondaryTags, string>[PrimaryTag | SecondaryTags];
19
+ }>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string;
20
20
  dict: <const PrimaryString extends string, const SecondaryObject extends { [Key in SecondaryTags]: ExtractVariables<PrimaryString> extends infer PrimaryVariables ? ExtractVariables<SecondaryObject[Key] & string> extends infer SecondaryVariables ? PrimaryVariables[] extends SecondaryVariables[] ? SecondaryVariables[] extends PrimaryVariables[] ? SecondaryObject[Key] : "variables not match!" : "variables not match!!" : never : never }>(translation: { [Key in PrimaryTag]: PrimaryString } & SecondaryObject) => <const ArgsType extends Record<ExtractVariables<PrimaryString>, string | number> = Record<ExtractVariables<PrimaryString>, string | number>>() => Readonly<{
21
21
  translation: typeof translation;
22
22
  [_args]?: ArgsType;
package/dist/index.d.mts CHANGED
@@ -16,7 +16,7 @@ declare const kotori: <const PrimaryTag extends AllTags, const SecondaryTags ext
16
16
  t: <Dict extends () => Readonly<{
17
17
  translation: Record<PrimaryTag | SecondaryTags, string>;
18
18
  [_args]?: Record<string, string | number>;
19
- }>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string | Record<PrimaryTag | SecondaryTags, string>[PrimaryTag | SecondaryTags];
19
+ }>>(dict: Dict, ...args: keyof NonNullable<ReturnType<Dict>[typeof _args]> extends never ? [] : [NonNullable<ReturnType<Dict>[typeof _args]>]) => string;
20
20
  dict: <const PrimaryString extends string, const SecondaryObject extends { [Key in SecondaryTags]: ExtractVariables<PrimaryString> extends infer PrimaryVariables ? ExtractVariables<SecondaryObject[Key] & string> extends infer SecondaryVariables ? PrimaryVariables[] extends SecondaryVariables[] ? SecondaryVariables[] extends PrimaryVariables[] ? SecondaryObject[Key] : "variables not match!" : "variables not match!!" : never : never }>(translation: { [Key in PrimaryTag]: PrimaryString } & SecondaryObject) => <const ArgsType extends Record<ExtractVariables<PrimaryString>, string | number> = Record<ExtractVariables<PrimaryString>, string | number>>() => Readonly<{
21
21
  translation: typeof translation;
22
22
  [_args]?: ArgsType;
package/dist/index.mjs CHANGED
@@ -15,11 +15,7 @@ const kotori = (props) => {
15
15
  listeners.delete(listener);
16
16
  };
17
17
  };
18
- const t = (dict, ...args) => {
19
- let locale = dict().translation[language] || "";
20
- for (const objKey in args[0]) locale = locale.replace(new RegExp(`\\{\\{\\s*${objKey}\\s*\\}\\}`, "g"), () => String(args[0]?.[objKey]));
21
- return locale;
22
- };
18
+ const t = (dict, ...args) => (dict().translation[language] || "").replace(/\{\{\s*([\w-]+)\s*\}\}/g, (_, key) => String(args[0]?.[key]));
23
19
  return {
24
20
  setLanguage,
25
21
  t,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kotori",
3
3
  "description": "Strongly-typed and composable internationalization library for React",
4
- "version": "5.0.4",
4
+ "version": "5.0.5",
5
5
  "scripts": {
6
6
  "setup": "rm -rf node_modules && npm i && git init && husky",
7
7
  "prepublishOnly": "npm i && npx tsc && npm run build",