change-key-case

1.0.0 • Public • Published

change-key-case

A wrapper around change-case that changes the keys of an object.

Installation

npm i change-key-case

Usage

Possible cases: camel, constant, dot, header, lower, no, param, pascal, path, sentence, snake, swap, title, upper.

import changeKeyCase from "change-key-case"

changeKeyCase("sentence")({someProperty: true})
// =>  {"Some property": true}

changeKeyCase("sentence", {someProperty: true})
// =>  {"Some property": true}


// can be useful with console.table
const sentenceCase = changeKeyCase("sentence")
console.table(
  [
    {id: "1234", photoService: "flickr"},
    {id: "abcd", photoService: "unsplash"},
  ].map(sentenceCase)
)
// =>
// Id   Photo service
// ---- -------------
// 1234 flick
// abcd unsplash

// or to change api responses with snake case to camel case
const camelCase = changeKeyCase("camel")
fetch("/api/things")
  .then(response => response.json())
  .then(camelCase)

Readme

Keywords

Package Sidebar

Install

npm i change-key-case

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.48 kB

Total Files

6

Last publish

Collaborators

  • relekang