voca
Version:
The ultimate JavaScript string library
57 lines (49 loc) • 1.44 kB
JavaScript
import './internal/is_nil.js';
import './internal/coerce_to_boolean.js';
import './is_string.js';
import { c as coerceToString } from './internal/coerce_to_string.js';
import capitalize from './capitalize.js';
import lowerCase from './lower_case.js';
import './internal/const.js';
import './internal/const_extended.js';
import './internal/nil_default.js';
import './internal/to_string.js';
import words from './words.js';
/**
* Transforms the `word` into camel case chunk.
*
* @param {string} word The word string
* @param {number} index The index of the word in phrase.
* @return {string} The transformed word.
* @ignore
*/
function wordToCamel(word, index) {
return index === 0 ? lowerCase(word) : capitalize(word, true);
}
/**
* Converts the `subject` to <a href="https://en.wikipedia.org/wiki/CamelCase">camel case</a>.
*
* @function camelCase
* @static
* @since 1.0.0
* @memberOf Case
* @param {string} [subject=''] The string to convert to camel case.
* @return {string} The camel case string.
* @example
* v.camelCase('bird flight');
* // => 'birdFlight'
*
* v.camelCase('BirdFlight');
* // => 'birdFlight'
*
* v.camelCase('-BIRD-FLIGHT-');
* // => 'birdFlight'
*/
function camelCase(subject) {
var subjectString = coerceToString(subject);
if (subjectString === '') {
return '';
}
return words(subjectString).map(wordToCamel).join('');
}
export default camelCase;