Skip to content

michaellyu/nameize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nameize

Camelize & Snakeize

Installing

yarn add nameize # npm install nameize

How To Use

const { camelize, snakeize, camelCase, snakeCase } = require('nameize');

const snakeObj = {
  primary_key: 1,
  numbers: [1, 4, 7, 3, 6, 9],
  members: [
    { first_name: 'Jianmi', last_name: 'Wen' },
    { first_name: 'Shayu', last_name: 'Li' },
    { first_name: 'Xujian', last_name: 'Jiang' },
  ],
};

const camelObj = {
  primaryKey: 1,
  numbers: [1, 4, 7, 3, 6, 9],
  members: [
    { firstName: 'Jianmi', lastName: 'Wen' },
    { firstName: 'Shayu', lastName: 'Li' },
    { firstName: 'Xujian', lastName: 'Jiang' },
  ],
};

const obj = camelize(snakeObj); // obj same as camelObj
const obj2 = snakeize(camelObj); // obj2 same as snakeObj
const camelName = camelCase('name_to_name'); // camelName value is 'nameToName'
const snakeName = snakeCase('nameToName'); // snakeName value is 'name_to_name'

Example

const { camelize, snakeize } = require('nameize');

let data;
axios
  .get('path-to-api')
  .then((res) => {
    // Before use
    data = camelize(res.data);
  });

// Before send
const data2 = snakeize(data);
axios
  .post('path-to-api', data2);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published