MCPcopy Create free account
hub / github.com/grid-js/gridjs / camelCase

Function camelCase

src/util/string.ts:1–22  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

1export function camelCase(str: string): string {
2 if (!str) return '';
3
4 const words = str.split(' ');
5
6 // do not convert strings that are already in camelCase format
7 if (words.length === 1 && /([a-z][A-Z])+/g.test(str)) {
8 return str;
9 }
10
11 return words
12 .map(function (word, index) {
13 // if it is the first word, lowercase all the chars
14 if (index == 0) {
15 return word.toLowerCase();
16 }
17
18 // if it is not the first word only upper case the first char and lowercase the rest
19 return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
20 })
21 .join('');
22}

Callers 2

setIDMethod · 0.90
string.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…