i18next 23.14.0 → 23.15.1
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/esm/package.json +1 -1
- package/package.json +1 -1
- package/typescript/helpers.d.ts +8 -0
- package/typescript/options.d.ts +10 -0
- package/typescript/t.d.ts +28 -4
- package/typescript/t.v4.d.ts +17 -1
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"23.
|
|
1
|
+
{"type":"module","version":"23.15.1"}
|
package/package.json
CHANGED
package/typescript/helpers.d.ts
CHANGED
|
@@ -58,3 +58,11 @@ type $StringKeyPathToRecordUnion<
|
|
|
58
58
|
export type $StringKeyPathToRecord<TPath extends string, TValue> = $UnionToIntersection<
|
|
59
59
|
$StringKeyPathToRecordUnion<TPath, TValue>
|
|
60
60
|
>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* We could use NoInfer typescript build-in utility,
|
|
64
|
+
* however this project still supports ts < 5.4.
|
|
65
|
+
*
|
|
66
|
+
* @see https://github.com/millsp/ts-toolbelt/blob/master/sources/Function/NoInfer.ts
|
|
67
|
+
*/
|
|
68
|
+
export type $NoInfer<A> = [A][A extends any ? 0 : never];
|
package/typescript/options.d.ts
CHANGED
|
@@ -106,6 +106,16 @@ export type TypeOptions = $MergeBy<
|
|
|
106
106
|
* Suffix for interpolation
|
|
107
107
|
*/
|
|
108
108
|
interpolationSuffix: '}}';
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Prefix for unescaped interpolation
|
|
112
|
+
*/
|
|
113
|
+
unescapePrefix: '-';
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Suffix for unescaped interpolation
|
|
117
|
+
*/
|
|
118
|
+
unescapeSuffix: '';
|
|
109
119
|
},
|
|
110
120
|
CustomTypeOptions
|
|
111
121
|
>;
|
package/typescript/t.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
$Dictionary,
|
|
5
5
|
$SpecialObject,
|
|
6
6
|
$StringKeyPathToRecord,
|
|
7
|
+
$NoInfer,
|
|
7
8
|
} from './helpers.js';
|
|
8
9
|
import type {
|
|
9
10
|
TypeOptions,
|
|
@@ -29,6 +30,8 @@ type _Resources = TypeOptions['resources'];
|
|
|
29
30
|
type _JSONFormat = TypeOptions['jsonFormat'];
|
|
30
31
|
type _InterpolationPrefix = TypeOptions['interpolationPrefix'];
|
|
31
32
|
type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
|
|
33
|
+
type _UnescapePrefix = TypeOptions['unescapePrefix'];
|
|
34
|
+
type _UnescapeSuffix = TypeOptions['unescapeSuffix'];
|
|
32
35
|
|
|
33
36
|
type $IsResourcesDefined = [keyof _Resources] extends [never] ? false : true;
|
|
34
37
|
type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends true
|
|
@@ -53,6 +56,14 @@ type WithOrWithoutPlural<Key> = _JSONFormat extends 'v4' | 'v3'
|
|
|
53
56
|
type JoinKeys<K1, K2> = `${K1 & string}${_KeySeparator}${K2 & string}`;
|
|
54
57
|
type AppendNamespace<Ns, Keys> = `${Ns & string}${_NsSeparator}${Keys & string}`;
|
|
55
58
|
|
|
59
|
+
type TrimSpaces<T extends string, Acc extends string = ''> = T extends `${infer Char}${infer Rest}`
|
|
60
|
+
? Char extends ' '
|
|
61
|
+
? TrimSpaces<Rest, Acc>
|
|
62
|
+
: TrimSpaces<Rest, `${Acc}${Char}`>
|
|
63
|
+
: T extends ''
|
|
64
|
+
? Acc
|
|
65
|
+
: never;
|
|
66
|
+
|
|
56
67
|
/** ****************************************************
|
|
57
68
|
* Build all keys and key prefixes based on Resources *
|
|
58
69
|
***************************************************** */
|
|
@@ -141,10 +152,16 @@ export type ParseKeys<
|
|
|
141
152
|
/** *******************************************************
|
|
142
153
|
* Parse t function return type and interpolation values *
|
|
143
154
|
******************************************************** */
|
|
155
|
+
type ParseActualValue<Ret> = Ret extends `${_UnescapePrefix}${infer ActualValue}${_UnescapeSuffix}`
|
|
156
|
+
? TrimSpaces<ActualValue>
|
|
157
|
+
: Ret;
|
|
158
|
+
|
|
144
159
|
type ParseInterpolationValues<Ret> =
|
|
145
160
|
Ret extends `${string}${_InterpolationPrefix}${infer Value}${_InterpolationSuffix}${infer Rest}`
|
|
146
161
|
?
|
|
147
|
-
| (Value extends `${infer ActualValue},${string}`
|
|
162
|
+
| (Value extends `${infer ActualValue},${string}`
|
|
163
|
+
? ParseActualValue<ActualValue>
|
|
164
|
+
: ParseActualValue<Value>)
|
|
148
165
|
| ParseInterpolationValues<Rest>
|
|
149
166
|
: never;
|
|
150
167
|
|
|
@@ -244,6 +261,12 @@ export type TFunctionDetailedResult<T = string, TOpt extends TOptions = {}> = {
|
|
|
244
261
|
usedParams: InterpolationMap<T> & { count?: TOpt['count'] };
|
|
245
262
|
};
|
|
246
263
|
|
|
264
|
+
type TFunctionProcessReturnValue<Ret, DefaultValue> = Ret extends string | $SpecialObject | null
|
|
265
|
+
? Ret
|
|
266
|
+
: [DefaultValue] extends [never]
|
|
267
|
+
? Ret
|
|
268
|
+
: DefaultValue;
|
|
269
|
+
|
|
247
270
|
type TFunctionReturnOptionalDetails<Ret, TOpt extends TOptions> = TOpt['returnDetails'] extends true
|
|
248
271
|
? TFunctionDetailedResult<Ret, TOpt>
|
|
249
272
|
: Ret;
|
|
@@ -262,12 +285,13 @@ export interface TFunction<Ns extends Namespace = DefaultNamespace, KPrefix = un
|
|
|
262
285
|
const TOpt extends TOptions,
|
|
263
286
|
Ret extends TFunctionReturn<Ns, AppendKeyPrefix<Key, KPrefix>, TOpt>,
|
|
264
287
|
const ActualOptions extends TOpt & InterpolationMap<Ret> = TOpt & InterpolationMap<Ret>,
|
|
288
|
+
DefaultValue extends string = never,
|
|
265
289
|
>(
|
|
266
290
|
...args:
|
|
267
291
|
| [key: Key | Key[], options?: ActualOptions]
|
|
268
|
-
| [key: string | string[], options: TOpt & $Dictionary & { defaultValue:
|
|
269
|
-
| [key: string | string[], defaultValue:
|
|
270
|
-
): TFunctionReturnOptionalDetails<Ret
|
|
292
|
+
| [key: string | string[], options: TOpt & $Dictionary & { defaultValue: DefaultValue }]
|
|
293
|
+
| [key: string | string[], defaultValue: DefaultValue, options?: TOpt & $Dictionary]
|
|
294
|
+
): TFunctionReturnOptionalDetails<TFunctionProcessReturnValue<$NoInfer<Ret>, DefaultValue>, TOpt>;
|
|
271
295
|
}
|
|
272
296
|
|
|
273
297
|
export type KeyPrefix<Ns extends Namespace> = ResourceKeys<true>[$FirstNamespace<Ns>] | undefined;
|
package/typescript/t.v4.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ type _Resources = TypeOptions['resources'];
|
|
|
29
29
|
type _JSONFormat = TypeOptions['jsonFormat'];
|
|
30
30
|
type _InterpolationPrefix = TypeOptions['interpolationPrefix'];
|
|
31
31
|
type _InterpolationSuffix = TypeOptions['interpolationSuffix'];
|
|
32
|
+
type _UnescapePrefix = TypeOptions['unescapePrefix'];
|
|
33
|
+
type _UnescapeSuffix = TypeOptions['unescapeSuffix'];
|
|
32
34
|
|
|
33
35
|
type $IsResourcesDefined = [keyof _Resources] extends [never] ? false : true;
|
|
34
36
|
type $ValueIfResourcesDefined<Value, Fallback> = $IsResourcesDefined extends true
|
|
@@ -53,6 +55,14 @@ type WithOrWithoutPlural<Key> = _JSONFormat extends 'v4' | 'v3'
|
|
|
53
55
|
type JoinKeys<K1, K2> = `${K1 & string}${_KeySeparator}${K2 & string}`;
|
|
54
56
|
type AppendNamespace<Ns, Keys> = `${Ns & string}${_NsSeparator}${Keys & string}`;
|
|
55
57
|
|
|
58
|
+
type TrimSpaces<T extends string, Acc extends string = ''> = T extends `${infer Char}${infer Rest}`
|
|
59
|
+
? Char extends ' '
|
|
60
|
+
? TrimSpaces<Rest, Acc>
|
|
61
|
+
: TrimSpaces<Rest, `${Acc}${Char}`>
|
|
62
|
+
: T extends ''
|
|
63
|
+
? Acc
|
|
64
|
+
: never;
|
|
65
|
+
|
|
56
66
|
/** ****************************************************
|
|
57
67
|
* Build all keys and key prefixes based on Resources *
|
|
58
68
|
***************************************************** */
|
|
@@ -140,10 +150,16 @@ export type ParseKeys<
|
|
|
140
150
|
/** *******************************************************
|
|
141
151
|
* Parse t function return type and interpolation values *
|
|
142
152
|
******************************************************** */
|
|
153
|
+
type ParseActualValue<Ret> = Ret extends `${_UnescapePrefix}${infer ActualValue}${_UnescapeSuffix}`
|
|
154
|
+
? TrimSpaces<ActualValue>
|
|
155
|
+
: Ret;
|
|
156
|
+
|
|
143
157
|
type ParseInterpolationValues<Ret> =
|
|
144
158
|
Ret extends `${string}${_InterpolationPrefix}${infer Value}${_InterpolationSuffix}${infer Rest}`
|
|
145
159
|
?
|
|
146
|
-
| (Value extends `${infer ActualValue},${string}`
|
|
160
|
+
| (Value extends `${infer ActualValue},${string}`
|
|
161
|
+
? ParseActualValue<ActualValue>
|
|
162
|
+
: ParseActualValue<Value>)
|
|
147
163
|
| ParseInterpolationValues<Rest>
|
|
148
164
|
: never;
|
|
149
165
|
|