UNPKG

voca

Version:

The ultimate JavaScript string library

42 lines (36 loc) 1.07 kB
import './internal/is_nil.js'; import './is_string.js'; import { c as coerceToString } from './internal/coerce_to_string.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'; /** * Converts the `subject` to <a href="https://en.wikipedia.org/wiki/Snake_case">snake case</a>. * * @function snakeCase * @static * @since 1.0.0 * @memberOf Case * @param {string} [subject=''] The string to convert to snake case. * @return {string} Returns the snake case string. * @example * v.snakeCase('learning to fly'); * // => 'learning_to_fly' * * v.snakeCase('LearningToFly'); * // => 'learning_to_fly' * * v.snakeCase('-Learning-To-Fly-'); * // => 'learning_to_fly' */ function snakeCase(subject) { var subjectString = coerceToString(subject); if (subjectString === '') { return ''; } return words(subjectString).map(lowerCase).join('_'); } export default snakeCase;