data-format
The best and performative way to convert naming conventions like: snake_case, camelCase, flatcase, kebab-case
Hey everyone!
If you need help maintaining the naming convention in your application, this library is perfect for you. The data-format gives you methods to convert the naming convention, like snake_case, camelCase, flatcase, kebab-case.
import { camelToSnake } from '@ballin-team/data-format';
const user = { id: 1, firstName: 'John', lastName: 'Cena'};
const snakeObject = camelToSnake(user);
console.log(snakeObject); // { id: 1, first_name: 'John', last_name: 'Cena'}
import { camelToFlat } from '@ballin-team/data-format';
const user = { id: 3, firstName: 'Undertaker', lastName: null };
const flatObject = camelToFlat(user);
console.log(flatObject); // { id: 3, firstname: 'Undertaker', lastname: null }
import { camelToKebab } from '@ballin-team/data-format';
const user = { id: 3, firstName: 'Undertaker', lastName: null };
const kebabObject = camelToKebab(user);
console.log(kebabObject); // { id: 3, 'first-name': 'Undertaker', 'last-name': null }
import { snakeToCamel } from '@ballin-team/data-format';
const user = { id: 2, first_name: 'Rey', last_name: 'Mysterio'};
const camelObject = snakeToCamel(user);
console.log(camelObject); // { id: 2, firstName: 'Rey', lastName: 'Mysterio'}
import { snakeToFlat } from '@ballin-team/data-format';
const user = { id: 3, first_name: 'Undertaker', last_name: null };
const flatObject = snakeToFlat(user);
console.log(flatObject); // { id: 3, firstname: 'Undertaker', lastname: null }
import { snakeToKebab } from '@ballin-team/data-format';
const user = { id: 3, first_name: 'Undertaker', last_name: null };
const kebabObject = snakeToKebab(user);
console.log(kebabObject); // { id: 3, 'first-name': 'Undertaker', 'last-name': null }
import { kebabToSnake } from '@ballin-team/data-format';
const user = { id: 3, 'first-name': 'Undertaker', 'last-name': null };
const snakeObject = kebabToSnake(user);
console.log(snakeObject); // { id: 3, first_name: 'Undertaker', last_name: null }
import { kebabToCamel } from '@ballin-team/data-format';
const user = { id: 3, 'first-name': 'Undertaker', 'last-name': null };
const camelObject = kebabToCamel(user);
console.log(camelObject); // { id: 3, firstName: 'Undertaker', lastName: null }
For huge data with repetitive key names you can pass the argument useCache as true to avoid convert the same key many times.
import { snakeToCamel } from '@ballin-team/data-format';
const users = [
{ id: 1, first_name: 'John', last_name: 'Cena'},
{ id: 2, first_name: 'Rey', last_name: 'Mysterio'},
...,
];
const hugeAndRepeatedKeys = snakeToCamel(users, true); // [{ id: 1, firstName: 'John', lastName: 'Cena'}, { id: 2, firstName: 'Rey', lastName: 'Mysterio'}, ...]