i18next-cli 0.9.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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +489 -0
- package/dist/cjs/cli.js +2 -0
- package/dist/cjs/config.js +1 -0
- package/dist/cjs/extractor/core/extractor.js +1 -0
- package/dist/cjs/extractor/core/key-finder.js +1 -0
- package/dist/cjs/extractor/core/translation-manager.js +1 -0
- package/dist/cjs/extractor/parsers/ast-visitors.js +1 -0
- package/dist/cjs/extractor/parsers/comment-parser.js +1 -0
- package/dist/cjs/extractor/parsers/jsx-parser.js +1 -0
- package/dist/cjs/extractor/plugin-manager.js +1 -0
- package/dist/cjs/heuristic-config.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/init.js +1 -0
- package/dist/cjs/linter.js +1 -0
- package/dist/cjs/locize.js +1 -0
- package/dist/cjs/migrator.js +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/status.js +1 -0
- package/dist/cjs/syncer.js +1 -0
- package/dist/cjs/types-generator.js +1 -0
- package/dist/cjs/utils/file-utils.js +1 -0
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/utils/nested-object.js +1 -0
- package/dist/cjs/utils/validation.js +1 -0
- package/dist/esm/cli.js +2 -0
- package/dist/esm/config.js +1 -0
- package/dist/esm/extractor/core/extractor.js +1 -0
- package/dist/esm/extractor/core/key-finder.js +1 -0
- package/dist/esm/extractor/core/translation-manager.js +1 -0
- package/dist/esm/extractor/parsers/ast-visitors.js +1 -0
- package/dist/esm/extractor/parsers/comment-parser.js +1 -0
- package/dist/esm/extractor/parsers/jsx-parser.js +1 -0
- package/dist/esm/extractor/plugin-manager.js +1 -0
- package/dist/esm/heuristic-config.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/init.js +1 -0
- package/dist/esm/linter.js +1 -0
- package/dist/esm/locize.js +1 -0
- package/dist/esm/migrator.js +1 -0
- package/dist/esm/status.js +1 -0
- package/dist/esm/syncer.js +1 -0
- package/dist/esm/types-generator.js +1 -0
- package/dist/esm/utils/file-utils.js +1 -0
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/utils/nested-object.js +1 -0
- package/dist/esm/utils/validation.js +1 -0
- package/package.json +81 -0
- package/src/cli.ts +166 -0
- package/src/config.ts +158 -0
- package/src/extractor/core/extractor.ts +195 -0
- package/src/extractor/core/key-finder.ts +70 -0
- package/src/extractor/core/translation-manager.ts +115 -0
- package/src/extractor/index.ts +7 -0
- package/src/extractor/parsers/ast-visitors.ts +637 -0
- package/src/extractor/parsers/comment-parser.ts +125 -0
- package/src/extractor/parsers/jsx-parser.ts +166 -0
- package/src/extractor/plugin-manager.ts +54 -0
- package/src/extractor.ts +15 -0
- package/src/heuristic-config.ts +64 -0
- package/src/index.ts +12 -0
- package/src/init.ts +156 -0
- package/src/linter.ts +191 -0
- package/src/locize.ts +251 -0
- package/src/migrator.ts +139 -0
- package/src/status.ts +192 -0
- package/src/syncer.ts +114 -0
- package/src/types-generator.ts +116 -0
- package/src/types.ts +312 -0
- package/src/utils/file-utils.ts +81 -0
- package/src/utils/logger.ts +36 -0
- package/src/utils/nested-object.ts +113 -0
- package/src/utils/validation.ts +69 -0
- package/tryme.js +8 -0
- package/tsconfig.json +71 -0
- package/types/cli.d.ts +3 -0
- package/types/cli.d.ts.map +1 -0
- package/types/config.d.ts +50 -0
- package/types/config.d.ts.map +1 -0
- package/types/extractor/core/extractor.d.ts +66 -0
- package/types/extractor/core/extractor.d.ts.map +1 -0
- package/types/extractor/core/key-finder.d.ts +31 -0
- package/types/extractor/core/key-finder.d.ts.map +1 -0
- package/types/extractor/core/translation-manager.d.ts +31 -0
- package/types/extractor/core/translation-manager.d.ts.map +1 -0
- package/types/extractor/index.d.ts +8 -0
- package/types/extractor/index.d.ts.map +1 -0
- package/types/extractor/parsers/ast-visitors.d.ts +235 -0
- package/types/extractor/parsers/ast-visitors.d.ts.map +1 -0
- package/types/extractor/parsers/comment-parser.d.ts +24 -0
- package/types/extractor/parsers/comment-parser.d.ts.map +1 -0
- package/types/extractor/parsers/jsx-parser.d.ts +35 -0
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -0
- package/types/extractor/plugin-manager.d.ts +37 -0
- package/types/extractor/plugin-manager.d.ts.map +1 -0
- package/types/extractor.d.ts +7 -0
- package/types/extractor.d.ts.map +1 -0
- package/types/heuristic-config.d.ts +10 -0
- package/types/heuristic-config.d.ts.map +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/init.d.ts +29 -0
- package/types/init.d.ts.map +1 -0
- package/types/linter.d.ts +33 -0
- package/types/linter.d.ts.map +1 -0
- package/types/locize.d.ts +5 -0
- package/types/locize.d.ts.map +1 -0
- package/types/migrator.d.ts +37 -0
- package/types/migrator.d.ts.map +1 -0
- package/types/status.d.ts +20 -0
- package/types/status.d.ts.map +1 -0
- package/types/syncer.d.ts +33 -0
- package/types/syncer.d.ts.map +1 -0
- package/types/types-generator.d.ts +29 -0
- package/types/types-generator.d.ts.map +1 -0
- package/types/types.d.ts +268 -0
- package/types/types.d.ts.map +1 -0
- package/types/utils/file-utils.d.ts +61 -0
- package/types/utils/file-utils.d.ts.map +1 -0
- package/types/utils/logger.d.ts +34 -0
- package/types/utils/logger.d.ts.map +1 -0
- package/types/utils/nested-object.d.ts +71 -0
- package/types/utils/nested-object.d.ts.map +1 -0
- package/types/utils/validation.d.ts +47 -0
- package/types/utils/validation.d.ts.map +1 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a nested value in an object using a key path and separator.
|
|
3
|
+
* Creates intermediate objects as needed.
|
|
4
|
+
*
|
|
5
|
+
* @param obj - The target object to modify
|
|
6
|
+
* @param path - The key path (e.g., 'user.profile.name')
|
|
7
|
+
* @param value - The value to set
|
|
8
|
+
* @param keySeparator - The separator to use for splitting the path, or false for flat keys
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const obj = {}
|
|
13
|
+
* setNestedValue(obj, 'user.profile.name', 'John', '.')
|
|
14
|
+
* // Result: { user: { profile: { name: 'John' } } }
|
|
15
|
+
*
|
|
16
|
+
* // With flat keys
|
|
17
|
+
* setNestedValue(obj, 'user.name', 'Jane', false)
|
|
18
|
+
* // Result: { 'user.name': 'Jane' }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function setNestedValue(obj: Record<string, any>, path: string, value: any, keySeparator: string | false): void;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a nested value from an object using a key path and separator.
|
|
24
|
+
*
|
|
25
|
+
* @param obj - The object to search in
|
|
26
|
+
* @param path - The key path (e.g., 'user.profile.name')
|
|
27
|
+
* @param keySeparator - The separator to use for splitting the path, or false for flat keys
|
|
28
|
+
* @returns The found value or undefined if not found
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const obj = { user: { profile: { name: 'John' } } }
|
|
33
|
+
* const name = getNestedValue(obj, 'user.profile.name', '.')
|
|
34
|
+
* // Returns: 'John'
|
|
35
|
+
*
|
|
36
|
+
* // With flat keys
|
|
37
|
+
* const flatObj = { 'user.name': 'Jane' }
|
|
38
|
+
* const name = getNestedValue(flatObj, 'user.name', false)
|
|
39
|
+
* // Returns: 'Jane'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function getNestedValue(obj: Record<string, any>, path: string, keySeparator: string | false): any;
|
|
43
|
+
/**
|
|
44
|
+
* Extracts all nested keys from an object, optionally with a prefix.
|
|
45
|
+
* Recursively traverses the object structure to build a flat list of key paths.
|
|
46
|
+
*
|
|
47
|
+
* @param obj - The object to extract keys from
|
|
48
|
+
* @param keySeparator - The separator to use for joining keys, or false for flat keys
|
|
49
|
+
* @param prefix - Optional prefix to prepend to all keys
|
|
50
|
+
* @returns Array of all nested key paths
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const obj = {
|
|
55
|
+
* user: {
|
|
56
|
+
* profile: { name: 'John', age: 30 },
|
|
57
|
+
* settings: { theme: 'dark' }
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* const keys = getNestedKeys(obj, '.')
|
|
62
|
+
* // Returns: ['user.profile.name', 'user.profile.age', 'user.settings.theme']
|
|
63
|
+
*
|
|
64
|
+
* // With flat keys
|
|
65
|
+
* const flatObj = { 'user.name': 'Jane', 'user.age': 25 }
|
|
66
|
+
* const flatKeys = getNestedKeys(flatObj, false)
|
|
67
|
+
* // Returns: ['user.name', 'user.age']
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function getNestedKeys(obj: object, keySeparator: string | false, prefix?: string): string[];
|
|
71
|
+
//# sourceMappingURL=nested-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nested-object.d.ts","sourceRoot":"","sources":["../../src/utils/nested-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,GAAG,EACV,YAAY,EAAE,MAAM,GAAG,KAAK,GAC3B,IAAI,CAcN;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GAAG,KAAK,GAC3B,GAAG,CAKL;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,KAAK,EAAE,MAAM,SAAK,GAAG,MAAM,EAAE,CAa/F"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { I18nextToolkitConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the extractor configuration to ensure required fields are present and properly formatted.
|
|
4
|
+
*
|
|
5
|
+
* This function performs the following validations:
|
|
6
|
+
* - Ensures extract.input is specified and non-empty
|
|
7
|
+
* - Ensures extract.output is specified
|
|
8
|
+
* - Ensures locales array is specified and non-empty
|
|
9
|
+
* - Ensures extract.output contains the required {{language}} placeholder
|
|
10
|
+
*
|
|
11
|
+
* @param config - The i18next toolkit configuration object to validate
|
|
12
|
+
*
|
|
13
|
+
* @throws {ExtractorError} When any validation rule fails
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* try {
|
|
18
|
+
* validateExtractorConfig(config)
|
|
19
|
+
* console.log('Configuration is valid')
|
|
20
|
+
* } catch (error) {
|
|
21
|
+
* console.error('Invalid configuration:', error.message)
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateExtractorConfig(config: I18nextToolkitConfig): void;
|
|
26
|
+
/**
|
|
27
|
+
* Custom error class for extraction-related errors.
|
|
28
|
+
* Provides additional context like file path and underlying cause.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* throw new ExtractorError('Failed to parse file', 'src/component.tsx', syntaxError)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ExtractorError extends Error {
|
|
36
|
+
readonly file?: string | undefined;
|
|
37
|
+
readonly cause?: Error | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new ExtractorError with optional file context and cause.
|
|
40
|
+
*
|
|
41
|
+
* @param message - The error message
|
|
42
|
+
* @param file - Optional file path where the error occurred
|
|
43
|
+
* @param cause - Optional underlying error that caused this error
|
|
44
|
+
*/
|
|
45
|
+
constructor(message: string, file?: string | undefined, cause?: Error | undefined);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,uBAAuB,CAAE,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAgB3E;AAED;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAUrB,IAAI,CAAC,EAAE,MAAM;aACb,KAAK,CAAC,EAAE,KAAK;IAV/B;;;;;;OAMG;gBAED,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC"}
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import swc from 'unplugin-swc'
|
|
3
|
+
import { defineConfig } from 'vitest/config'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
test: {
|
|
7
|
+
// Make vitest globals like `describe` and `it` available without importing
|
|
8
|
+
globals: true,
|
|
9
|
+
// Look for test files in the entire project
|
|
10
|
+
root: './',
|
|
11
|
+
},
|
|
12
|
+
plugins: [swc.vite()]
|
|
13
|
+
})
|