UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

39 lines (38 loc) 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.camelCase = void 0; const upperFirst_1 = __importDefault(require("./upperFirst")); const words_1 = __importDefault(require("./words")); const toString_1 = __importDefault(require("./toString")); /** * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). * * @since 5.5.0 * @category String * @param s The string to convert. * @returns Returns the camel cased string. * @see [[lowerCase]], [[kebabCase]], [[snakeCase]], [[startCase]], [[upperCase]], [[upperFirst]] * @example * * ```js * camelCase('Foo Bar') * // => 'fooBar' * * camelCase('--foo-bar--') * // => 'fooBar' * * camelCase('__FOO_BAR__') * // => 'fooBar' * ``` */ function camelCase(s) { return (0, words_1.default)((0, toString_1.default)(s).replace(/['\u2019]/g, "")).reduce((result, word, index) => { word = word.toLowerCase(); return result + (index ? (0, upperFirst_1.default)(word) : word); }, ""); } exports.camelCase = camelCase; exports.default = camelCase;