@queso/camel-case
Version:
Converts a string value into camel case.
59 lines (42 loc) • 4.03 kB
text/mdx
---
name: camel-case
menu: String
route: /camel-case
---
import { Link } from 'docz'
import Editor from '../../src/components/Editor'
# camel-case
[](https://nodei.co/npm/@queso/camel-case/)
<svg width="151.3" height="20" viewBox="0 0 1513 200" xmlns="http://www.w3.org/2000/svg">
<g>
<rect fill="#555" width="864" height="200"/>
<rect fill="#08C" x="864" width="649" height="200"/>
</g>
<g fill="#fff" textAnchor="start" fontFamily="Verdana,DejaVu Sans,sans-serif" fontSize="110">
<text x="220" y="148" textLength="604" fill="#000" opacity="0.1">min + gzip</text>
<text x="210" y="138" textLength="604">min + gzip</text>
<text x="919" y="148" textLength="549" fill="#000" opacity="0.1">224 bytes</text>
<text x="909" y="138" textLength="549">224 bytes</text>
</g>
<image x="40" y="35" width="130" height="132" href="https://queso.surge.sh/public/favicon.png"/>
</svg>
[source](https://github.com/jedmao/queso/blob/master/src/packages/camel-case/camelCase.ts)
Converts a string value into [camel case](https://en.wikipedia.org/wiki/Camel_case).
## Playground
<Editor
jsFunc="var%20camelCase%20%3D%20%28function%20%28%29%20%7B%0A%09%27use%20strict%27%3B%0A%0A%09const%20allCapitalLetterGroups%20%3D%20/%5BA-Z%C0-%D6%D9-%DD%5D+/g%3B%0A%09const%20allWords%20%3D%20/%5BA-Z%C0-%D6%D9-%DDa-z%E0-%F6%F9-%FD%5D+/g%3B%0A%09/**%0A%09%20*%09Converts%20a%20string%20value%20into%20%5Bcamel%20case%5D%28https%3A//en.wikipedia.org/wiki/Camel_case%29.%0A%09%20*%20@param%20value%20The%20string%20to%20convert.%0A%09%20*%20@category%20String%0A%09%20*%20@returns%20The%20camel-cased%20string.%0A%09%20*%20@example%0A%09camelCase%28%27foo-bar-baz%27%29%0A%09//%20%3D%3E%20%27fooBarBaz%27%0A%09%20*/%0A%09function%20camelCase%28value%29%20%7B%0A%09%09const%20words%20%3D%20value%0A%09%09%09.replace%28allCapitalLetterGroups%2C%20valleyCase%29%0A%09%09%09.match%28allWords%29%3B%0A%09%09return%20words%0A%09%09%09%3F%20words%5B0%5D%5B0%5D.toLowerCase%28%29%20+%0A%09%09%09%09%09words%0A%09%09%09%09%09%09.map%28x%20%3D%3E%20x%5B0%5D.toUpperCase%28%29%20+%20x.slice%281%29%29%0A%09%09%09%09%09%09.join%28%27%27%29%0A%09%09%09%09%09%09.slice%281%29%0A%09%09%09%3A%20%27%27%0A%09%09function%20valleyCase%28s%29%20%7B%0A%09%09%09return%20s.length%20%3E%202%0A%09%09%09%09%3F%20s%5B0%5D%20+%20s.slice%281%2C%20-1%29.toLowerCase%28%29%20+%20s.slice%28-1%29%0A%09%09%09%09%3A%20s%0A%09%09%7D%0A%09%7D%0A%0A%09return%20camelCase%3B%0A%0A%7D%28%29%29%3B%0A"
tsFunc="const%20allCapitalLetterGroups%20%3D%20/%5BA-Z%C0-%D6%D9-%DD%5D+/g%0Aconst%20allWords%20%3D%20/%5BA-Z%C0-%D6%D9-%DDa-z%E0-%F6%F9-%FD%5D+/g%0A%0A/**%0A%20*%09Converts%20a%20string%20value%20into%20%5Bcamel%20case%5D%28https%3A//en.wikipedia.org/wiki/Camel_case%29.%0A%20*%20@param%20value%20The%20string%20to%20convert.%0A%20*%20@category%20String%0A%20*%20@returns%20The%20camel-cased%20string.%0A%20*%20@example%0AcamelCase%28%27foo-bar-baz%27%29%0A//%20%3D%3E%20%27fooBarBaz%27%0A%20*/%0Afunction%20camelCase%28value%3A%20string%29%20%7B%0A%09const%20words%20%3D%20value%0A%09%09.replace%28allCapitalLetterGroups%2C%20valleyCase%29%0A%09%09.match%28allWords%29%0A%09return%20words%0A%09%09%3F%20words%5B0%5D%5B0%5D.toLowerCase%28%29%20+%0A%09%09%09%09words%0A%09%09%09%09%09.map%28x%20%3D%3E%20x%5B0%5D.toUpperCase%28%29%20+%20x.slice%281%29%29%0A%09%09%09%09%09.join%28%27%27%29%0A%09%09%09%09%09.slice%281%29%0A%09%09%3A%20%27%27%0A%0A%09function%20valleyCase%28s%3A%20string%29%20%7B%0A%09%09return%20s.length%20%3E%202%0A%09%09%09%3F%20s%5B0%5D%20+%20s.slice%281%2C%20-1%29.toLowerCase%28%29%20+%20s.slice%28-1%29%0A%09%09%09%3A%20s%0A%09%7D%0A%7D%0A"
value="camelCase%28%27foo-bar-baz%27%29%3B%0A"
/>
### Result
<div id="editor-result" />
## Parameters
| Name | Type | Description |
| :------ | :------- | :--------------------- |
| `value` | `string` | The string to convert. |
## Returns
The camel-cased string.
### Return type
```ts
string
```