@next-box/i18n 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@next-box/i18n",
3
3
  "description": "A type-safe content resolver with content path auto-complete and value preview.",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/next-box",
@@ -54,7 +54,7 @@
54
54
  "callsites": "^4.2.0",
55
55
  "markdown-to-jsx": "^9.10.4",
56
56
  "type-fest": "^5.10.0",
57
- "zcb": "^0.3.10"
57
+ "zcb": "^0.3.13"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": "<20",
package/src/main.ts CHANGED
@@ -1,22 +1,23 @@
1
- import { type Get } from 'type-fest';
2
- import { type AnyRecord, type Path, createConfigReader } from 'zcb';
1
+ import { type AnyRecord, createConfigReader } from 'zcb';
3
2
  import { type CreateI18nResult } from '#types.ts';
4
3
 
5
4
  export const createI18n = <U extends object>(i18n: U): CreateI18nResult<U> => {
6
5
  const reader = createConfigReader<U>(i18n);
7
6
 
7
+ const tt: CreateI18nResult<U>['tt'] = (path, ...variables) => {
8
+ const result = reader.read(path, ...variables);
9
+
10
+ if (result === undefined) {
11
+ throw new Error(`Path "${String(path)}" did not resolve to a value`);
12
+ }
13
+
14
+ return result;
15
+ };
16
+
8
17
  return {
9
18
  // @ts-expect-error intentionally ignoring the type checking here as
10
19
  // function is supposed to be untyped.
11
20
  t: (key: string, variables?: AnyRecord): string | undefined => reader.read(key, variables),
12
- tt: <P extends Path<U>>(path: P, variables?: AnyRecord): Get<U, P> => {
13
- const result = reader.read(path, variables);
14
-
15
- if (result === undefined) {
16
- throw new Error(`Path "${String(path)}" did not resolve to a value`);
17
- }
18
-
19
- return result;
20
- },
21
+ tt,
21
22
  };
22
23
  };