npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

changecase-objects

v1.1.0

Published

Convert an object's keys to any case

Downloads

256

Readme

changecase-objects

Convert an object's keys to different cases

Installation

$ npm install --save changecase-objects

Usage

var changeKeys = require('changecase-objects')

changeKeys.snakeCase({ fooBar: 'baz' })
// returns { foo_bar: 'baz' }

changeKeys.snakeCase({ 'foo-bar': true, nested: { fooBaz: 'bar' }})
// returns { foo_bar: true, nested: { foo_baz: 'bar' }}

or with imports

import { snakeCase } from 'changecase-objects'

snakeCase({ fooBar: 'baz' })
// returns { foo_bar: 'baz' }

snakeCase({ 'foo-bar': true, nested: { fooBaz: 'bar' }})
// returns { foo_bar: true, nested: { foo_baz: 'bar' }}

API

Extra Options

Every function accepts an optional options object. The following options are currently supported:

| Name | Type | Description | |-------------|-----------------|--------------------------------------------------| | exclude | array<string> | Array of key values to exclude from case change. |

exclude
camelCase({ foo_bar: 'baz', 'filters[foo_bar]': 'val' }, { exclude: ['filters[foo_bar]'] })
// returns { fooBar: 'baz', 'filters[foo_bar]': 'val' }

camelCase

camelCase(obj, [options]) -> Object

Converts keys to a string with the separators denoted by having the next letter capitalized.

camelCase({ 'key name': 'val' })
// returns { keyName: 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into camel case. | | options | Object | No | see options |


CONSTANT_CASE

constantCase(obj, [options]) -> Object

Converts keys to upper case, with an underscore separator.

constantCase({ 'key name': 'val' })
// returns { KEY_NAME: 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into constant case. | | options | Object | No | see options |


dot.case

dotCase(obj, [options]) -> Object

Converts keys to lower case, with a period separator.

dotCase({ 'key name': 'val' })
// returns { 'key.name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into dot case. | | options | Object | No | see options |


Header-Case

headerCase(obj, [options]) -> Object

Converts keys to title case, with a dash separator.

headerCase({ 'key name': 'val' })
// returns { 'Key-Name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into header case. | | options | Object | No | see options |


kebab-case

kebabCase(obj, [options]) -> Object

Converts keys to lower case, with a dash separator.

kebabCase({ 'key name': 'val' })
// returns { 'key-name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into kebab case. | | options | Object | No | see options |


lower case

lowerCase(obj, [options]) -> Object

Converts keys to lower case, with a space separator.

lowerCase({ 'Key Name': 'val' })
// returns { 'key name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into lower case. | | options | Object | No | see options |


PascalCase

pascalCase(obj, [options]) -> Object

Converts keys to camel case, with the first character also capitalized.

pascalCase({ 'key name': 'val' })
// returns { KeyName: 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into pascal case. | | options | Object | No | see options |


path/case

pathCase(obj, [options]) -> Object

Converts keys to lower case, with a slash separator.

pathCase({ 'key name': 'val' })
// returns { 'key/name': 'val' })
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into path case. | | options | Object | No | see options |


Sentence case

sentenceCase(obj, [options]) -> Object

Converts keys to lower case, with a space separator, with the first letter capitalized.

sentenceCase({ 'key name': 'val' })
// returns { 'Key name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into sentence case. | | options | Object | No | see options |


snake_case

snakeCase(obj, [options]) -> Object

Converts keys to lower case, with an underscore separator.

snakeCase({ 'key name': 'val' })
// returns { key_name: 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into snake case. | | options | Object | No | see options |


Title Case

titleCase(obj, [options]) -> Object

Converts keys to lower case with the first letter of each word capitalized, with a space separator.

titleCase({ 'key name': 'val' })
// returns { 'Key Name': 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into title case. | | options | Object | No | see options |


UPPER CASE

upperCase(obj, [options]) -> Object

Converts keys to upper case, with a space separator.

upperCase({ 'key name': 'val' })
// returns { 'KEY NAME: 'val' }
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into upper case. | | options | Object | No | see options |


-cUsToM-cAsE-

customCase(obj, caseFn, [options]) -> Object

Allows for custom casing rules by converting keys according to given function.

customCase({ 'key name': 'val' }, key => transform(key))
// returns keys formatted by `caseFn`
Parameters

| Name | Type | Required | Description | |-------------|-----------------------------|----------|--------------------------------------------------| | obj | Object or array<Object> | Yes | An object to transform keys into upper case. | | caseFn | function(string) -> string| Yes | A function that returns a modified key. | | options | Object | No | see options |