The value to be converted to kebab-case string
Optionalscream: boolean
Optionally return the result as UpperCase (Screaming).
The kebab-cased version of the provided value
strKebabCase(null); // "null"
strKebabCase(undefined); // "undefined"
strKebabCase("hello darkness"); // "hello-darkness"
strKebabCase("hello_darkness"); // "hello-darkness"
strKebabCase("_hello_darkness"); // "-hello-darkness"
strKebabCase("hello darkness, my old friend."); // "hello-darkness-my-old-friend-"
strKebabCase("helloDarkness"); // "hello-darkness"
strKebabCase("XMLHttpRequest"); // "xml-http-request"
strKebabCase("fooBar2Baz"); // "foo-bar2-baz"
strKebabCase("café crème"); // "café-crème"
// Add optional SCREAM flag
strKebabCase("hello darkness", true); // "HELLO-DARKNESS"
strKebabCase("hello_darkness", true); // "HELLO-DARKNESS"
strKebabCase("_hello_darkness", true); // "-HELLO-DARKNESS"
strKebabCase("hello darkness, my old friend.", true); // "HELLO-DARKNESS-MY-OLD-FRIEND-"
Convert the provided value to
kebab-casedstring, you can optionally specify whther the result is all uppercased by passingtrueas the optionalscreamargument, otherwise the entire result will be lowercased.Words are split at any separator (whitespace, punctuation and symbols, eg. spaces,
_and-, of ASCII and Latin-1, exceptª²³µ¹º¼½¾, and of the General Punctuation, Currency Symbols, Arrows to Miscellaneous Symbols and Arrows, and CJK Symbols and Punctuation blocks, with the same exceptions as strLetterCase, so the emoji of these blocks are separators, eg."I ⭐ JS"is"i-js", all other characters such as😀and™are part of a word, eg."I 😀 JS"is"i-😀-js"and"50µs"is"50µs"), where any other word character (eg. a lowercase letter, a number,™or an emoji) is followed by an uppercase letter ("fooBar","bar2Baz","Hello™World"is"hello™-world", also after a separator, eg."the iPhone"is"the-i-phone") and before the last letter of an uppercase run that is followed by a lowercase letter ("XMLHttp", but not a pluralswhich ends the word, eg."userIDs"is"user-ids"), then joined with a single-. Leading and trailing whitespace is removed, any other leading or trailing separators are replaced with a single-so the conversion is reversible with strSnakeCase (eg."_a_b_"to"-a-b-"and back to"_a_b_"). Non-ASCII letters are retained, uppercase letters (word boundaries) are detected forA-Z, the Latin-1 lettersÀ-Þ(except×), the basic Greek capitalsΆ,Έ-ΏandΑ-Ϋ(U+0386, U+0388 to U+038F and U+0391 to U+03AB) and the basic Cyrillic capitalsЀ-Я(U+0400 to U+042F), in both precomposed and decomposed forms (eg."Έ"and"Ε"followed by a combining acute accent), other cased letters (eg."Ł","Č","Ϗ"and"Ґ") are case converted but don't start a new word (and onlya-z,ß-ÿexcept÷and the basic Greek and Cyrillic lowercase letters end an uppercase run, eg."ABCłdef"is"abcłdef"), while a decomposed letter whose base letter is within those ranges (eg."C"followed by a combining caron) does, so normalize the value first (eg. withString.prototype.normalize()where supported) when it may contain both forms. The same fixed character ranges are used on every runtime. If the value is not a string it will be converted.