You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tools.js 2.0KB

3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export class SovTools {
  2. static log(value) {
  3. try {
  4. console.log(value) ;
  5. }
  6. catch {}
  7. }
  8. static arrayRemove(arr, value) {
  9. return arr.filter(function(ele){ return ele != value; });
  10. }
  11. static toPlainText(html) {
  12. let scratchDiv = document.createElement('div');
  13. scratchDiv.innerHTML = html;
  14. return scratchDiv.textContent;
  15. }
  16. static getDateFormatted(date, separator) {
  17. if(date) {
  18. var date = new Date(date);
  19. var _d = date.getDate(),
  20. d = _d > 9 ? _d : '0' + _d,
  21. _m = date.getMonth() + 1,
  22. m = _m > 9 ? _m : '0' + _m,
  23. formatted = d + separator + m + separator + date.getFullYear();
  24. return formatted;
  25. }
  26. else {
  27. return '';
  28. }
  29. }
  30. static getUrlParameter(sParam) {
  31. var sPageURL = window.location.search.substring(1),
  32. sURLVariables = sPageURL.split('&'),
  33. sParameterName,
  34. i;
  35. for (i = 0; i < sURLVariables.length; i++) {
  36. sParameterName = sURLVariables[i].split('=');
  37. if (sParameterName[0] === sParam) {
  38. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  39. }
  40. }
  41. }
  42. static indexOfFirstDigit(input) {
  43. let i = 0;
  44. for (; input[i] < '0' || input[i] > '9'; i++) ;
  45. return i == input.length ? -1 : i;
  46. }
  47. static indexOfLastDigit(input) {
  48. let i = input.length - 1;
  49. for (; input[i] < '0' || input[i] > '9'; i--) ;
  50. return i == input.length ? -1 : i;
  51. }
  52. }