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

keys-converter

v3.0.4

Published

This package provide a util function to convert snake case object keys to camel case

Downloads

357

Readme

Snake Case to Camel Case

A lib to convert object keys to camel-case or snake-case.

npm i keys-converter 

# or 

yarn add keys-converter

Use on browser

<script src="https://cdn.jsdelivr.net/npm/[email protected]/bundle/index.min.js"></script>
<script type="module">
	
	import { objectKeysToCamelCaseV2, objectKeysToSnakeCaseV2 } from 'https://cdn.skypack.dev/keys-converter';

</script>

Imports


import { objectKeysToSnakeCaseV2, objectKeysToCamelCaseV2 } from 'keys-converter';

How to use it?

objectKeysToCamelCaseV2 and objectKeysToSnakeCaseV2

Two available functions

  • convert object keys from snake_case to camelCase

import { objectKeysToCamelCaseV2 } from 'keys-converter';

const user = {
	_id: "sf2309sdf0010",
	company_name: "some name",
	user_password: "some@pass123",
	created_at: "2020-01-01",
	updated_at: "2020-01-01"
};

const result = objectKeysToCamelCaseV2(user);

console.log(result);
> `{
	_id: "sf2309sdf0010",
	companyName: "some name",
	userPassword: "some@pass123",
	createdAt: "2020-01-01",
	updatedAt: "2020-01-01"
  }`

  • convert object keys from camelCase to snake_case

import { objectKeysToSnakeCaseV2} from 'keys-converter';

const user = {
	_id: "sf2309sdf0010",
	companyName: "some name",
	userPassword: "some@pass123",
	createdAt: "2020-01-01",
	updatedAt: "2020-01-01"
};

const result = objectKeysToSnakeCaseV2(user);

console.log(result);
> `{
	_id: "sf2309sdf0010",
	company_name: "some name",
	user_password: "some@pass123",
	created_at: "2020-01-01",
	updated_at: "2020-01-01"
}`

The function objectKeysToCamelCaseV2 receives an object. You can to infer the return type as argument so the result returned will have types

Inference result and input

const user = {
	_id: "sf2309sdf0010",
	companyName: "some name",
	userPassword: "some@pass123",
	createdAt: "2020-01-01",
	updatedAt: "2020-01-01"
};

/** Dynamic Type */
interface ResultType {
	_id: string;
	company_name: string,
	user_password: string,
	created_at: "2020-01-01",
	updated_at: "2020-01-01"
}

const result = objectKeysToSnakeCaseV2<ResultType>(user);

If you provide the input type the function will validate the arguments, So if you provide the result type the returned value will have "types"


Warning

  • Function does not remove the first underscore for security

example If your object has a protected prop like _id It will keep it