The lodash method kebabCase exported as a standalone Node.js module for converting strings to kebab-case format
npx @tessl/cli install tessl/npm-lodash-kebabcase@4.1.0The lodash method kebabCase exported as a standalone Node.js module for converting strings to kebab-case format. It transforms strings to kebab case by splitting words on boundaries (camelCase, PascalCase, snake_case, spaces, etc.) and joining them with hyphens in lowercase.
npm install lodash.kebabcasevar kebabCase = require('lodash.kebabcase');The module exports the kebabCase function as the default export.
var kebabCase = require('lodash.kebabcase');
// Convert different string formats to kebab-case
console.log(kebabCase('Foo Bar')); // => 'foo-bar'
console.log(kebabCase('fooBar')); // => 'foo-bar'
console.log(kebabCase('__FOO_BAR__')); // => 'foo-bar'
console.log(kebabCase('XMLHttpRequest')); // => 'xml-http-request'Converts strings to kebab case by splitting words and joining them with hyphens in lowercase.
/**
* Converts string to kebab case
* @param {string} [string=''] - The string to convert
* @returns {string} Returns the kebab cased string
*/
function kebabCase(string = '')Examples:
kebabCase('Foo Bar');
// => 'foo-bar'
kebabCase('fooBar');
// => 'foo-bar'
kebabCase('__FOO_BAR__');
// => 'foo-bar'
kebabCase('XMLHttpRequest');
// => 'xml-http-request'
kebabCase('hello world 123');
// => 'hello-world-123'
kebabCase('camelCaseString');
// => 'camel-case-string'
kebabCase('PascalCaseString');
// => 'pascal-case-string'
kebabCase('snake_case_string');
// => 'snake-case-string'
kebabCase(' Multiple Spaces ');
// => 'multiple-spaces'
kebabCase('Special-Characters!@#');
// => 'special-characters'
kebabCase('unicode-café');
// => 'unicode-cafe'
kebabCase('');
// => ''
kebabCase();
// => ''