UNPKG

@simongrasinovski/str-utils

Version:

A lightweight utility library for effortless string manipulation. Simplify common tasks like case validation, conversion and formatting with easy-to-use functions that enhance your JavaScript applications

26 lines (24 loc) 804 B
"use strict"; var _require = require('./utils'), ensureString = _require.ensureString; var _require2 = require('./constants'), EMPTY_SPACES_REGEX = _require2.EMPTY_SPACES_REGEX, CAPITALIZATION_REGEX = _require2.CAPITALIZATION_REGEX; /** * Converts a string to camelCase. * * @function * @param {string} input - The string to convert. * @returns {string} String in camelCase. * * @throws {TypeError} Throws an error if the input is not a string. * * @example * const result = camelCase('Hello World'); * console.log(result); // 'helloWorld' */ module.exports = ensureString(function (input) { return input.replace(CAPITALIZATION_REGEX, function (match, index) { return index === 0 ? match.toLowerCase() : match.toUpperCase(); }).replace(EMPTY_SPACES_REGEX, ''); });