Last active
November 24, 2015 01:40
-
-
Save jczimm/5ab3bce4958c475ba477 to your computer and use it in GitHub Desktop.
Simple character mapping.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var charMap = function charMap(str, from, to, tryLowerCase = false) { | |
return str | |
.split("") | |
.map((char, i) => to.charAt(from.indexOf(tryLowerCase ? char.toLowerCase() : char)) || char) | |
.join(""); | |
}; | |
var normal = "abcdefghijklmnopqrstuvwxyz", | |
smallLetters = "\u1d00\u0299\u1d04\u1d05\u1d07\u0493\u0262\u029c\u026a\u1d0a\u1d0b\u029f\u1d0d\u0274\u1d0f\u1d18\u01eb\u0280s\u1d1b\u1d1c\u1d20\u1d21x\u028f\u1d22"; | |
charMap("Lorem ipsum", normal, smallLetters); | |
// => "Lᴏʀᴇᴍ ɪᴘsᴜᴍ" | |
charMap("Lorem ipsum", normal, smallLetters, true); | |
// => "ʟᴏʀᴇᴍ ɪᴘsᴜᴍ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment