zalgo.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. var all = [].concat(soul.up, soul.down, soul.mid);
  42. function randomNumber(range) {
  43. var r = Math.floor(Math.random() * range);
  44. return r;
  45. }
  46. function isChar(character) {
  47. var bool = false;
  48. all.filter(function(i) {
  49. bool = (i === character);
  50. });
  51. return bool;
  52. }
  53. function heComes(text, options) {
  54. var result = '';
  55. var counts;
  56. var l;
  57. options = options || {};
  58. options['up'] =
  59. typeof options['up'] !== 'undefined' ? options['up'] : true;
  60. options['mid'] =
  61. typeof options['mid'] !== 'undefined' ? options['mid'] : true;
  62. options['down'] =
  63. typeof options['down'] !== 'undefined' ? options['down'] : true;
  64. options['size'] =
  65. typeof options['size'] !== 'undefined' ? options['size'] : 'maxi';
  66. text = text.split('');
  67. for (l in text) {
  68. if (isChar(l)) {
  69. continue;
  70. }
  71. result = result + text[l];
  72. counts = {'up': 0, 'down': 0, 'mid': 0};
  73. switch (options.size) {
  74. case 'mini':
  75. counts.up = randomNumber(8);
  76. counts.mid = randomNumber(2);
  77. counts.down = randomNumber(8);
  78. break;
  79. case 'maxi':
  80. counts.up = randomNumber(16) + 3;
  81. counts.mid = randomNumber(4) + 1;
  82. counts.down = randomNumber(64) + 3;
  83. break;
  84. default:
  85. counts.up = randomNumber(8) + 1;
  86. counts.mid = randomNumber(6) / 2;
  87. counts.down = randomNumber(8) + 1;
  88. break;
  89. }
  90. var arr = ['up', 'mid', 'down'];
  91. for (var d in arr) {
  92. var index = arr[d];
  93. for (var i = 0; i <= counts[index]; i++) {
  94. if (options[index]) {
  95. result = result + soul[index][randomNumber(soul[index].length)];
  96. }
  97. }
  98. }
  99. }
  100. return result;
  101. }
  102. // don't summon him
  103. return heComes(text, options);
  104. };