@vknext/shared 1.4.5 → 1.4.6

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.
@@ -10,6 +10,7 @@ export declare class Lang<T extends LangMap> {
10
10
  protected decodedKeys: T;
11
11
  constructor(decodedKeys: T);
12
12
  use<U extends Formatted>(key: keyof T, values?: FormatObject<U> | null | number, mode?: "raw" | "decode"): string;
13
+ protected formatTemplate(template: string, values: FormatObject<Formatted>): string;
13
14
  toggleDebug(): void;
14
15
  }
15
16
  export {};
@@ -1 +1 @@
1
- import{pluralFrom as e}from"../pluralFrom.js";class r{isDebug=!1;decodedKeys;constructor(e){this.decodedKeys=e}use(r,t={},s="decode"){if(!r)return"...";if(this.isDebug)return r;if(!(r in this.decodedKeys))return"";let i=this.decodedKeys[r];if("raw"===s)return i;if(Array.isArray(i)&&"number"==typeof t)return e(t,i,!1);if("string"==typeof i&&t&&"object"==typeof t)for(const[e,r]of i.matchAll(/\{(.*?)\}/g)){const s=t[r]||"";i=String(i).replace(e,s)}return i}toggleDebug(){this.isDebug=!this.isDebug}}export{r as Lang};
1
+ import{pluralFrom as e}from"../pluralFrom.js";class t{isDebug=!1;decodedKeys;constructor(e){this.decodedKeys=e}use(t,r={},o="decode"){if(!t)return"...";if(this.isDebug)return t;if(!(t in this.decodedKeys))return"";let s=this.decodedKeys[t];if("raw"===o)return s;if(Array.isArray(s)&&null!==r){if("number"==typeof r)return e(r,s,!1);"object"==typeof r&&(s=s.map((e=>this.formatTemplate(e,r))))}return"string"==typeof s&&r&&"object"==typeof r&&(s=this.formatTemplate(s,r)),s}formatTemplate(e,t){for(const[r,o]of e.matchAll(/\{(.*?)\}/g)){const s=t[o]||"";e=String(e).replace(r,s)}return e}toggleDebug(){this.isDebug=!this.isDebug}}export{t as Lang};
@@ -5,6 +5,6 @@ type FormatObject<U extends Formatted> = {
5
5
  };
6
6
  export declare class LangReact<T extends LangMap> extends Lang<T> {
7
7
  constructor(decodedKeys: T);
8
- use<U extends Formatted>(key: keyof T, values?: FormatObject<U> | null | number, mode?: "raw" | "decode"): string;
8
+ protected formatTemplate(template: string, values: FormatObject<Formatted>): string;
9
9
  }
10
10
  export {};
@@ -1 +1 @@
1
- import{isValidElement as r,Children as t}from"react";import{pluralFrom as e}from"../pluralFrom.js";import{Lang as o}from"./Lang.js";const i=/(\{[\d|\w]+\})/;class s extends o{constructor(r){super(r)}use(o,s={},n="decode"){if(!o)return"...";if(this.isDebug)return o;if(!(o in this.decodedKeys))return"";let u=this.decodedKeys[o];if("raw"===n)return u;if(Array.isArray(u)&&"number"==typeof s)return e(s,u,!1);if("string"==typeof u&&s&&"object"==typeof s){let e=!1;const o=(u||"").split(i).filter((r=>!!r)).map(((o,n)=>{if(o.match(i)){const i=o.slice(1,-1);let u=s[i];return r(u)?(e=!0,t.toArray(u).map((r=>({...r,key:n.toString()})))):u}return o}));return e?o:o.join("")}return u}}export{s as LangReact};
1
+ import{isValidElement as t,Children as r}from"react";import{Lang as e}from"./Lang.js";const o=/(\{[\d|\w]+\})/;class n extends e{constructor(t){super(t)}formatTemplate(e,n){let s=!1;const a=(e||"").split(o).filter((t=>!!t)).map(((e,a)=>{if(e.match(o)){const o=e.slice(1,-1);let c=n[o];return t(c)?(s=!0,r.toArray(c).map((t=>({...t,key:a.toString()})))):c}return e}));return s?a:a.join("")}}export{n as LangReact};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vknext/shared",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "vk next shared",
5
5
  "type": "module",
6
6
  "files": [