zustic 1.0.9 → 1.1.0

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.
@@ -0,0 +1,39 @@
1
+ interface I18nParams<T, L> {
2
+ initialLan: L;
3
+ resource: (lan: L) => Promise<T> | T;
4
+ }
5
+
6
+ /**
7
+ * Recursively gets all nested keys from object using dot notation.
8
+ * Safely handles deep nesting without infinite recursion.
9
+ */
10
+ type Join<K extends string | number, P extends string | number> =
11
+ `${K}${'' extends P ? '' : `.${P}` }`;
12
+
13
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
14
+
15
+ type NestedKeys<T, D extends number = 9> =
16
+ D extends never ? never :
17
+ T extends object
18
+ ? {
19
+ [K in keyof T]-?: K extends string
20
+ ? T[K] extends (infer U)[]
21
+ ? K
22
+ : T[K] extends object
23
+ ? K | Join<K, NestedKeys<T[K], Prev[D]>>
24
+ : K
25
+ : never
26
+ }[keyof T & string]
27
+ : never;
28
+
29
+ type TranslationKey<T> = NestedKeys<T> & string;
30
+
31
+ declare function create<T = any, L = any>(params: I18nParams<T, L>): () => {
32
+ t: (key: TranslationKey<T>) => string;
33
+ lan: L;
34
+ updateTranslation: (lang: L) => void;
35
+ isUpdating: boolean;
36
+ isInitialLoading: boolean;
37
+ };
38
+
39
+ export { create };
@@ -0,0 +1,39 @@
1
+ interface I18nParams<T, L> {
2
+ initialLan: L;
3
+ resource: (lan: L) => Promise<T> | T;
4
+ }
5
+
6
+ /**
7
+ * Recursively gets all nested keys from object using dot notation.
8
+ * Safely handles deep nesting without infinite recursion.
9
+ */
10
+ type Join<K extends string | number, P extends string | number> =
11
+ `${K}${'' extends P ? '' : `.${P}` }`;
12
+
13
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
14
+
15
+ type NestedKeys<T, D extends number = 9> =
16
+ D extends never ? never :
17
+ T extends object
18
+ ? {
19
+ [K in keyof T]-?: K extends string
20
+ ? T[K] extends (infer U)[]
21
+ ? K
22
+ : T[K] extends object
23
+ ? K | Join<K, NestedKeys<T[K], Prev[D]>>
24
+ : K
25
+ : never
26
+ }[keyof T & string]
27
+ : never;
28
+
29
+ type TranslationKey<T> = NestedKeys<T> & string;
30
+
31
+ declare function create<T = any, L = any>(params: I18nParams<T, L>): () => {
32
+ t: (key: TranslationKey<T>) => string;
33
+ lan: L;
34
+ updateTranslation: (lang: L) => void;
35
+ isUpdating: boolean;
36
+ isInitialLoading: boolean;
37
+ };
38
+
39
+ export { create };
@@ -0,0 +1 @@
1
+ "use strict";"use client";var c=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var M=(e,a)=>{for(var t in a)c(e,t,{get:a[t],enumerable:!0})},x=(e,a,t,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of h(a))!w.call(e,i)&&i!==t&&c(e,i,{get:()=>a[i],enumerable:!(n=U(a,i))||n.enumerable});return e};var b=e=>x(c({},"__esModule",{value:!0}),e);var C={};M(C,{create:()=>E});module.exports=b(C);var m=require("react");function S(e,a=[]){let t,n=[],i=r=>{let s=typeof r=="function"?r(t):r;t={...t,...s},n.forEach(d=>d())},l=()=>t,u=v(i,l,a);t=e(u,l);let o=r=>(n.push(r),()=>{n=n.filter(s=>s!==r)});return(r=s=>s)=>(0,m.useSyncExternalStore)(o,()=>r(t))}var v=(e,a,t)=>!t||t.length===0?e:t.reduceRight((n,i)=>i(e,a)(n),e);var y=require("react");function E(e){let{resource:a,initialLan:t}=e,n=0,i=S((l,u)=>({lan:t,data:null,isUpdating:!1,isInitialLoading:!0,async load(o){let r=++n,s=u().data===null;l({isUpdating:!s,isInitialLoading:s});let d=await Promise.resolve(a(o));r===n&&l({data:d,isUpdating:!1,isInitialLoading:!1})},update(o){l({lan:o})}}));return function(){let{lan:u,data:o,update:r,isUpdating:s,isInitialLoading:d,load:L}=i();(0,y.useEffect)(()=>{L(u)},[u]);function g(p){var f;return!o||d?"":(f=p.split(".").reduce((T,I)=>T==null?void 0:T[I],o))!=null?f:p}function P(p){r(p)}return{t:g,lan:u,updateTranslation:P,isUpdating:s,isInitialLoading:d}}}0&&(module.exports={create});
@@ -0,0 +1 @@
1
+ "use client";import{a as d}from"../chunk-RXPCG2VZ.mjs";import{useEffect as I}from"react";function S(p){let{resource:f,initialLan:L}=p,l=0,T=d((a,n)=>({lan:L,data:null,isUpdating:!1,isInitialLoading:!0,async load(t){let s=++l,i=n().data===null;a({isUpdating:!i,isInitialLoading:i});let e=await Promise.resolve(f(t));s===l&&a({data:e,isUpdating:!1,isInitialLoading:!1})},update(t){a({lan:t})}}));return function(){let{lan:n,data:t,update:s,isUpdating:i,isInitialLoading:e,load:c}=T();I(()=>{c(n)},[n]);function g(r){var u;return!t||e?"":(u=r.split(".").reduce((o,y)=>o==null?void 0:o[y],t))!=null?u:r}function m(r){s(r)}return{t:g,lan:n,updateTranslation:m,isUpdating:i,isInitialLoading:e}}}export{S as create};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zustic",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "A fast, minimal state management solution for React ecosystems. Works seamlessly with React, Next.js, and React Native, offering predictable state updates with a tiny footprint.",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -16,6 +16,11 @@
16
16
  "types": "./dist/query/index.d.ts",
17
17
  "import": "./dist/query/index.mjs",
18
18
  "require": "./dist/query/index.js"
19
+ },
20
+ "./i18n": {
21
+ "types": "./dist/i18n/index.d.ts",
22
+ "import": "./dist/i18n/index.mjs",
23
+ "require": "./dist/i18n/index.js"
19
24
  }
20
25
  },
21
26
  "directories": {