UNPKG
toggle-case
Version:
latest (1.0.5)
1.0.5
1.0.4
1.0.3
1.0.2
1.0.0
Converts strings to alternating case
github.com/seyi-adeleke/ToGgLe-CaSe
toggle-case
/
src
/
index.js
13 lines
(12 loc)
•
331 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
module
.
exports
=
function
toggle
(
text
) {
if
(
typeof
text !==
'string'
) {
return
''
; }
return
text.
replace
(
/_|-|\./g
,
''
).
split
(
''
).
map
(
(
letter, index
) =>
{
if
(index %
2
===
0
) {
return
letter.
toUpperCase
(); }
return
letter.
toLowerCase
(); }).
join
(
''
) .
trim
(); };