Camel case is the practice of capitalizing the first letter of each word in a series (excepting first word which starts with lower case letter) and then removing spaces, numbers, underscores, hyphens, and other special characters. This leaves a concatenation of words that is combined into a single string with various letters capitalized throughout.
- The first letter is in lowercase
- Each next word should start with capitalized letter
- The word does not end on a capitalized letter: camelCasE
- No two capitalized letters shall follow directly each other: camelCAse
- No number in that word at any place: CamelCase1more
- No dot(.), underscore (_) or dash (-) within the word, only letters: camel_Case
- No ‘foreign’ letters in it like äöüß or accentuated like áéí. cämélCáße
npm install camel
const camel = require('camel')
// is camelCase
camel.isCamelCase('fooBar') // => true
camel.isCamelCase('foo-bar') // => false
// camelize
camel.camelize('foo-bar') // => 'fooBar'
camel.camelize('foo_bar') // => 'fooBar'
// decamelize
camel.decamelize('fooBar') // => 'foo_bar'
camel.decamelize('fooBar', '-') // => 'foo-bar'
Function that validate if string value is a camel case
Param | Description | Type |
---|---|---|
value | String value to validate | string |
Function that camelize string value. Keep in mind that, it's a greedy operation, it will remove any special character and also numbers to create camelCase string value.
Param | Description | Type |
---|---|---|
value | String value to camelize | string |
Function that decamelize string value.
It saves any special characters and numbers unlike camelize
function.
Param | Description | Type |
---|---|---|
value | String value in camelCase | string |
separator | Separator for the new decamelized string. Underscore by default | string |
See changelog.
Licensed under the MIT License.