Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xadillax/otrans
Object key transformation for Node.js.
https://github.com/xadillax/otrans
Last synced: 29 days ago
JSON representation
Object key transformation for Node.js.
- Host: GitHub
- URL: https://github.com/xadillax/otrans
- Owner: XadillaX
- License: mit
- Created: 2016-06-22T08:43:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-08T11:22:58.000Z (over 6 years ago)
- Last Synced: 2024-10-09T13:24:12.848Z (about 1 month ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Otrans
[![Otrans](http://img.shields.io/npm/v/otrans.svg)](https://www.npmjs.org/package/otrans)
[![Otrans](http://img.shields.io/npm/dm/otrans.svg)](https://www.npmjs.org/package/otrans)
[![Build Status](https://travis-ci.org/XadillaX/otrans.svg?branch=master)](https://travis-ci.org/XadillaX/otrans)
[![Coverage Status](https://img.shields.io/coveralls/XadillaX/otrans/master.svg)](https://coveralls.io/r/XadillaX/otrans?branch=master)
[![License](https://img.shields.io/npm/l/otrans.svg?style=flat)](https://www.npmjs.org/package/otrans)
[![Dependency Status](https://david-dm.org/XadillaX/otrans.svg)](https://david-dm.org/XadillaX/otrans)Object key transformation for Node.js.
## Installation
```sh
$ npm install --save -d otrans
```## Usage
```js
const otrans = require("otrans");
```### .toCamel
```js
otrans.toCamel({
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
});// {
// "glossary": {
// "title": "example glossary",
// "glossDiv": {
// "title": "S",
// "glossList": {
// "glossEntry": {
// "id": "SGML",
// "sortAs": "SGML",
// "glossTerm": "Standard Generalized Markup Language",
// "acronym": "SGML",
// "abbrev": "ISO 8879:1986",
// "glossDef": {
// "para": "A meta-markup language, used to create markup languages such as DocBook.",
// "glossSeeAlso": [
// "GML",
// "XML"
// ]
// },
// "glossSee": "markup"
// }
// }
// }
// }
// }
```### .toUnderscore
```js
otrans.toUnderscore({
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
});// {
// "glossary": {
// "title": "example glossary",
// "gloss_div": {
// "title": "S",
// "gloss_list": {
// "gloss_entry": {
// "id": "SGML",
// "sort_as": "SGML",
// "gloss_term": "Standard Generalized Markup Language",
// "acronym": "SGML",
// "abbrev": "ISO 8879:1986",
// "gloss_def": {
// "para": "A meta-markup language, used to create markup languages such as DocBook.",
// "gloss_see_also": [
// "GML",
// "XML"
// ]
// },
// "gloss_see": "markup"
// }
// }
// }
// }
// }
```> **Hint**: The second parameter of `toCamel` or `toUnderscore` is a force transformation key map.
>
> eg. if you're going to transform object like this:
>
> ```js
> otrans.toUnderscore({ jar2proxy: true, keepRunning: true });
> ```
>
> You'll get `{ "jar_2_proxy": true, "keep_running": true }`. But if you do like this:
>
> ```js
> otrans.toUnderscore({ jar2proxy: true, keepRunning: true }, { jar2proxy: proxy2jar });
> ```
>
> You'll get `{ "proxy2jar": true, "keep_running": true }` then.## Contribute
You're welcome to make pull requests!
「雖然我覺得不怎麼可能有人會關注我」