JSON manipulation utilities for nested i18n structures. Handles flattening, unflattening, deep merging, and ICU message detection.
- Source
Methods
(inner) flattenJson(obj, prefixopt, resultopt) → {Record.<string, string>}
Flattens nested JSON to dot-notation keys
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj | Object | |||
prefix | string | <optional> | '' | |
result | Object | <optional> | {} |
- Source
Returns:
- Type:
- Record.<string, string>
Example
flattenJson({ user: { name: 'John' } }) // { 'user.name': 'John' }(inner) isICUMessage(value) → {boolean}
Detects ICU MessageFormat syntax (plural, select, selectordinal)
Parameters:
| Name | Type | Description |
|---|---|---|
value | * |
- Source
Returns:
- Type:
- boolean
(inner) mergeDeep(target, source) → {Object}
Deep merges source into target, preserving existing values
Parameters:
| Name | Type | Description |
|---|---|---|
target | Object | |
source | Object |
- Source
Returns:
- Type:
- Object
(async, inner) readJsonFile(filePath, verboseopt) → {Promise.<(Object|null)>}
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filePath | string | |||
verbose | boolean | <optional> | false |
- Source
Returns:
- Type:
- Promise.<(Object|null)>
(inner) readJsonFileSync(filePath, verboseopt) → {Object|null}
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
filePath | string | |||
verbose | boolean | <optional> | false |
- Source
Returns:
- Type:
- Object |
null
(inner) unflattenJson(obj) → {Object}
Restores nested structure from dot-notation keys
Parameters:
| Name | Type | Description |
|---|---|---|
obj | Record.<string, string> |
- Source
Returns:
- Type:
- Object
Example
unflattenJson({ 'user.name': 'John' }) // { user: { name: 'John' } }(async, inner) writeJsonFile(filePath, data) → {Promise.<void>}
Parameters:
| Name | Type | Description |
|---|---|---|
filePath | string | |
data | Object |
- Source
Returns:
- Type:
- Promise.<void>