i18next 23.8.0 → 23.8.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/options.d.ts +5 -0
- package/typescript/t.d.ts +26 -16
- package/typescript/t.v4.d.ts +26 -16
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"23.8.
|
|
1
|
+
{"type":"module","version":"23.8.1"}
|
package/package.json
CHANGED
package/typescript/options.d.ts
CHANGED
package/typescript/t.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
// Type Options
|
|
14
14
|
type _ReturnObjects = TypeOptions['returnObjects'];
|
|
15
|
+
type _ReturnEmptyString = TypeOptions['returnEmptyString'];
|
|
15
16
|
type _ReturnNull = TypeOptions['returnNull'];
|
|
16
17
|
type _KeySeparator = TypeOptions['keySeparator'];
|
|
17
18
|
type _NsSeparator = TypeOptions['nsSeparator'];
|
|
@@ -157,23 +158,32 @@ type ParseTReturnPluralOrdinal<
|
|
|
157
158
|
string}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`,
|
|
158
159
|
> = Res[(KeyWithOrdinalPlural | Key) & keyof Res];
|
|
159
160
|
|
|
160
|
-
type
|
|
161
|
+
type ParseTReturnWithFallback<Key, Val> = Val extends ''
|
|
162
|
+
? _ReturnEmptyString extends true
|
|
163
|
+
? ''
|
|
164
|
+
: Key
|
|
165
|
+
: Val extends null
|
|
166
|
+
? _ReturnNull extends true
|
|
167
|
+
? null
|
|
168
|
+
: Key
|
|
169
|
+
: Val;
|
|
170
|
+
|
|
171
|
+
type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
|
|
161
172
|
Key,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
: Res[Key & keyof Res];
|
|
173
|
+
Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
|
|
174
|
+
? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
|
|
175
|
+
: // Process plurals only if count is provided inside options
|
|
176
|
+
TOpt['count'] extends number
|
|
177
|
+
? TOpt['ordinal'] extends boolean
|
|
178
|
+
? ParseTReturnPluralOrdinal<Res, Key>
|
|
179
|
+
: ParseTReturnPlural<Res, Key>
|
|
180
|
+
: // otherwise access plain key without adding plural and ordinal suffixes
|
|
181
|
+
Res extends readonly unknown[]
|
|
182
|
+
? Key extends `${infer NKey extends number}`
|
|
183
|
+
? Res[NKey]
|
|
184
|
+
: never
|
|
185
|
+
: Res[Key & keyof Res]
|
|
186
|
+
>;
|
|
177
187
|
|
|
178
188
|
type TReturnOptionalNull = _ReturnNull extends true ? null : never;
|
|
179
189
|
type TReturnOptionalObjects<TOpt extends TOptions> = _ReturnObjects extends true
|
package/typescript/t.v4.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
|
|
10
10
|
// Type Options
|
|
11
11
|
type _ReturnObjects = TypeOptions['returnObjects'];
|
|
12
|
+
type _ReturnEmptyString = TypeOptions['returnEmptyString'];
|
|
12
13
|
type _ReturnNull = TypeOptions['returnNull'];
|
|
13
14
|
type _KeySeparator = TypeOptions['keySeparator'];
|
|
14
15
|
type _NsSeparator = TypeOptions['nsSeparator'];
|
|
@@ -157,23 +158,32 @@ type ParseTReturnPluralOrdinal<
|
|
|
157
158
|
string}${_PluralSeparator}ordinal${_PluralSeparator}${PluralSuffix}`,
|
|
158
159
|
> = Res[(KeyWithOrdinalPlural | Key) & keyof Res];
|
|
159
160
|
|
|
160
|
-
type
|
|
161
|
+
type ParseTReturnWithFallback<Key, Val> = Val extends ''
|
|
162
|
+
? _ReturnEmptyString extends true
|
|
163
|
+
? ''
|
|
164
|
+
: Key
|
|
165
|
+
: Val extends null
|
|
166
|
+
? _ReturnNull extends true
|
|
167
|
+
? null
|
|
168
|
+
: Key
|
|
169
|
+
: Val;
|
|
170
|
+
|
|
171
|
+
type ParseTReturn<Key, Res, TOpt extends TOptions = {}> = ParseTReturnWithFallback<
|
|
161
172
|
Key,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
: Res[Key & keyof Res];
|
|
173
|
+
Key extends `${infer K1}${_KeySeparator}${infer RestKey}`
|
|
174
|
+
? ParseTReturn<RestKey, Res[K1 & keyof Res], TOpt>
|
|
175
|
+
: // Process plurals only if count is provided inside options
|
|
176
|
+
TOpt['count'] extends number
|
|
177
|
+
? TOpt['ordinal'] extends boolean
|
|
178
|
+
? ParseTReturnPluralOrdinal<Res, Key>
|
|
179
|
+
: ParseTReturnPlural<Res, Key>
|
|
180
|
+
: // otherwise access plain key without adding plural and ordinal suffixes
|
|
181
|
+
Res extends readonly unknown[]
|
|
182
|
+
? Key extends `${infer NKey extends number}`
|
|
183
|
+
? Res[NKey]
|
|
184
|
+
: never
|
|
185
|
+
: Res[Key & keyof Res]
|
|
186
|
+
>;
|
|
177
187
|
|
|
178
188
|
type TReturnOptionalNull = _ReturnNull extends true ? null : never;
|
|
179
189
|
type TReturnOptionalObjects<TOpt extends TOptions> = _ReturnObjects extends true
|