UNPKG

toggle-case

Version:

Converts strings to alternating case

13 lines (12 loc) 342 B
'use strict'; module.exports = function toggle(text) { if (typeof text !== 'string') { return ''; } return text.replace(/_|-|\./g, '').split('').map(function (letter, index) { if (index % 2 === 0) { return letter.toUpperCase(); } return letter.toLowerCase(); }).join('').trim(); };