ypotryll
v0.2.1
Published
A package for converting between variable naming conventions.
Downloads
8
Readme
Ypotryll
A package for converting between variable naming conventions.
This package is especially helpful when you are using a web app stack with both Ruby and Javascript. With Javascript using camel case as its variable naming convention, and Ruby using snake case, it is useful to have a tool to translate between the two.
Installation
npm install ypotryll
Examples
convert(string, from, to)
This is used to translate a string from one case to another.
string
: the string to be convertedfrom
: A string stating the type converting from- available options:
camel
,constant
,pascal
,snake
- available options:
to
: A string stating the type converting to- available options:
camel
,constant
,pascal
,snake
,trim
- available options:
var ypotryll = require('ypotryll');
var camelText = 'lookSomeCamelText';
var pascalText = ypotryll.convert(camelText, 'camel', 'pascal');
/*
* LookSomeCamelText
*/
convertParams(object, from, to)
This is used to translate a objects keys from one case to another. An appropriate place to use this before sending a JSON object to a Ruby on Rails API endpoint.
object
: the object whose keys are to be convertedfrom
: A string stating the type converting from- available options:
camel
,constant
,pascal
,snake
- default:
camel
- available options:
to
: A string stating the type converting to- available options:
camel
,constant
,pascal
,snake
,trim
- default:
snake
- available options:
var ypotryll = require('ypotryll');
var contacts = [{
name: 'Jenny',
phoneNumbers: [
{
phoneNumber: '867-5309'
}
],
}];
var snakeParams = ypotryll.convertParams(contacts);
/*
* [
* {
* name: 'Jenny',
* phone_numbers: [
* {
* phone_number: '867-5309',
* },
* ],
* },
* ]
*/
Contribute
Want to contribute? Awesome! Check out our contributing file.
License
MIT Licensed. Copyright (c) Will Olson 2017.