intor-translator 1.0.14 → 1.0.15

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/index.cjs CHANGED
@@ -212,9 +212,8 @@ var translate = ({
212
212
 
213
213
  // src/translators/base-translator/base-translator.ts
214
214
  var BaseTranslator = class {
215
- constructor(options = {}) {
215
+ constructor(options) {
216
216
  this.messagesRef = { current: void 0 };
217
- this.localeRef = { current: void 0 };
218
217
  /** Check if a key exists in the specified locale or current locale. */
219
218
  this.hasKey = (key, targetLocale) => {
220
219
  return hasKey({
@@ -224,12 +223,8 @@ var BaseTranslator = class {
224
223
  targetLocale
225
224
  });
226
225
  };
227
- if (options.messages) {
228
- this.messagesRef.current = options.messages;
229
- }
230
- if (options.locale) {
231
- this.localeRef.current = options.locale;
232
- }
226
+ this.messagesRef = { current: options.messages };
227
+ this.localeRef = { current: options.locale };
233
228
  }
234
229
  /** Get all message data. */
235
230
  get messages() {
@@ -270,7 +265,7 @@ var CoreTranslator = class extends BaseTranslator {
270
265
  replacements
271
266
  });
272
267
  };
273
- this.options = options || {};
268
+ this.options = options;
274
269
  }
275
270
  /** Get the current loading state. */
276
271
  get isLoading() {
package/dist/index.d.cts CHANGED
@@ -313,7 +313,7 @@ type MessagesRef<M> = {
313
313
  * };
314
314
  */
315
315
  type LocaleRef<M> = {
316
- current?: LocaleKey<M>;
316
+ current: LocaleKey<M>;
317
317
  };
318
318
  /**
319
319
  * A ref object indicating whether translation is loading.
@@ -374,13 +374,13 @@ type TranslateContext = {
374
374
 
375
375
  interface BaseTranslatorOptions<M = unknown> {
376
376
  messages?: Readonly<M>;
377
- locale?: LocaleKey<M>;
377
+ locale: LocaleKey<M>;
378
378
  }
379
379
 
380
380
  declare class BaseTranslator<M = unknown> {
381
381
  protected messagesRef: MessagesRef<M>;
382
382
  protected localeRef: LocaleRef<M>;
383
- constructor(options?: BaseTranslatorOptions<M>);
383
+ constructor(options: BaseTranslatorOptions<M>);
384
384
  /** Get all message data. */
385
385
  get messages(): M | undefined;
386
386
  /**
@@ -391,7 +391,7 @@ declare class BaseTranslator<M = unknown> {
391
391
  */
392
392
  setMessages<N extends LocaleNamespaceMessages>(messages: N): void;
393
393
  /** Get the current active locale. */
394
- get locale(): LocaleKey<M> | undefined;
394
+ get locale(): LocaleKey<M>;
395
395
  /** Change the active locale. */
396
396
  setLocale(newLocale: LocaleKey<M>): void;
397
397
  /** Check if a key exists in the specified locale or current locale. */
@@ -404,7 +404,7 @@ interface CoreTranslatorOptions<M> extends BaseTranslatorOptions<M>, TranslateCo
404
404
  declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
405
405
  protected options: CoreTranslatorOptions<M>;
406
406
  protected isLoadingRef: IsLoadingRef;
407
- constructor(options?: CoreTranslatorOptions<M>);
407
+ constructor(options: CoreTranslatorOptions<M>);
408
408
  /** Get the current loading state. */
409
409
  get isLoading(): boolean;
410
410
  /** Set the loading state. */
@@ -413,7 +413,7 @@ declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
413
413
  }
414
414
 
415
415
  declare class ScopeTranslator<M = unknown> extends CoreTranslator<M> {
416
- constructor(options?: CoreTranslatorOptions<M>);
416
+ constructor(options: CoreTranslatorOptions<M>);
417
417
  scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): ScopedTranslatorMethods<M, K>;
418
418
  scoped(): TranslatorMethods<M>;
419
419
  }
package/dist/index.d.ts CHANGED
@@ -313,7 +313,7 @@ type MessagesRef<M> = {
313
313
  * };
314
314
  */
315
315
  type LocaleRef<M> = {
316
- current?: LocaleKey<M>;
316
+ current: LocaleKey<M>;
317
317
  };
318
318
  /**
319
319
  * A ref object indicating whether translation is loading.
@@ -374,13 +374,13 @@ type TranslateContext = {
374
374
 
375
375
  interface BaseTranslatorOptions<M = unknown> {
376
376
  messages?: Readonly<M>;
377
- locale?: LocaleKey<M>;
377
+ locale: LocaleKey<M>;
378
378
  }
379
379
 
380
380
  declare class BaseTranslator<M = unknown> {
381
381
  protected messagesRef: MessagesRef<M>;
382
382
  protected localeRef: LocaleRef<M>;
383
- constructor(options?: BaseTranslatorOptions<M>);
383
+ constructor(options: BaseTranslatorOptions<M>);
384
384
  /** Get all message data. */
385
385
  get messages(): M | undefined;
386
386
  /**
@@ -391,7 +391,7 @@ declare class BaseTranslator<M = unknown> {
391
391
  */
392
392
  setMessages<N extends LocaleNamespaceMessages>(messages: N): void;
393
393
  /** Get the current active locale. */
394
- get locale(): LocaleKey<M> | undefined;
394
+ get locale(): LocaleKey<M>;
395
395
  /** Change the active locale. */
396
396
  setLocale(newLocale: LocaleKey<M>): void;
397
397
  /** Check if a key exists in the specified locale or current locale. */
@@ -404,7 +404,7 @@ interface CoreTranslatorOptions<M> extends BaseTranslatorOptions<M>, TranslateCo
404
404
  declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
405
405
  protected options: CoreTranslatorOptions<M>;
406
406
  protected isLoadingRef: IsLoadingRef;
407
- constructor(options?: CoreTranslatorOptions<M>);
407
+ constructor(options: CoreTranslatorOptions<M>);
408
408
  /** Get the current loading state. */
409
409
  get isLoading(): boolean;
410
410
  /** Set the loading state. */
@@ -413,7 +413,7 @@ declare class CoreTranslator<M = unknown> extends BaseTranslator<M> {
413
413
  }
414
414
 
415
415
  declare class ScopeTranslator<M = unknown> extends CoreTranslator<M> {
416
- constructor(options?: CoreTranslatorOptions<M>);
416
+ constructor(options: CoreTranslatorOptions<M>);
417
417
  scoped<K extends NodeKeys<UnionLocaleMessages<M>> & string>(preKey: K): ScopedTranslatorMethods<M, K>;
418
418
  scoped(): TranslatorMethods<M>;
419
419
  }
package/dist/index.js CHANGED
@@ -210,9 +210,8 @@ var translate = ({
210
210
 
211
211
  // src/translators/base-translator/base-translator.ts
212
212
  var BaseTranslator = class {
213
- constructor(options = {}) {
213
+ constructor(options) {
214
214
  this.messagesRef = { current: void 0 };
215
- this.localeRef = { current: void 0 };
216
215
  /** Check if a key exists in the specified locale or current locale. */
217
216
  this.hasKey = (key, targetLocale) => {
218
217
  return hasKey({
@@ -222,12 +221,8 @@ var BaseTranslator = class {
222
221
  targetLocale
223
222
  });
224
223
  };
225
- if (options.messages) {
226
- this.messagesRef.current = options.messages;
227
- }
228
- if (options.locale) {
229
- this.localeRef.current = options.locale;
230
- }
224
+ this.messagesRef = { current: options.messages };
225
+ this.localeRef = { current: options.locale };
231
226
  }
232
227
  /** Get all message data. */
233
228
  get messages() {
@@ -268,7 +263,7 @@ var CoreTranslator = class extends BaseTranslator {
268
263
  replacements
269
264
  });
270
265
  };
271
- this.options = options || {};
266
+ this.options = options;
272
267
  }
273
268
  /** Get the current loading state. */
274
269
  get isLoading() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "A type safe translator that knows what to say and how to handle the rest. Supports custom messages, rich replacements, and async loading.",
5
5
  "author": "Yiming Liao",
6
6
  "license": "MIT",