10 examples of 'camelcase in javascript' in JavaScript

Every line of 'camelcase in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
88function camelCase(string) {
89 return string.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (match, letter) {
90 return letter.toUpperCase()
91 })
92}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12export function camelCase (str) {
13 return kebabCase(str).replace(/-([a-z])/g, (whole, ch) => ch.toUpperCase())
14}
44export function camelCase(str) {
45 return str.replace(/-(\w)/g, ($, $1) => {
46 return $1.toUpperCase()
47 })
48}
38function camelCase (str) {
39 return str
40 .replace(/_/g, (_, index) => index === 0 ? _ : '-')
41 .replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) =>
42 index === 0 ? letter.toLowerCase() : letter.toUpperCase()
43 )
44 .replace(invalidChars, '')
45}
11function camelCase(str) {
12 return str.replace(/-(\w)/g, (_, letter) => {
13 return letter.toUpperCase();
14 })
15}
85export function camelCase(str: string, upper: boolean = false): string {
86 return str.replace(/(?:^\w|[A-Z]|\b\w|\s+|-+|_+)/g, function(match, index) {
87 if (+match === 0 || match[0] === '-') {
88 return '';
89 } else if (index === 0 && !upper) {
90 return match.toLowerCase();
91 } else {
92 return match.toUpperCase();
93 }
94 });
95}
4function camelCase(value: string): string {
5 return value.replace(/-([a-z0-9])/giu, (match, char) => char.toUpperCase());
6}
38function camelCase (s) {
39 return s.replace(/([\-_\s]+[a-z])|(^[a-z])/g, $1 => $1.toUpperCase())
40 .replace(/[\-_\s]+/g, '')
41}
7function camelCase(str) {
8 // Replace special characters with a space
9 str = str.replace(/[^a-zA-Z0-9 ]/g, ' ');
10 // put a space before an uppercase letter
11 str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
12 // Lower case first character and some other stuff
13 str = str.replace(/([^a-zA-Z0-9 ])|^[0-9]+/g, '').trim().toLowerCase();
14 // uppercase characters preceded by a space or number
15 str = str.replace(/([ 0-9]+)([a-zA-Z])/g, function (a, b, c) {
16 return b.trim() + c.toUpperCase();
17 });
18 return str;
19}
124function convertToCamelCase(key) {
125 return key.replace(/_(.)/g, (match, group1) => {
126 return group1.toUpperCase();
127 });
128}

Related snippets