UNPKG

js-convert-case

Version:

JavaScript Convert String and Keys of Object between cases (camelCase, snake_case, PascalCase, dot.case, path/case, text case, Sentence case, Header Case, UPPERCASE, lowercase, kebab-case). Use for both Node.JS and Browser

14 lines (13 loc) 448 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function toKebabCase(str) { if (str === void 0) { str = ''; } if (!str) return ''; return String(str) .replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '') .replace(/([a-z])([A-Z])/g, function (m, a, b) { return a + "_" + b.toLowerCase(); }) .replace(/[^A-Za-z0-9]+|_+/g, '-') .toLowerCase(); } exports.default = toKebabCase;