Git Product home page Git Product logo

casing's Introduction

casing

Recursively transform object key strings to and from camelCase and snake_case.

  • Supports objects, arrays and a combination of both in any depth.
  • Was originally intended for use with BookShelf and Knex.

Installation

$ npm install casing

Usage

'use strict';
var casing = require('casing');

var wasCamel = {
  objId: 123,
  myName: 'Slim Shady'
};
console.log(casing.snakeize(wasCamel));
// => { obj_id: 123, my_name: 'Slim Shady' }

var was_snake = {
  obj_id: 456,
  my_name: 'fiddycent'
};
console.log(casing.camelize(was_snake));
// => { objId: 456, myName: 'fiddycent' }

TypeScript

This package includes a definition file for TypeScript.

import { camelize, snakeize } from 'casing';

var wasCamel = { objId: 123 };
snakeize(wasCamel);

var was_snake = { obj_id: 456 };
camelize(was_snake);

License

MIT

casing's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

brunolm

casing's Issues

Add TypeScript definition file

You can add on your package.json

"types": "main.d.ts",

And create this file with the following contents:

/**
 * Deeply converts object keys to camelCase
 */
export declare const camelize: (obj: any) => any;

/**
 * Deeply converts object keys to snake_case
 */
export declare const snakeize: (obj: any) => any;

So when someone using TypeScript install your package they will get some type information (like auto complete to import function names without misspelling)

And then they can use it like this

import { camelize, snakeize } from 'casing';

var wasCamel = { objId: 123 };
snakeize(wasCamel);

var was_snake = { obj_id: 456 };
camelize(was_snake);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.