@aidc-toolkit/utility 0.9.8-beta → 0.9.9-beta
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/LICENSE +0 -27
- package/README.md +14 -0
- package/dist/index.cjs +95 -74
- package/dist/index.d.cts +71 -550
- package/dist/index.d.ts +71 -550
- package/dist/index.js +91 -70
- package/package.json +8 -8
- package/src/character-set.ts +1 -1
- package/src/index.ts +17 -1
- package/src/locale/en/locale-strings.ts +2 -2
- package/src/locale/fr/locale-strings.ts +2 -2
- package/src/locale/i18n.ts +3 -2
- package/src/{sequencer.ts → sequence.ts} +12 -12
- package/src/transformer.ts +102 -99
- package/test/character-set.test.ts +4 -4
- package/test/{sequencer.test.ts → sequence.test.ts} +16 -16
- package/test/transformer.test.ts +20 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,507 +1,5 @@
|
|
|
1
|
-
import { $NormalizeIntoArray, $Dictionary } from './typescript/helpers.js';
|
|
2
|
-
import { DefaultNamespace, FlatNamespace, InitOptions, Namespace, FormatFunction, Resource, TOptions, InterpolationOptions, ResourceLanguage, ResourceKey } from './typescript/options.js';
|
|
3
|
-
import { TFunction, KeyPrefix } from './typescript/t.js';
|
|
4
1
|
import { I18NEnvironment } from '@aidc-toolkit/core';
|
|
5
|
-
import { Resource
|
|
6
|
-
|
|
7
|
-
// Internal Helpers
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
interface Interpolator {
|
|
11
|
-
init(options: InterpolationOptions, reset: boolean): undefined;
|
|
12
|
-
reset(): undefined;
|
|
13
|
-
resetRegExp(): undefined;
|
|
14
|
-
interpolate(str: string, data: object, lng: string, options: InterpolationOptions): string;
|
|
15
|
-
nest(str: string, fc: (...args: any[]) => any, options: InterpolationOptions): string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare class ResourceStore {
|
|
19
|
-
constructor(data: Resource, options: InitOptions);
|
|
20
|
-
|
|
21
|
-
public data: Resource;
|
|
22
|
-
|
|
23
|
-
public options: InitOptions;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Gets fired when resources got added or removed
|
|
27
|
-
*/
|
|
28
|
-
on(event: 'added' | 'removed', callback: (lng: string, ns: string) => void): void;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Remove event listener
|
|
32
|
-
* removes all callback when callback not specified
|
|
33
|
-
*/
|
|
34
|
-
off(event: 'added' | 'removed', callback?: (lng: string, ns: string) => void): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface Formatter {
|
|
38
|
-
init(services: Services, i18nextOptions: InitOptions): void;
|
|
39
|
-
add(name: string, fc: (value: any, lng: string | undefined, options: any) => string): void;
|
|
40
|
-
addCached(
|
|
41
|
-
name: string,
|
|
42
|
-
fc: (lng: string | undefined, options: any) => (value: any) => string,
|
|
43
|
-
): void;
|
|
44
|
-
format: FormatFunction;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface Services {
|
|
48
|
-
backendConnector: any;
|
|
49
|
-
i18nFormat: any;
|
|
50
|
-
interpolator: Interpolator;
|
|
51
|
-
languageDetector: any;
|
|
52
|
-
languageUtils: any;
|
|
53
|
-
logger: any;
|
|
54
|
-
pluralResolver: any;
|
|
55
|
-
resourceStore: ResourceStore;
|
|
56
|
-
formatter?: Formatter;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type ModuleType =
|
|
60
|
-
| 'backend'
|
|
61
|
-
| 'logger'
|
|
62
|
-
| 'languageDetector'
|
|
63
|
-
| 'postProcessor'
|
|
64
|
-
| 'i18nFormat'
|
|
65
|
-
| 'formatter'
|
|
66
|
-
| '3rdParty';
|
|
67
|
-
|
|
68
|
-
interface Module {
|
|
69
|
-
type: ModuleType;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
type CallbackError = Error | string | null | undefined;
|
|
73
|
-
type ReadCallback = (
|
|
74
|
-
err: CallbackError,
|
|
75
|
-
data: ResourceKey | boolean | null | undefined,
|
|
76
|
-
) => void;
|
|
77
|
-
type MultiReadCallback = (err: CallbackError, data: Resource | null | undefined) => void;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Used to load data for i18next.
|
|
81
|
-
* Can be provided as a singleton or as a prototype constructor (preferred for supporting multiple instances of i18next).
|
|
82
|
-
* For singleton set property `type` to `'backend'` For a prototype constructor set static property.
|
|
83
|
-
*/
|
|
84
|
-
interface BackendModule<Options = object> extends Module {
|
|
85
|
-
type: 'backend';
|
|
86
|
-
init(services: Services, backendOptions: Options, i18nextOptions: InitOptions): void;
|
|
87
|
-
read(language: string, namespace: string, callback: ReadCallback): void;
|
|
88
|
-
/** Save the missing translation */
|
|
89
|
-
create?(
|
|
90
|
-
languages: readonly string[],
|
|
91
|
-
namespace: string,
|
|
92
|
-
key: string,
|
|
93
|
-
fallbackValue: string,
|
|
94
|
-
): void;
|
|
95
|
-
/** Load multiple languages and namespaces. For backends supporting multiple resources loading */
|
|
96
|
-
readMulti?(
|
|
97
|
-
languages: readonly string[],
|
|
98
|
-
namespaces: readonly string[],
|
|
99
|
-
callback: MultiReadCallback,
|
|
100
|
-
): void;
|
|
101
|
-
/** Store the translation. For backends acting as cache layer */
|
|
102
|
-
save?(language: string, namespace: string, data: ResourceLanguage): void;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Used to detect language in user land.
|
|
107
|
-
* Can be provided as a singleton or as a prototype constructor (preferred for supporting multiple instances of i18next).
|
|
108
|
-
* For singleton set property `type` to `'languageDetector'` For a prototype constructor set static property.
|
|
109
|
-
*/
|
|
110
|
-
interface LanguageDetectorModule extends Module {
|
|
111
|
-
type: 'languageDetector';
|
|
112
|
-
init?(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void;
|
|
113
|
-
/** Must return detected language */
|
|
114
|
-
detect(): string | readonly string[] | undefined;
|
|
115
|
-
cacheUserLanguage?(lng: string): void;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Used to detect language in user land.
|
|
120
|
-
* Can be provided as a singleton or as a prototype constructor (preferred for supporting multiple instances of i18next).
|
|
121
|
-
* For singleton set property `type` to `'languageDetector'` For a prototype constructor set static property.
|
|
122
|
-
*/
|
|
123
|
-
interface LanguageDetectorAsyncModule extends Module {
|
|
124
|
-
type: 'languageDetector';
|
|
125
|
-
/** Set to true to enable async detection */
|
|
126
|
-
async: true;
|
|
127
|
-
init?(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void;
|
|
128
|
-
/** Must call callback passing detected language or return a Promise */
|
|
129
|
-
detect(
|
|
130
|
-
callback: (lng: string | readonly string[] | undefined) => void | undefined,
|
|
131
|
-
): void | Promise<string | readonly string[] | undefined>;
|
|
132
|
-
cacheUserLanguage?(lng: string): void | Promise<void>;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Override the built-in console logger.
|
|
137
|
-
* Do not need to be a prototype function.
|
|
138
|
-
*/
|
|
139
|
-
interface LoggerModule extends Module {
|
|
140
|
-
type: 'logger';
|
|
141
|
-
log(...args: any[]): void;
|
|
142
|
-
warn(...args: any[]): void;
|
|
143
|
-
error(...args: any[]): void;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
interface I18nFormatModule extends Module {
|
|
147
|
-
type: 'i18nFormat';
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
interface FormatterModule extends Module, Formatter {
|
|
151
|
-
type: 'formatter';
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
interface ThirdPartyModule extends Module {
|
|
155
|
-
type: '3rdParty';
|
|
156
|
-
init(i18next: i18n): void;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
interface Modules {
|
|
160
|
-
backend?: BackendModule;
|
|
161
|
-
logger?: LoggerModule;
|
|
162
|
-
languageDetector?: LanguageDetectorModule | LanguageDetectorAsyncModule;
|
|
163
|
-
i18nFormat?: I18nFormatModule;
|
|
164
|
-
formatter?: FormatterModule;
|
|
165
|
-
external: ThirdPartyModule[];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// helper to identify class https://stackoverflow.com/a/45983481/2363935
|
|
169
|
-
interface Newable<T> {
|
|
170
|
-
new (...args: any[]): T;
|
|
171
|
-
}
|
|
172
|
-
interface NewableModule<T extends Module> extends Newable<T> {
|
|
173
|
-
type: T['type'];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
type Callback = (error: any, t: TFunction) => void;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Uses similar args as the t function and returns true if a key exists.
|
|
180
|
-
*/
|
|
181
|
-
interface ExistsFunction<
|
|
182
|
-
TKeys extends string = string,
|
|
183
|
-
TInterpolationMap extends object = $Dictionary,
|
|
184
|
-
> {
|
|
185
|
-
(key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): boolean;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
interface CloneOptions extends InitOptions {
|
|
189
|
-
/**
|
|
190
|
-
* Will create a new instance of the resource store and import the existing translation resources.
|
|
191
|
-
* This way it will not shared the resource store instance.
|
|
192
|
-
* @default false
|
|
193
|
-
*/
|
|
194
|
-
forkResourceStore?: boolean;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
interface CustomInstanceExtensions {}
|
|
198
|
-
|
|
199
|
-
// Used just here to exclude `DefaultNamespace` which can be both string or array from `FlatNamespace`
|
|
200
|
-
// in TFunction declaration below.
|
|
201
|
-
// Due to this only very special usage I'm not moving this inside helpers.
|
|
202
|
-
type InferArrayValuesElseReturnType<T> = T extends (infer A)[] ? A : T;
|
|
203
|
-
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
205
|
-
interface i18n extends CustomInstanceExtensions {
|
|
206
|
-
// Expose parameterized t in the i18next interface hierarchy
|
|
207
|
-
t: TFunction<
|
|
208
|
-
[
|
|
209
|
-
...$NormalizeIntoArray<DefaultNamespace>,
|
|
210
|
-
...Exclude<FlatNamespace, InferArrayValuesElseReturnType<DefaultNamespace>>[],
|
|
211
|
-
]
|
|
212
|
-
>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* The default of the i18next module is an i18next instance ready to be initialized by calling init.
|
|
216
|
-
* You can create additional instances using the createInstance function.
|
|
217
|
-
*
|
|
218
|
-
* @param options - Initial options.
|
|
219
|
-
* @param callback - will be called after all translations were loaded or with an error when failed (in case of using a backend).
|
|
220
|
-
*/
|
|
221
|
-
init(callback?: Callback): Promise<TFunction>;
|
|
222
|
-
init<T>(options: InitOptions<T>, callback?: Callback): Promise<TFunction>;
|
|
223
|
-
|
|
224
|
-
loadResources(callback?: (err: any) => void): void;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* The use function is there to load additional plugins to i18next.
|
|
228
|
-
* For available module see the plugins page and don't forget to read the documentation of the plugin.
|
|
229
|
-
*
|
|
230
|
-
* @param module Accepts a class or object
|
|
231
|
-
*/
|
|
232
|
-
use<T extends Module>(module: T | NewableModule<T> | Newable<T>): this;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* List of modules used
|
|
236
|
-
*/
|
|
237
|
-
modules: Modules;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Internal container for all used plugins and implementation details like languageUtils, pluralResolvers, etc.
|
|
241
|
-
*/
|
|
242
|
-
services: Services;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Internal container for translation resources
|
|
246
|
-
*/
|
|
247
|
-
store: ResourceStore;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Uses similar args as the t function and returns true if a key exists.
|
|
251
|
-
*/
|
|
252
|
-
exists: ExistsFunction;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Returns a resource data by language.
|
|
256
|
-
*/
|
|
257
|
-
getDataByLanguage(lng: string): { [key: string]: { [key: string]: string } } | undefined;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Returns a t function that defaults to given language or namespace.
|
|
261
|
-
* Both params could be arrays of languages or namespaces and will be treated as fallbacks in that case.
|
|
262
|
-
* On the returned function you can like in the t function override the languages or namespaces by passing them in options or by prepending namespace.
|
|
263
|
-
*
|
|
264
|
-
* Accepts optional keyPrefix that will be automatically applied to returned t function.
|
|
265
|
-
*/
|
|
266
|
-
getFixedT<
|
|
267
|
-
Ns extends Namespace | null = DefaultNamespace,
|
|
268
|
-
TKPrefix extends KeyPrefix<ActualNs> = undefined,
|
|
269
|
-
ActualNs extends Namespace = Ns extends null ? DefaultNamespace : Ns,
|
|
270
|
-
>(
|
|
271
|
-
...args:
|
|
272
|
-
| [lng: string | readonly string[], ns?: Ns, keyPrefix?: TKPrefix]
|
|
273
|
-
| [lng: null, ns: Ns, keyPrefix?: TKPrefix]
|
|
274
|
-
): TFunction<ActualNs, TKPrefix>;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Changes the language. The callback will be called as soon translations were loaded or an error occurs while loading.
|
|
278
|
-
* HINT: For easy testing - setting lng to 'cimode' will set t function to always return the key.
|
|
279
|
-
*/
|
|
280
|
-
changeLanguage(lng?: string, callback?: Callback): Promise<TFunction>;
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Is set to the current detected or set language.
|
|
284
|
-
* If you need the primary used language depending on your configuration (supportedLngs, load) you will prefer using i18next.languages[0].
|
|
285
|
-
*/
|
|
286
|
-
language: string;
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Is set to an array of language-codes that will be used it order to lookup the translation value.
|
|
290
|
-
*/
|
|
291
|
-
languages: readonly string[];
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Is set to the current resolved language.
|
|
295
|
-
* It can be used as primary used language, for example in a language switcher.
|
|
296
|
-
*/
|
|
297
|
-
resolvedLanguage?: string;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Checks if namespace has loaded yet.
|
|
301
|
-
* i.e. used by react-i18next
|
|
302
|
-
*/
|
|
303
|
-
hasLoadedNamespace(
|
|
304
|
-
ns: string | readonly string[],
|
|
305
|
-
options?: {
|
|
306
|
-
lng?: string | readonly string[];
|
|
307
|
-
fallbackLng?: InitOptions['fallbackLng'];
|
|
308
|
-
/**
|
|
309
|
-
* if `undefined` is returned default checks are performed.
|
|
310
|
-
*/
|
|
311
|
-
precheck?: (
|
|
312
|
-
i18n: i18n,
|
|
313
|
-
/**
|
|
314
|
-
* Check if the language namespace provided are not in loading status:
|
|
315
|
-
* returns `true` if load is completed successfully or with an error.
|
|
316
|
-
*/
|
|
317
|
-
loadNotPending: (
|
|
318
|
-
lng: string | readonly string[],
|
|
319
|
-
ns: string | readonly string[],
|
|
320
|
-
) => boolean,
|
|
321
|
-
) => boolean | undefined;
|
|
322
|
-
},
|
|
323
|
-
): boolean;
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Loads additional namespaces not defined in init options.
|
|
327
|
-
*/
|
|
328
|
-
loadNamespaces(ns: string | readonly string[], callback?: Callback): Promise<void>;
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Loads additional languages not defined in init options (preload).
|
|
332
|
-
*/
|
|
333
|
-
loadLanguages(lngs: string | readonly string[], callback?: Callback): Promise<void>;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Reloads resources on given state. Optionally you can pass an array of languages and namespaces as params if you don't want to reload all.
|
|
337
|
-
*/
|
|
338
|
-
reloadResources(
|
|
339
|
-
lngs?: string | readonly string[],
|
|
340
|
-
ns?: string | readonly string[],
|
|
341
|
-
callback?: () => void,
|
|
342
|
-
): Promise<void>;
|
|
343
|
-
reloadResources(lngs: null, ns: string | readonly string[], callback?: () => void): Promise<void>;
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Changes the default namespace.
|
|
347
|
-
*/
|
|
348
|
-
setDefaultNamespace(ns: string | readonly string[]): void;
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Returns rtl or ltr depending on languages read direction.
|
|
352
|
-
*/
|
|
353
|
-
dir(lng?: string): 'ltr' | 'rtl';
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Exposes interpolation.format function added on init.
|
|
357
|
-
*/
|
|
358
|
-
format: FormatFunction;
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Will return a new i18next instance.
|
|
362
|
-
* Please read the options page for details on configuration options.
|
|
363
|
-
* Providing a callback will automatically call init.
|
|
364
|
-
* The callback will be called after all translations were loaded or with an error when failed (in case of using a backend).
|
|
365
|
-
*/
|
|
366
|
-
createInstance(options?: InitOptions, callback?: Callback): i18n;
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Creates a clone of the current instance. Shares store, plugins and initial configuration.
|
|
370
|
-
* Can be used to create an instance sharing storage but being independent on set language or namespaces.
|
|
371
|
-
*/
|
|
372
|
-
cloneInstance(options?: CloneOptions, callback?: Callback): i18n;
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Gets fired after initialization.
|
|
376
|
-
*/
|
|
377
|
-
on(event: 'initialized', callback: (options: InitOptions) => void): void;
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Gets fired on loaded resources.
|
|
381
|
-
*/
|
|
382
|
-
on(
|
|
383
|
-
event: 'loaded',
|
|
384
|
-
callback: (loaded: { [language: string]: { [namespace: string]: boolean } }) => void,
|
|
385
|
-
): void;
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Gets fired if loading resources failed.
|
|
389
|
-
*/
|
|
390
|
-
on(event: 'failedLoading', callback: (lng: string, ns: string, msg: string) => void): void;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Gets fired on accessing a key not existing.
|
|
394
|
-
*/
|
|
395
|
-
on(
|
|
396
|
-
event: 'missingKey',
|
|
397
|
-
callback: (lngs: readonly string[], namespace: string, key: string, res: string) => void,
|
|
398
|
-
): void;
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Gets fired when resources got added or removed.
|
|
402
|
-
*/
|
|
403
|
-
on(event: 'added' | 'removed', callback: (lng: string, ns: string) => void): void;
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Gets fired when changeLanguage got called.
|
|
407
|
-
*/
|
|
408
|
-
on(event: 'languageChanged', callback: (lng: string) => void): void;
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Event listener
|
|
412
|
-
*/
|
|
413
|
-
on(event: string, listener: (...args: any[]) => void): void;
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Remove event listener
|
|
417
|
-
* removes all callback when callback not specified
|
|
418
|
-
*/
|
|
419
|
-
off(event: string, listener?: (...args: any[]) => void): void;
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Gets one value by given key.
|
|
423
|
-
*/
|
|
424
|
-
getResource(
|
|
425
|
-
lng: string,
|
|
426
|
-
ns: string,
|
|
427
|
-
key: string,
|
|
428
|
-
options?: Pick<InitOptions, 'keySeparator' | 'ignoreJSONStructure'>,
|
|
429
|
-
): any;
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Adds one key/value.
|
|
433
|
-
*/
|
|
434
|
-
addResource(
|
|
435
|
-
lng: string,
|
|
436
|
-
ns: string,
|
|
437
|
-
key: string,
|
|
438
|
-
value: string,
|
|
439
|
-
options?: { keySeparator?: string; silent?: boolean },
|
|
440
|
-
): i18n;
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* Adds multiple key/values.
|
|
444
|
-
*/
|
|
445
|
-
addResources(lng: string, ns: string, resources: any): i18n;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Adds a complete bundle.
|
|
449
|
-
* Setting deep param to true will extend existing translations in that file.
|
|
450
|
-
* Setting overwrite to true it will overwrite existing translations in that file.
|
|
451
|
-
*/
|
|
452
|
-
addResourceBundle(
|
|
453
|
-
lng: string,
|
|
454
|
-
ns: string,
|
|
455
|
-
resources: any,
|
|
456
|
-
deep?: boolean,
|
|
457
|
-
overwrite?: boolean,
|
|
458
|
-
): i18n;
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Checks if a resource bundle exists.
|
|
462
|
-
*/
|
|
463
|
-
hasResourceBundle(lng: string, ns: string): boolean;
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Returns a resource bundle.
|
|
467
|
-
*/
|
|
468
|
-
getResourceBundle(lng: string, ns: string): any;
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Removes an existing bundle.
|
|
472
|
-
*/
|
|
473
|
-
removeResourceBundle(lng: string, ns: string): i18n;
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Current options
|
|
477
|
-
*/
|
|
478
|
-
options: InitOptions;
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Is initialized
|
|
482
|
-
*/
|
|
483
|
-
isInitialized: boolean;
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Is initializing
|
|
487
|
-
*/
|
|
488
|
-
isInitializing: boolean;
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Store was initialized
|
|
492
|
-
*/
|
|
493
|
-
initializedStoreOnce: boolean;
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Language was initialized
|
|
497
|
-
*/
|
|
498
|
-
initializedLanguageOnce: boolean;
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Emit event
|
|
502
|
-
*/
|
|
503
|
-
emit(eventName: string, ...args: any[]): void;
|
|
504
|
-
}
|
|
2
|
+
import { Resource, i18n } from 'i18next';
|
|
505
3
|
|
|
506
4
|
declare const localeStrings: {
|
|
507
5
|
readonly Transformer: {
|
|
@@ -509,8 +7,8 @@ declare const localeStrings: {
|
|
|
509
7
|
readonly tweakMustBeGreaterThanOrEqualToZero: "Tweak {{tweak}} must be greater than or equal to 0";
|
|
510
8
|
readonly valueMustBeGreaterThanOrEqualToZero: "Value {{value}} must be greater than or equal to 0";
|
|
511
9
|
readonly valueMustBeLessThan: "Value {{value}} must be less than {{domain}}";
|
|
512
|
-
readonly
|
|
513
|
-
readonly
|
|
10
|
+
readonly minimumValueMustBeGreaterThanOrEqualToZero: "Minimum value {{minimumValue}} must be greater than or equal to 0";
|
|
11
|
+
readonly maximumValueMustBeLessThan: "Maximum value {{maximumValue}} must be less than {{domain}}";
|
|
514
12
|
};
|
|
515
13
|
readonly RegExpValidator: {
|
|
516
14
|
readonly stringDoesNotMatchPattern: "String {{s}} does not match pattern";
|
|
@@ -544,7 +42,7 @@ type UtilityLocaleStrings = typeof localeStrings;
|
|
|
544
42
|
/**
|
|
545
43
|
* Utility resources.
|
|
546
44
|
*/
|
|
547
|
-
declare const utilityResources: Resource
|
|
45
|
+
declare const utilityResources: Resource;
|
|
548
46
|
declare const i18nextUtility: i18n;
|
|
549
47
|
/**
|
|
550
48
|
* Initialize internationalization.
|
|
@@ -561,9 +59,9 @@ declare const i18nextUtility: i18n;
|
|
|
561
59
|
declare function i18nUtilityInit(environment: I18NEnvironment, debug?: boolean): Promise<void>;
|
|
562
60
|
|
|
563
61
|
/**
|
|
564
|
-
*
|
|
62
|
+
* Sequence. Defines an ascending or descending sequence of big integers implemented as an iterable.
|
|
565
63
|
*/
|
|
566
|
-
declare class
|
|
64
|
+
declare class Sequence implements Iterable<bigint> {
|
|
567
65
|
/**
|
|
568
66
|
* Start value (inclusive).
|
|
569
67
|
*/
|
|
@@ -583,11 +81,11 @@ declare class Sequencer implements Iterable<bigint> {
|
|
|
583
81
|
/**
|
|
584
82
|
* Minimum value (inclusive).
|
|
585
83
|
*/
|
|
586
|
-
private readonly
|
|
84
|
+
private readonly _minimumValue;
|
|
587
85
|
/**
|
|
588
86
|
* Maximum value (inclusive).
|
|
589
87
|
*/
|
|
590
|
-
private readonly
|
|
88
|
+
private readonly _maximumValue;
|
|
591
89
|
/**
|
|
592
90
|
* Constructor.
|
|
593
91
|
*
|
|
@@ -614,11 +112,11 @@ declare class Sequencer implements Iterable<bigint> {
|
|
|
614
112
|
/**
|
|
615
113
|
* Get the minimum value (inclusive).
|
|
616
114
|
*/
|
|
617
|
-
get
|
|
115
|
+
get minimumValue(): bigint;
|
|
618
116
|
/**
|
|
619
117
|
* Get the maximum value (inclusive).
|
|
620
118
|
*/
|
|
621
|
-
get
|
|
119
|
+
get maximumValue(): bigint;
|
|
622
120
|
/**
|
|
623
121
|
* Iterable implementation.
|
|
624
122
|
*
|
|
@@ -629,23 +127,27 @@ declare class Sequencer implements Iterable<bigint> {
|
|
|
629
127
|
}
|
|
630
128
|
|
|
631
129
|
/**
|
|
632
|
-
* Transformer
|
|
130
|
+
* Transformer primitive type.
|
|
131
|
+
*/
|
|
132
|
+
type TransformerPrimitive = string | number | bigint | boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Transformer input type, one of:
|
|
633
135
|
*
|
|
634
|
-
* -
|
|
635
|
-
* - Iterable<
|
|
136
|
+
* - TInput (primitive type)
|
|
137
|
+
* - Iterable<TInput>
|
|
636
138
|
*
|
|
637
|
-
* @template
|
|
638
|
-
*
|
|
139
|
+
* @template TInput
|
|
140
|
+
* Transformer input primitive type.
|
|
639
141
|
*/
|
|
640
|
-
type TransformerInput<
|
|
142
|
+
type TransformerInput<TInput extends TransformerPrimitive> = TInput | Iterable<TInput>;
|
|
641
143
|
/**
|
|
642
144
|
* Transformer callback, used to convert transformed value to its final value.
|
|
643
145
|
*
|
|
644
146
|
* @template TInput
|
|
645
|
-
*
|
|
147
|
+
* Transformer input primitive type.
|
|
646
148
|
*
|
|
647
149
|
* @template TOutput
|
|
648
|
-
*
|
|
150
|
+
* Transformer output type.
|
|
649
151
|
*
|
|
650
152
|
* @param input
|
|
651
153
|
* Input value.
|
|
@@ -656,33 +158,33 @@ type TransformerInput<T extends string | number | bigint | boolean> = T | Iterab
|
|
|
656
158
|
* @returns
|
|
657
159
|
* Output value.
|
|
658
160
|
*/
|
|
659
|
-
type TransformerCallback<TInput, TOutput> = (input: TInput, index: number) => TOutput;
|
|
161
|
+
type TransformerCallback<TInput extends TransformerPrimitive, TOutput> = (input: TInput, index: number) => TOutput;
|
|
660
162
|
/**
|
|
661
163
|
* Transformer output, based on transformer input:
|
|
662
164
|
*
|
|
663
|
-
* - If type
|
|
664
|
-
* - If type
|
|
165
|
+
* - If type TTransformerInput is primitive, result is type TOutput.
|
|
166
|
+
* - If type TTransformerInput is Iterable, result is type Iterable<TOutput>.
|
|
665
167
|
*
|
|
666
|
-
* @template
|
|
168
|
+
* @template TTransformerInput
|
|
667
169
|
* Transformer input type.
|
|
668
170
|
*
|
|
669
171
|
* @template TOutput
|
|
670
172
|
* Output base type.
|
|
671
173
|
*/
|
|
672
|
-
type TransformerOutput<
|
|
174
|
+
type TransformerOutput<TTransformerInput extends TransformerInput<TransformerPrimitive>, TOutput> = TTransformerInput extends (TTransformerInput extends TransformerInput<infer TInput> ? TInput : never) ? TOutput : Iterable<TOutput>;
|
|
673
175
|
/**
|
|
674
|
-
* Transform an iterable
|
|
176
|
+
* Transform an input iterable to an output iterable that applies a transformer callback to each value in the input.
|
|
675
177
|
*
|
|
676
|
-
* @param
|
|
677
|
-
* Input iterable.
|
|
178
|
+
* @param values
|
|
179
|
+
* Input values iterable.
|
|
678
180
|
*
|
|
679
181
|
* @param transformerCallback
|
|
680
182
|
* Callback to transform input value to output value.
|
|
681
183
|
*
|
|
682
184
|
* @returns
|
|
683
|
-
* Output iterable.
|
|
185
|
+
* Output values iterable.
|
|
684
186
|
*/
|
|
685
|
-
declare function transformIterable<TInput, TOutput>(
|
|
187
|
+
declare function transformIterable<TInput extends TransformerPrimitive, TOutput>(values: Iterable<TInput>, transformerCallback: TransformerCallback<TInput, TOutput>): Iterable<TOutput>;
|
|
686
188
|
/**
|
|
687
189
|
* Transformer that transforms values in a numeric domain to values in a range equal to the domain or to another range
|
|
688
190
|
* defined by a callback function. In other words, the domain determines valid input values and, without a callback, the
|
|
@@ -753,31 +255,57 @@ declare abstract class Transformer {
|
|
|
753
255
|
* Transformed value.
|
|
754
256
|
*/
|
|
755
257
|
protected abstract doForward(value: bigint): bigint;
|
|
258
|
+
/**
|
|
259
|
+
* Validate that a value is within the domain and do the work of transforming it forward.
|
|
260
|
+
*
|
|
261
|
+
* @param value
|
|
262
|
+
* Value.
|
|
263
|
+
*
|
|
264
|
+
* @returns
|
|
265
|
+
* Transformed value.
|
|
266
|
+
*/
|
|
267
|
+
private validateDoForward;
|
|
268
|
+
/**
|
|
269
|
+
* Validate that a value is within the domain, do the work of transforming it forward, and apply a callback.
|
|
270
|
+
*
|
|
271
|
+
* @param transformerCallback
|
|
272
|
+
* Called after each value is transformed to convert it to its final value.
|
|
273
|
+
*
|
|
274
|
+
* @param value
|
|
275
|
+
* Value.
|
|
276
|
+
*
|
|
277
|
+
* @param index
|
|
278
|
+
* Index in sequence (0 for single transformation).
|
|
279
|
+
*
|
|
280
|
+
* @returns
|
|
281
|
+
* Transformed value.
|
|
282
|
+
*/
|
|
283
|
+
private validateDoForwardCallback;
|
|
756
284
|
/**
|
|
757
285
|
* Transform value(s) forward.
|
|
758
286
|
*
|
|
759
|
-
* @template
|
|
287
|
+
* @template TTransformerInput
|
|
760
288
|
* Value(s) input type.
|
|
761
289
|
*
|
|
762
290
|
* @param valueOrValues
|
|
763
|
-
* Value(s). If this is an instance of {@link
|
|
291
|
+
* Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
|
|
764
292
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
765
293
|
*
|
|
766
294
|
* @returns
|
|
767
295
|
* Transformed value(s).
|
|
768
296
|
*/
|
|
769
|
-
forward<
|
|
297
|
+
forward<TTransformerInput extends TransformerInput<number | bigint>>(valueOrValues: TTransformerInput): TransformerOutput<TTransformerInput, bigint>;
|
|
770
298
|
/**
|
|
771
299
|
* Transform value(s) forward, optionally applying a transformation.
|
|
772
300
|
*
|
|
773
|
-
* @template
|
|
301
|
+
* @template TTransformerInput
|
|
774
302
|
* Value(s) input type.
|
|
775
303
|
*
|
|
776
|
-
* @template
|
|
304
|
+
* @template TOutput
|
|
777
305
|
* Transformation callback output type.
|
|
778
306
|
*
|
|
779
307
|
* @param valueOrValues
|
|
780
|
-
* Value(s). If this is an instance of {@link
|
|
308
|
+
* Value(s). If this is an instance of {@link Sequence}, the minimum and maximum values are validated prior to
|
|
781
309
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
782
310
|
*
|
|
783
311
|
* @param transformerCallback
|
|
@@ -786,7 +314,7 @@ declare abstract class Transformer {
|
|
|
786
314
|
* @returns
|
|
787
315
|
* Transformed value(s).
|
|
788
316
|
*/
|
|
789
|
-
forward<
|
|
317
|
+
forward<TTransformerInput extends TransformerInput<number | bigint>, TOutput>(valueOrValues: TTransformerInput, transformerCallback: TransformerCallback<bigint, TOutput>): TransformerOutput<TTransformerInput, TOutput>;
|
|
790
318
|
/**
|
|
791
319
|
* Do the work of transforming a value in reverse.
|
|
792
320
|
*
|
|
@@ -822,10 +350,11 @@ declare class IdentityTransformer extends Transformer {
|
|
|
822
350
|
protected doReverse(transformedValue: bigint): bigint;
|
|
823
351
|
}
|
|
824
352
|
/**
|
|
825
|
-
* Encryption transformer. Values are transformed using repeated shuffle and xor operations
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
353
|
+
* Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
|
|
354
|
+
* many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
|
|
355
|
+
* number generation, below), if true format-preserving encryption is required, a more robust algorithm such as
|
|
356
|
+
* {@link https://doi.org/10.6028/NIST.SP.800-38Gr1-draft | FF1} is recommended. Furthermore, no work has been done to
|
|
357
|
+
* mitigate {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
|
|
829
358
|
*
|
|
830
359
|
* The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
|
|
831
360
|
* the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
|
|
@@ -854,10 +383,6 @@ declare class EncryptionTransformer extends Transformer {
|
|
|
854
383
|
* Number of bytes covered by the domain.
|
|
855
384
|
*/
|
|
856
385
|
private readonly _domainBytes;
|
|
857
|
-
/**
|
|
858
|
-
* Tweak.
|
|
859
|
-
*/
|
|
860
|
-
private readonly _tweak;
|
|
861
386
|
/**
|
|
862
387
|
* Xor bytes array generated from the domain and tweak.
|
|
863
388
|
*/
|
|
@@ -884,10 +409,6 @@ declare class EncryptionTransformer extends Transformer {
|
|
|
884
409
|
* Tweak.
|
|
885
410
|
*/
|
|
886
411
|
constructor(domain: number | bigint, tweak: number | bigint);
|
|
887
|
-
/**
|
|
888
|
-
* Get the tweak.
|
|
889
|
-
*/
|
|
890
|
-
get tweak(): bigint;
|
|
891
412
|
/**
|
|
892
413
|
* Convert a value to a byte array big enough to handle the entire domain.
|
|
893
414
|
*
|
|
@@ -1385,4 +906,4 @@ declare const ALPHABETIC_CREATOR: CharacterSetCreator;
|
|
|
1385
906
|
*/
|
|
1386
907
|
declare const ALPHANUMERIC_CREATOR: CharacterSetCreator;
|
|
1387
908
|
|
|
1388
|
-
export { ALPHABETIC_CREATOR, ALPHANUMERIC_CREATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, Exclusion, HEXADECIMAL_CREATOR, IdentityTransformer, NUMERIC_CREATOR, RecordValidator, RegExpValidator,
|
|
909
|
+
export { ALPHABETIC_CREATOR, ALPHANUMERIC_CREATOR, CharacterSetCreator, type CharacterSetValidation, CharacterSetValidator, EncryptionTransformer, Exclusion, HEXADECIMAL_CREATOR, IdentityTransformer, NUMERIC_CREATOR, RecordValidator, RegExpValidator, Sequence, type StringValidation, type StringValidator, Transformer, type TransformerCallback, type TransformerInput, type TransformerOutput, type TransformerPrimitive, type UtilityLocaleStrings, i18nUtilityInit, i18nextUtility, transformIterable, utilityNS, utilityResources };
|