Otrans
Object key transformation for Node.js.
Installation
$ npm install --save -d otrans
Usage
const otrans = ;
.toCamel
otrans; // {// "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
otrans; // {// "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
ortoUnderscore
is a force transformation key map.eg. if you're going to transform object like this:
otrans;You'll get
{ "jar_2_proxy": true, "keep_running": true }
. But if you do like this:otrans;You'll get
{ "proxy2jar": true, "keep_running": true }
then.
Contribute
You're welcome to make pull requests!
「雖然我覺得不怎麼可能有人會關注我」