Socket
Book a DemoInstallSign in
Socket

object-case-converter

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-case-converter

Convert keys in an javascript object for some cases(camelCase, snake_case, etc.)

1.0.4
latest
Source
npmnpm
Version published
Maintainers
4
Created
Source

object-case-converter

Greenkeeper badge

Convert keys in an javascript Object or Array to the specific forms(camelCase, snake_case, etc.)

Installation

$ npm install --save object-case-converter

Usage

ES6

import { camelCase, snakeCase } from 'object-case-converter';

const result1 = camelCase(null);
// result1 = null

const result2 = camelCase({
    id: '1',
    nick_name: 'nick1',
    contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }],
    news_letter: { all_email: false, marketing_email: false },
});
// result2 = {
//    id: '1',
//    nickName: 'nick1',
//    contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }],
//    newsLetter: { all_email: false, marketing_email: false },
//}

const result3 = snakeCase([
    { id: '1', nickName: 'nick1', contacts: [{ contactType: 'phone', value: '000-000-000' }, { contactType: 'email', value: 'test@email.com' }] },
    { id: '2', nickName: 'nick2', contacts: [] },
    { id: '3', nickName: 'nick3', contacts: [{ contactType: 'address', value: 'xxx' }] },
], true);
// result3 = [
//    { id: '1', nick_name: 'nick1', contacts: [{ contact_type: 'phone', value: '000-000-000' }, { contact_type: 'email', value: 'test@email.com' }] },
//    { id: '2', nick_name: 'nick2', contacts: [] },
//    { id: '3', nick_name: 'nick3', contacts: [{ contact_type: 'address', value: 'xxx' }] },
//]

ES5

var converter = require('object-case-converter');

converter.camelCase(...);
converter.snakeCase(...);

Methods

camelCase(objectOrArray, isRecursive = false)

Convert keys in an object or objects in an array to camelCase

  • objectOrArray [Object|Array] - object or array to be converted
  • isRecursive [boolean] - If it is true, this function works as recursive way

snakeCase(objectOrArray, isRecursive = false)

Convert keys in an object or objects in an array to snake_case

  • objectOrArray [Object|Array] - object or array to be converted
  • isRecursive [boolean] - If it is true, this function works as recursive way

Development

$ git clone git@github.com:ridibooks/object-case-converter.git
$ cd object-case-converter
$ npm install

Build

Webpack build using Babel (Not required in development.)

$ npm run build

Test

Tests using Jest

$ npm test

Keywords

converter

FAQs

Package last updated on 21 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.