@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
23 lines (21 loc) • 636 B
JavaScript
;
var _require = require('./utils'),
ensureString = _require.ensureString;
var _require2 = require('./constants'),
EMPTY_SPACES_REGEX = _require2.EMPTY_SPACES_REGEX;
/**
* Converts a string to snake_case.
*
* @function
* @param {string} input - The string to convert.
* @returns {string} String in snake_case.
*
* @throws {TypeError} Throws an error if the input is not a string.
*
* @example
* const result = snakeCase('Hello World');
* console.log(result); // 'hello_world'
*/
module.exports = ensureString(function (input) {
return input.toLowerCase().replace(EMPTY_SPACES_REGEX, '_');
});