1.0.2 • Published 6 years ago

snakecase-keys-object v1.0.2

Weekly downloads
197
License
ISC
Repository
github
Last release
6 years ago

snakecase-keys-object

NPM version NPM downloads

Snakecase the keys of an object. Use for node.js and browser

It is useful for oracledb.

Installation

$ npm install --save snakecase-keys-object

or

$ yarn add snakecase-keys-object

Usage

Node.JS

const snakeKeys = require('snakecase-keys-object');

const object = {
	camelCase: 1,
	UPPERCASE: 2,
	lowercase: 3,
	snake_case: 4,
	PascalCase: 5,
	'Title Case': 6,
	'dot.case': 7,
	'param-case': 8,
	'Sentence case': 9,
	'path/case': 10,
	'Header-Case': 11
};

const res = snakeKeys(object);

console.log(res);
/**
 { camel_case: 1,
   uppercase: 2,
   lowercase: 3,
   snake_case: 4,
   pascal_case: 5,
   title_case: 6,
   dot_case: 7,
   param_case: 8,
   sentence_case: 9,
   path_case: 10,
   header_case: 11 }
 */

console.log(snakeKeys(null)); // null
console.log(snakeKeys(undefined)); // null

Browser

1. NPM Package
<script src="./node_modules/snakecase-keys-object/dist/snakecase-keys-object.js"></script>
<!-- Or use minified-->
<script src="./node_modules/snakecase-keys-object/dist/snakecase-keys-object.min.js"></script>
2. Download from source
<script src="path/to/snakecase-keys-object"></script>
Usage
<script>
	const object = {
		camelCase: 1,
		UPPERCASE: 2,
		lowercase: 3,
		snake_case: 4,
		PascalCase: 5,
		'Title Case': 6,
		'dot.case': 7,
		'param-case': 8,
		'Sentence case': 9,
		'path/case': 10,
		'Header-Case': 11
	};

	const res = snakeKeys(object);

	console.log(res);
	console.log(snakeKeys(null)); // null
	console.log(snakeKeys(undefined)); // null
</script>

API

snakeKeys(object)

Returns a new object which keys is/are snakecased.

Related