@plyaz/types 1.1.1 → 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.
- package/dist/translations/types.d.ts +96 -2
- package/package.json +9 -6
|
@@ -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
|
|
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.
|
|
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.",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"require": "./dist/index.js",
|
|
16
16
|
"default": "./dist/index.mjs"
|
|
17
17
|
},
|
|
18
|
+
"./translations": {
|
|
19
|
+
"types": "./dist/translations/index.d.ts"
|
|
20
|
+
},
|
|
18
21
|
"./package.json": "./package.json"
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
@@ -28,18 +31,18 @@
|
|
|
28
31
|
"packageManager": "pnpm@10.11.0",
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@changesets/cli": "^2.29.5",
|
|
31
|
-
"@plyaz/devtools": "^1.3.0",
|
|
32
|
-
"@types/node": "^20.0.0",
|
|
33
|
-
"@vitest/coverage-v8": "^3.1.3",
|
|
34
34
|
"@darraghor/eslint-plugin-nestjs-typed": "^6.6.2",
|
|
35
35
|
"@eslint/eslintrc": "^3.2.0",
|
|
36
36
|
"@eslint/js": "^9.15.0",
|
|
37
37
|
"@eslint/markdown": "^6.5.0",
|
|
38
38
|
"@nestjs/common": "^11.1.3",
|
|
39
39
|
"@next/eslint-plugin-next": "^15.0.3",
|
|
40
|
+
"@plyaz/devtools": "^1.4.2",
|
|
41
|
+
"@types/node": "^20.0.0",
|
|
42
|
+
"@types/react": "^19.1.8",
|
|
40
43
|
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
41
44
|
"@typescript-eslint/parser": "^8.15.0",
|
|
42
|
-
"@
|
|
45
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
43
46
|
"eslint": "^9.29.0",
|
|
44
47
|
"eslint-config-next": "^15.3.3",
|
|
45
48
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -74,10 +77,10 @@
|
|
|
74
77
|
"next": "15.3.3",
|
|
75
78
|
"prettier": "^3.5.3",
|
|
76
79
|
"standard-version": "^9.5.0",
|
|
80
|
+
"tailwindcss": "^4.1.8",
|
|
77
81
|
"tsup": "8.5.0",
|
|
78
82
|
"type-fest": "^4.41.0",
|
|
79
83
|
"typescript": "^5",
|
|
80
|
-
"tailwindcss": "^4.1.8",
|
|
81
84
|
"typescript-eslint": "^8.34.0",
|
|
82
85
|
"vitest": "3.2.4",
|
|
83
86
|
"zod": "^3.25.64"
|