i18next 23.8.3 → 23.9.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.
@@ -1 +1 @@
1
- {"type":"module","version":"23.8.3"}
1
+ {"type":"module","version":"23.9.0"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next",
3
- "version": "23.8.3",
3
+ "version": "23.9.0",
4
4
  "description": "i18next internationalization framework",
5
5
  "main": "./dist/cjs/i18next.js",
6
6
  "module": "./dist/esm/i18next.js",
@@ -12,4 +12,49 @@ export type $OmitArrayKeys<Arr> = Arr extends readonly any[] ? Omit<Arr, keyof a
12
12
 
13
13
  export type $PreservedValue<Value, Fallback> = [Value] extends [never] ? Fallback : Value;
14
14
 
15
- export type $NormalizeIntoArray<T extends unknown | readonly unknown[]> = T extends readonly unknown[] ? T : [T];
15
+ export type $NormalizeIntoArray<T extends unknown | readonly unknown[]> =
16
+ T extends readonly unknown[] ? T : [T];
17
+
18
+ /**
19
+ * @typeParam T
20
+ * @example
21
+ * ```
22
+ * $UnionToIntersection<{foo: {bar: string} | {asd: boolean}}> = {foo: {bar: string} & {asd: boolean}}
23
+ * ```
24
+ *
25
+ * @see https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
26
+ */
27
+ type $UnionToIntersection<T> = (T extends unknown ? (k: T) => void : never) extends (
28
+ k: infer I,
29
+ ) => void
30
+ ? I
31
+ : never;
32
+
33
+ /**
34
+ * @typeParam TPath union of strings
35
+ * @typeParam TValue value of the record
36
+ * @example
37
+ * ```
38
+ * $StringKeyPathToRecord<'foo.bar' | 'asd'> = {foo: {bar: string} | {asd: boolean}}
39
+ * ```
40
+ */
41
+ type $StringKeyPathToRecordUnion<
42
+ TPath extends string,
43
+ TValue,
44
+ > = TPath extends `${infer TKey}.${infer Rest}`
45
+ ? { [Key in TKey]: $StringKeyPathToRecord<Rest, TValue> }
46
+ : { [Key in TPath]: TValue };
47
+
48
+ /**
49
+ * Used to intersect output of {@link $StringKeyPathToRecordUnion}
50
+ *
51
+ * @typeParam TPath union of strings
52
+ * @typeParam TValue value of the record
53
+ * @example
54
+ * ```
55
+ * $StringKeyPathToRecord<'foo.bar' | 'asd'> = {foo: {bar: string} & {asd: boolean}}
56
+ * ```
57
+ */
58
+ export type $StringKeyPathToRecord<TPath extends string, TValue> = $UnionToIntersection<
59
+ $StringKeyPathToRecordUnion<TPath, TValue>
60
+ >;
package/typescript/t.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { $OmitArrayKeys, $PreservedValue, $Dictionary, $SpecialObject } from './helpers.js';
1
+ import type {
2
+ $OmitArrayKeys,
3
+ $PreservedValue,
4
+ $Dictionary,
5
+ $SpecialObject,
6
+ $StringKeyPathToRecord,
7
+ } from './helpers.js';
2
8
  import type {
3
9
  TypeOptions,
4
10
  Namespace,
@@ -140,9 +146,10 @@ type ParseInterpolationValues<Ret> =
140
146
  | (Value extends `${infer ActualValue},${string}` ? ActualValue : Value)
141
147
  | ParseInterpolationValues<Rest>
142
148
  : never;
143
- type InterpolationMap<Ret> = Record<
144
- $PreservedValue<ParseInterpolationValues<Ret>, string>,
145
- unknown
149
+
150
+ type InterpolationMap<Ret> = $PreservedValue<
151
+ $StringKeyPathToRecord<ParseInterpolationValues<Ret>, unknown>,
152
+ Record<string, unknown>
146
153
  >;
147
154
 
148
155
  type ParseTReturnPlural<
@@ -1,4 +1,10 @@
1
- import type { $OmitArrayKeys, $PreservedValue, $Dictionary, $SpecialObject } from './helpers.js';
1
+ import type {
2
+ $OmitArrayKeys,
3
+ $PreservedValue,
4
+ $Dictionary,
5
+ $SpecialObject,
6
+ $StringKeyPathToRecord,
7
+ } from './helpers.js';
2
8
  import type {
3
9
  TypeOptions,
4
10
  Namespace,
@@ -7,6 +13,9 @@ import type {
7
13
  TOptions,
8
14
  } from './options.js';
9
15
 
16
+ /** @todo consider to replace {} with Record<string, never> */
17
+ /* eslint @typescript-eslint/ban-types: ['error', { types: { "{}": false } }] */
18
+
10
19
  // Type Options
11
20
  type _ReturnObjects = TypeOptions['returnObjects'];
12
21
  type _ReturnEmptyString = TypeOptions['returnEmptyString'];
@@ -21,9 +30,6 @@ type _JSONFormat = TypeOptions['jsonFormat'];
21
30
  type _InterpolationPrefix = TypeOptions['interpolationPrefix'];
22
31
  type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
23
32
 
24
- /** @todo consider to replace {} with Record<string, never> */
25
- /* eslint @typescript-eslint/ban-types: ['error', { types: { "{}": false } }] */
26
-
27
33
  type $IsResourcesDefined = [keyof _Resources] extends [never] ? false : true;
28
34
  type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends true
29
35
  ? Value
@@ -140,9 +146,10 @@ type ParseInterpolationValues<Ret> =
140
146
  | (Value extends `${infer ActualValue},${string}` ? ActualValue : Value)
141
147
  | ParseInterpolationValues<Rest>
142
148
  : never;
143
- type InterpolationMap<Ret> = Record<
144
- $PreservedValue<ParseInterpolationValues<Ret>, string>,
145
- unknown
149
+
150
+ type InterpolationMap<Ret> = $PreservedValue<
151
+ $StringKeyPathToRecord<ParseInterpolationValues<Ret>, unknown>,
152
+ Record<string, unknown>
146
153
  >;
147
154
 
148
155
  type ParseTReturnPlural<