zalgo.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // please no
  2. module['exports'] = function zalgo(text, options) {
  3. text = text || " he is here ";
  4. var soul = {
  5. "up" : [
  6. '̍', '̎', '̄', '̅',
  7. '̿', '̑', '̆', '̐',
  8. '͒', '͗', '͑', '̇',
  9. '̈', '̊', '͂', '̓',
  10. '̈', '͊', '͋', '͌',
  11. '̃', '̂', '̌', '͐',
  12. '̀', '́', '̋', '̏',
  13. '̒', '̓', '̔', '̽',
  14. '̉', 'ͣ', 'ͤ', 'ͥ',
  15. 'ͦ', 'ͧ', 'ͨ', 'ͩ',
  16. 'ͪ', 'ͫ', 'ͬ', 'ͭ',
  17. 'ͮ', 'ͯ', '̾', '͛',
  18. '͆', '̚'
  19. ],
  20. "down" : [
  21. '̖', '̗', '̘', '̙',
  22. '̜', '̝', '̞', '̟',
  23. '̠', '̤', '̥', '̦',
  24. '̩', '̪', '̫', '̬',
  25. '̭', '̮', '̯', '̰',
  26. '̱', '̲', '̳', '̹',
  27. '̺', '̻', '̼', 'ͅ',
  28. '͇', '͈', '͉', '͍',
  29. '͎', '͓', '͔', '͕',
  30. '͖', '͙', '͚', '̣'
  31. ],
  32. "mid" : [
  33. '̕', '̛', '̀', '́',
  34. '͘', '̡', '̢', '̧',
  35. '̨', '̴', '̵', '̶',
  36. '͜', '͝', '͞',
  37. '͟', '͠', '͢', '̸',
  38. '̷', '͡', ' ҉'
  39. ]
  40. },
  41. all = [].concat(soul.up, soul.down, soul.mid),
  42. zalgo = {};
  43. function randomNumber(range) {
  44. var r = Math.floor(Math.random() * range);
  45. return r;
  46. }
  47. function is_char(character) {
  48. var bool = false;
  49. all.filter(function (i) {
  50. bool = (i === character);
  51. });
  52. return bool;
  53. }
  54. function heComes(text, options) {
  55. var result = '', counts, l;
  56. options = options || {};
  57. options["up"] = typeof options["up"] !== 'undefined' ? options["up"] : true;
  58. options["mid"] = typeof options["mid"] !== 'undefined' ? options["mid"] : true;
  59. options["down"] = typeof options["down"] !== 'undefined' ? options["down"] : true;
  60. options["size"] = typeof options["size"] !== 'undefined' ? options["size"] : "maxi";
  61. text = text.split('');
  62. for (l in text) {
  63. if (is_char(l)) {
  64. continue;
  65. }
  66. result = result + text[l];
  67. counts = {"up" : 0, "down" : 0, "mid" : 0};
  68. switch (options.size) {
  69. case 'mini':
  70. counts.up = randomNumber(8);
  71. counts.mid = randomNumber(2);
  72. counts.down = randomNumber(8);
  73. break;
  74. case 'maxi':
  75. counts.up = randomNumber(16) + 3;
  76. counts.mid = randomNumber(4) + 1;
  77. counts.down = randomNumber(64) + 3;
  78. break;
  79. default:
  80. counts.up = randomNumber(8) + 1;
  81. counts.mid = randomNumber(6) / 2;
  82. counts.down = randomNumber(8) + 1;
  83. break;
  84. }
  85. var arr = ["up", "mid", "down"];
  86. for (var d in arr) {
  87. var index = arr[d];
  88. for (var i = 0 ; i <= counts[index]; i++) {
  89. if (options[index]) {
  90. result = result + soul[index][randomNumber(soul[index].length)];
  91. }
  92. }
  93. }
  94. }
  95. return result;
  96. }
  97. // don't summon him
  98. return heComes(text, options);
  99. }