string.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function trim(stringToTrim) {
  2. return stringToTrim.toString().replace(/^\s+|\s+$/g,"");
  3. }
  4. function isEmpty(str) {
  5. if (typeof str === "undefined" || str === undefined || str === null || str === "" || trim(str) === '')
  6. return true;
  7. else
  8. return false ;
  9. }
  10. function ellipsisString(text, maxLength = 150) {
  11. if (text.length > maxLength) {
  12. const truncatedString = text.substring(0, maxLength)
  13. return truncatedString + "..."
  14. }
  15. return text
  16. }
  17. function capitalize(str) {
  18. return str.charAt(0).toUpperCase() + str.slice(1);
  19. }
  20. function textLengthOverCut(txt, len, lastTxt) {
  21. if (len == "" || len == null) { // 기본값
  22. len = 20;
  23. }
  24. if (lastTxt == "" || lastTxt == null) { // 기본값
  25. lastTxt = "...";
  26. }
  27. if (txt.length > len) {
  28. txt = txt.substr(0, len) + lastTxt;
  29. }
  30. return txt;
  31. }
  32. function getByte(str) {
  33. return str
  34. .split('')
  35. .map(s => s.charCodeAt(0))
  36. .reduce((prev, c) => (prev + ((c === 10) ? 2 : ((c >> 7) ? 2 : 1))), 0);
  37. }
  38. function str_replace_hyphen(str, search) {
  39. return str.replace(search, '-')
  40. }