Search code examples
javascriptstringuppercaselowercase

Is there a way to change default uppercase value of a character using JavaScript?


I'm working on the development of a website in my native language, where the uppercase version of letter "i" is "İ". Default string.toUpperCase() method turns "i" into "I", which is a completely different letter (the lowercase version for this one is "ı"). Is there a way to set the default uppercase value for "i", so that I will be able to use toUpperCase() method successfully?

The locale is az_Latn_AZ.


Solution

  • You can change toUpperCase, like this:

    String.prototype.oldToUpperCase = String.prototype.toUpperCase;
    String.prototype.toUpperCase = function() {
        return this.split("i").join("I").oldToUpperCase();
    }
    

    Now test it like this:

    console.log("aaa".toUpperCase());
    console.log("aiaia".toUpperCase());