UNPKG
@webwriter/block-based-code
Version:
latest (1.7.3)
1.7.3
1.7.2
1.7.1
1.7.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
Write block-based code (e.g. Scratch) and run it.
@webwriter/block-based-code
/
utils
/
string.ts
9 lines
(8 loc)
•
267 B
text/typescript
View Raw
1
2
3
4
5
6
7
8
9
/** * Convert a string to kebab case. *
@param
str The string to convert. */
export
const
toKebabCase = (
str
:
string
):
string
=>
str .
match
(
/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g
) .
map
(
(
x
) =>
x.
toLowerCase
()) .
join
(
"-"
);