@plyaz/types 1.1.2 → 1.1.3

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.
@@ -1,4 +1,3 @@
1
- import type { Paths, Get } from 'type-fest';
2
1
  /**
3
2
  * Translation leaf type.
4
3
  * @description This type represents the structure of a translation leaf.
@@ -37,12 +36,56 @@ TranslationResourcesNested>>;
37
36
  * @example 'common', 'errors', etc.
38
37
  */
39
38
  export type Namespace<Resources extends TranslationResources> = keyof Resources['en'];
39
+ /**
40
+ * Helper type to remove the first element from a tuple type.
41
+ * Used internally by LeafPaths to track recursion depth.
42
+ */
43
+ type PrevTuple<T extends readonly unknown[]> = T extends [unknown, ...infer R] ? R : [];
40
44
  /**
41
45
  * Recursively extracts all nested keys from an object, creating dot-notation paths.
46
+ * @description This utility type traverses nested objects and creates dot-separated key paths.
47
+ * It uses a depth counter to prevent infinite recursion (max 25 levels, which should be sufficient
48
+ * for most translation structures while avoiding TypeScript compiler limits).
49
+ * @example
50
+ * type Paths = LeafPaths<{ a: { b: string, c: { d: string } } }>;
51
+ * // Result: 'a.b' | 'a.c.d'
52
+ * @template T - The object type to extract paths from
53
+ * @template Prev - The accumulated path string (used internally)
54
+ * @template Depth - Tuple type used to track recursion depth and prevent infinite loops
42
55
  */
43
- export type LeafPaths<T> = Paths<T> extends infer P ? P extends string ? Get<T, P> extends object ? never : P : never : never;
56
+ export type LeafPaths<T, Prev extends string = '', Depth extends readonly unknown[] = [
57
+ 1,
58
+ 1,
59
+ 1,
60
+ 1,
61
+ 1,
62
+ 1,
63
+ 1,
64
+ 1,
65
+ 1,
66
+ 1,
67
+ 1,
68
+ 1,
69
+ 1,
70
+ 1,
71
+ 1,
72
+ 1,
73
+ 1,
74
+ 1,
75
+ 1,
76
+ 1,
77
+ 1,
78
+ 1,
79
+ 1,
80
+ 1,
81
+ 1
82
+ ]> = Depth['length'] extends 0 ? never : T extends string ? Prev : T extends object ? {
83
+ [K in keyof T]: LeafPaths<T[K], Prev extends '' ? Extract<K, string> : `${Prev}.${Extract<K, string>}`, PrevTuple<Depth>>;
84
+ }[keyof T] : never;
44
85
  /**
45
86
  * Type-safe union of all translation keys in the form 'namespace.key' or 'namespace.nested.key'.
87
+ * @description This type generates a union of all possible translation keys by combining
88
+ * namespace names with their nested key paths. It ensures type safety when accessing translations.
46
89
  * @example 'common.hello', 'common.greeting', 'common.followers.zero', etc.
47
90
  * @example use: TranslationKeys<TranslationResources, 'en'>
48
91
  */
@@ -218,6 +261,11 @@ export interface Translator {
218
261
  */
219
262
  readonly addNamespace: (namespace: string, translations: Record<string, string>) => void;
220
263
  }
264
+ /**
265
+ * Command-line interface options for extracting translation keys from source code.
266
+ * @description These types define the configuration options for the CLI tool that
267
+ * automatically extracts translation keys from source files and generates translation files.
268
+ */
221
269
  export interface ExtractOptions {
222
270
  /**
223
271
  * File pattern to search for translation keys
@@ -240,6 +288,16 @@ export interface ExtractOptions {
240
288
  */
241
289
  readonly shouldDryRun: boolean;
242
290
  }
291
+ /**
292
+ * Pluralization test cases for validating translation pluralization rules.
293
+ * @description These types define the structure for testing pluralization functionality
294
+ * across different languages, ensuring correct plural forms are used based on numeric values.
295
+ */
296
+ /**
297
+ * Represents a single test case for pluralization validation.
298
+ * @description Defines a numeric value and its expected translation string
299
+ * to test pluralization rules in different languages.
300
+ */
243
301
  export interface PluralizationValueCase {
244
302
  /**
245
303
  * The numeric value to test pluralization against
@@ -250,6 +308,11 @@ export interface PluralizationValueCase {
250
308
  */
251
309
  readonly expected: string;
252
310
  }
311
+ /**
312
+ * Represents a complete set of pluralization test cases for a specific language.
313
+ * @description Groups multiple pluralization value cases together for a single language,
314
+ * allowing comprehensive testing of pluralization rules across different numeric values.
315
+ */
253
316
  export interface PluralizationCase {
254
317
  /**
255
318
  * The language code for this pluralization case
@@ -260,6 +323,16 @@ export interface PluralizationCase {
260
323
  */
261
324
  readonly values: readonly PluralizationValueCase[];
262
325
  }
326
+ /**
327
+ * Date formatting test cases for validating locale-specific date formatting.
328
+ * @description These types define the structure for testing date formatting functionality
329
+ * across different languages and locales.
330
+ */
331
+ /**
332
+ * Represents a test case for date formatting validation.
333
+ * @description Defines a language and its expected formatted date string
334
+ * to test date formatting rules in different locales.
335
+ */
263
336
  export interface DateCase {
264
337
  /**
265
338
  * The language code for this date formatting case
@@ -270,6 +343,16 @@ export interface DateCase {
270
343
  */
271
344
  readonly expected: string;
272
345
  }
346
+ /**
347
+ * Number formatting test cases for validating locale-specific number formatting.
348
+ * @description These types define the structure for testing number formatting functionality
349
+ * across different languages and locales.
350
+ */
351
+ /**
352
+ * Represents a test case for number formatting validation.
353
+ * @description Defines a language and its expected formatted number string
354
+ * to test number formatting rules in different locales.
355
+ */
273
356
  export interface NumberCase {
274
357
  /**
275
358
  * The language code for this number formatting case
@@ -280,6 +363,16 @@ export interface NumberCase {
280
363
  */
281
364
  readonly expected: string;
282
365
  }
366
+ /**
367
+ * Currency formatting test cases for validating locale-specific currency formatting.
368
+ * @description These types define the structure for testing currency formatting functionality
369
+ * across different languages and locales, including currency symbols and formatting options.
370
+ */
371
+ /**
372
+ * Represents a test case for currency formatting validation.
373
+ * @description Defines a language, expected formatted currency string, and formatting options
374
+ * to test currency formatting rules in different locales.
375
+ */
283
376
  export interface CurrencyCase {
284
377
  /**
285
378
  * The language code for this currency formatting case
@@ -294,3 +387,4 @@ export interface CurrencyCase {
294
387
  */
295
388
  readonly options: Intl.NumberFormatOptions;
296
389
  }
390
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",