Flip your text with charsets


/ Published in: JavaScript
Save to your folder(s)

Just call the function in an HTML element and it would flip the text in it.


Copy this code and paste it in your HTML
  1. function flip() {
  2. var result = flipString(document.f.original.value.toLowerCase());
  3. document.f.flipped.value = result;
  4. }
  5.  
  6. function flipString(aString) {
  7. var last = aString.length - 1;
  8. //Thanks to Brook Monroe for the
  9. //suggestion to use Array.join
  10. var result = new Array(aString.length)
  11. for (var i = last; i >= 0; --i) {
  12. var c = aString.charAt(i)
  13. var r = flipTable[c]
  14. result[last - i] = r != undefined ? r : c
  15. }
  16. return result.join('')
  17. }
  18.  
  19. var flipTable = {
  20. a : '\u0250',
  21. b : 'q',
  22. c : '\u0254', //open o -- from pne
  23. d : 'p',
  24. e : '\u01DD',
  25. f : '\u025F', //from pne
  26. g : '\u0183',
  27. h : '\u0265',
  28. i : '\u0131', //from pne
  29. j : '\u027E',
  30. k : '\u029E',
  31. //l : '\u0283',
  32. m : '\u026F',
  33. n : 'u',
  34. r : '\u0279',
  35. t : '\u0287',
  36. v : '\u028C',
  37. w : '\u028D',
  38. y : '\u028E',
  39. '.' : '\u02D9',
  40. '[' : ']',
  41. '(' : ')',
  42. '{' : '}',
  43. '?' : '\u00BF', //from pne
  44. '!' : '\u00A1',
  45. "\'" : ',',
  46. '<' : '>',
  47. '_' : '\u203E',
  48. ';' : '\u061B',
  49. '\u203F' : '\u2040',
  50. '\u2045' : '\u2046',
  51. '\u2234' : '\u2235'
  52. }
  53.  
  54. for (i in flipTable) {
  55. flipTable[flipTable[i]] = i
  56. }

URL: http://www.revfad.com/flip.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.