UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

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