0.2.1 • Published 7 years ago

ypotryll v0.2.1

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

Ypotryll

npm version PRs Welcome

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 converted
  • from: A string stating the type converting from
    • available options: camel, constant, pascal, snake
  • to: A string stating the type converting to
    • available options: camel, constant, pascal, snake, trim
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 converted
  • from: A string stating the type converting from
    • available options: camel, constant, pascal, snake
    • default: camel
  • to: A string stating the type converting to
    • available options: camel, constant, pascal, snake, trim
    • default: snake
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.

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago