Skip to content

Convert your normal text tO TeXt tHaT AlTeRnAtEs uPpErCaSe aNd lOwErCaSe

Notifications You must be signed in to change notification settings

laurens94/toAlternateCase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

toAlternateCase

A JavaScript function that extends the String Prototype (bad practice, don't use this in production).

Code:

String.prototype.toAlternateCase = function () {
    let r = "";
    for (let i = 0; i < this.length; i++) {
        r += i % 2 == 1 ? this[i].toUpperCase() : this[i].toLowerCase();
    }
    return r;
}

Usage:

Add the code to your project (not recommended) and run it on a string:

"Lorem ipsum dolor sit amet, consectetur adipiscing elit".toAlternateCase()
// => `"lOrEm iPsUm dOlOr sIt aMeT, cOnSeCtEtUr aDiPiScInG ElIt"`

Change all text occurrences on a webpage

Open the console and copy/paste this, press enter and see the magic happen:

String.prototype.toAlternateCase = function () {
    let r = "";
    for (let i = 0; i < this.length; i++) {
        r += i % 2 == 1 ? this[i].toUpperCase() : this[i].toLowerCase();
    }
    return r;
}
document.querySelectorAll("*").forEach((el) => {
    el.childNodes.forEach((child) => {
        if (child.nodeType === 3) child.nodeValue = child.textContent.toAlternateCase()
    })
})

eNjOy yOuR NeW StRiNgS iN aLtErNaTe cAsE

About

Convert your normal text tO TeXt tHaT AlTeRnAtEs uPpErCaSe aNd lOwErCaSe

Resources

Stars

Watchers

Forks

Releases

No releases published