change-key-case
v1.0.0
Published
Change the case for keys in an object with change-case
Downloads
8
Readme
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)