Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yamadapc/node-translate-object
Translate an object representation into another based on a map.
https://github.com/yamadapc/node-translate-object
Last synced: 15 days ago
JSON representation
Translate an object representation into another based on a map.
- Host: GitHub
- URL: https://github.com/yamadapc/node-translate-object
- Owner: yamadapc
- License: mit
- Created: 2014-04-15T00:02:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T17:58:42.000Z (almost 9 years ago)
- Last Synced: 2024-12-24T11:58:00.966Z (17 days ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
translate-object
================
[![Build Status](https://travis-ci.org/yamadapc/node-translate-object.svg)](https://travis-ci.org/yamadapc/node-translate-object)
[![devDependency Status](https://david-dm.org/yamadapc/node-translate-object/dev-status.svg)](https://david-dm.org/yamadapc/node-translate-object#info=devDependencies)Translate an object representation into another based on a map. This makes it
possible to parse objects into better (or common) structures, through
configuration, rather than programmatically - which is a good thing, IMHO.## Installation
Install the package with: `npm install translate-object`.
Then:
```javascript
var translate = require('translate-object');
```It hasn't been tested but should work fine on a browser. You can use it with
browserify :).## Usage
It works with simple keys:
```javascript
translate({ 'key1': 'something' }, { something: 'value' }),
// => { key1: 'value' }
```It works with nested keys:
```javascript
translate({ key1: 'something.nested' }, { something: { nested: 'here' } }),
// => { key1: 'here' }
```It works with array indexes:
```javascript
translate({ key1: 'something.1' }, { something: [1, 'value'] }),
// => { key1: 'value' }
```It works with mixed input:
```javascript
translate(
{ 'key1': 'something', 'key2': 'nested.severally', key3: 'array.1' },
{ something: 'value', nested: { severally: 'here' }, array: [1, 2] }
),
// => { key1: 'value', key2: 'here', key3: 2 }
```And the maps may be complex objects too:
```javascript
translate(
{ key1: ['an-array.2', 'an-array.1'],
key2: { alternative: 'syntax', here: 'hell' } },
{ 'an-array': [1, 'value', 3], syntax: 'ugly', hell: 'bleh' }
),
// => { key1: [ 3, 'value' ], key2: { alternative: 'ugly', here: 'bleh' } }
```## License
Copyright (c) 2014 Pedro Yamada. Licensed under the MIT license.## Donations
Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y