UNPKG

voca

Version:

The ultimate JavaScript string library

43 lines (37 loc) 1.14 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/Letter_case#cite_ref-13">kebab case</a>, * also called <i>spinal case</i> or <i>lisp case</i>. * * @function kebabCase * @static * @since 1.0.0 * @memberOf Case * @param {string} [subject=''] The string to convert to kebab case. * @return {string} Returns the kebab case string. * @example * v.kebabCase('goodbye blue sky'); * // => 'goodbye-blue-sky' * * v.kebabCase('GoodbyeBlueSky'); * // => 'goodbye-blue-sky' * * v.kebabCase('-Goodbye-Blue-Sky-'); * // => 'goodbye-blue-sky' */ function kebabCase(subject) { var subjectString = coerceToString(subject); if (subjectString === '') { return ''; } return words(subjectString).map(lowerCase).join('-'); } export default kebabCase;