burn.js 603 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. $(function()
  2. {
  3. initBurnChar();
  4. });
  5. function truncateCustomString(str, maxLength)
  6. {
  7. let count = 0;
  8. let strLength = 0;
  9. for(let char of str)
  10. {
  11. if(char.match(/[A-Z]/))
  12. {
  13. count += 2;
  14. }
  15. else if(char.match(/[a-z]/))
  16. {
  17. count += 1;
  18. }
  19. else if(char.charCodeAt(0) > 255)
  20. {
  21. count += 2;
  22. }
  23. else
  24. {
  25. count += 1;
  26. }
  27. if(count > maxLength)
  28. {
  29. break;
  30. }
  31. strLength++;
  32. }
  33. return str.slice(0, strLength);
  34. }