@tolki/types 1.10.0 → 1.12.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.
- package/package.json +1 -1
- package/src/lang.d.ts +23 -0
- package/src/objects.d.ts +1 -1
- package/src/strings.d.ts +26 -0
package/package.json
CHANGED
package/src/lang.d.ts
CHANGED
|
@@ -233,6 +233,26 @@ type LangCountable =
|
|
|
233
233
|
/** A number, or a value whose count is the number. */
|
|
234
234
|
type ChoiceNumber = number | LangCountable;
|
|
235
235
|
|
|
236
|
+
/** What `import()` answers for a locale's JSON file: a module namespace whose default export is the lines. */
|
|
237
|
+
type LocaleModule = { readonly default: LocaleLines };
|
|
238
|
+
|
|
239
|
+
/** Fetches one locale's lines, at once or later; a file imported as a module is unwrapped. */
|
|
240
|
+
type LocaleLinesLoader = (
|
|
241
|
+
locale: string,
|
|
242
|
+
) => LocaleLines | LocaleModule | Promise<LocaleLines | LocaleModule>;
|
|
243
|
+
|
|
244
|
+
/** What `createLang()` is built from. */
|
|
245
|
+
interface LangOptions<TLines extends LangLines = LangLines> {
|
|
246
|
+
/** The locale to start in. */
|
|
247
|
+
readonly locale: string;
|
|
248
|
+
/** The locale a lookup falls back to. */
|
|
249
|
+
readonly fallback?: string | null;
|
|
250
|
+
/** The lines already at hand, one object per locale. */
|
|
251
|
+
readonly lines?: TLines;
|
|
252
|
+
/** Fetches a locale's lines when it is first needed. */
|
|
253
|
+
readonly load?: LocaleLinesLoader;
|
|
254
|
+
}
|
|
255
|
+
|
|
236
256
|
// An export list keeps the helpers above private: a .d.ts module without one exports every declaration.
|
|
237
257
|
export type {
|
|
238
258
|
ChoiceNumber,
|
|
@@ -240,8 +260,11 @@ export type {
|
|
|
240
260
|
LangGroup,
|
|
241
261
|
LangInputValue,
|
|
242
262
|
LangLines,
|
|
263
|
+
LangOptions,
|
|
243
264
|
LangValue,
|
|
244
265
|
LocaleLines,
|
|
266
|
+
LocaleLinesLoader,
|
|
267
|
+
LocaleModule,
|
|
245
268
|
LocalesResolver,
|
|
246
269
|
MissingKeyHandler,
|
|
247
270
|
Replacements,
|
package/src/objects.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type NonObjectItems =
|
|
|
26
26
|
/**
|
|
27
27
|
* `NonObjectItems` without the Map, for an obj helper's empty-result row, so `Map | string[]` is not typed as empty.
|
|
28
28
|
*
|
|
29
|
-
* @remarks A Map keyed by `
|
|
29
|
+
* @remarks A Map keyed by `any` or an object type still fits the `WeakMap` member, so a union
|
|
30
30
|
* holding it beside another of these values is typed as empty, though its Map is walked.
|
|
31
31
|
*/
|
|
32
32
|
export type NonKeyedItems = Exclude<
|
package/src/strings.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
1
|
export interface CanBeEscapedWhenCastToString {
|
|
2
2
|
escapeWhenCastToString(escape: boolean): this;
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A subject Str's replace() and remove() accept: a string, strings in a list, Map, collection or iterable,
|
|
7
|
+
* or an object of strings.
|
|
8
|
+
*/
|
|
9
|
+
export type StringSubject<TSubject> =
|
|
10
|
+
| string
|
|
11
|
+
| Iterable<string>
|
|
12
|
+
| ReadonlyMap<unknown, string>
|
|
13
|
+
| (object & { readonly [K in keyof TSubject]: string });
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What replace() and remove() return for a subject: a string for a string, else the subject's shape holding
|
|
17
|
+
* strings.
|
|
18
|
+
*/
|
|
19
|
+
export type StringSubjectResult<TSubject> = TSubject extends string
|
|
20
|
+
? string
|
|
21
|
+
: TSubject extends ReadonlyMap<infer TKey, unknown>
|
|
22
|
+
? Map<TKey, string>
|
|
23
|
+
: TSubject extends readonly unknown[]
|
|
24
|
+
? string[]
|
|
25
|
+
: TSubject extends { all(): infer TItems }
|
|
26
|
+
? StringSubjectResult<TItems>
|
|
27
|
+
: TSubject extends Iterable<unknown>
|
|
28
|
+
? string[]
|
|
29
|
+
: { [K in keyof TSubject]: string };
|