https://github.com/andre-araujo/object-keys-parser
https://github.com/andre-araujo/object-keys-parser
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/andre-araujo/object-keys-parser
- Owner: andre-araujo
- Created: 2017-09-22T16:56:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T12:34:51.000Z (almost 8 years ago)
- Last Synced: 2025-10-12T05:46:09.379Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Object Keys Parser
A small lib to translate object keys.
## Why?
We can not predict the response of each api with which we work, sometimes we must deal with responses in different languages, or we simply need to normalize some objects keys to fit the application better.
## Install
```npm install object-keys-parser --save```
## Usage
Import ObjectParser:
```javascript
import ObjectParser from 'object-keys-parser'
```
Create a dictionary:
```javascript
const adventureDictionary = {
human: 'finn',
dog: 'jake',
vampire: 'marceline'
}
```
Then instantiate a ObjectParser using the dictionary:
```javascript
const adventureParser = new ObjectParser(adventureDictionary)
```
Now you can normalize the object keys or revert the keys to normal:
```javascript
const items = {
human: 'sword',
dog: null,
vampire: 'axe'
}
adventureParser.parse(items);
/* output:
{
finn: 'sword',
jake: null,
marceline: 'axe'
}
*/
```
```javascript
const items = {
finn: 'sword',
jake: null,
marceline: 'axe'
}
adventureParser.revert(items);
/* output:
{
human: 'sword',
dog: null,
vampire: 'axe'
}
*/
```
It also translate keys recursively:
```javascript
const friends = {
human: {
dog: null
}
}
adventureParser.parse(friends);
/* output:
{
finn: {
jake: null
}
}
*/
```