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 3.0KB

3 yıl önce
3 yıl önce
3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. static formatNumber(number, toFixed){
  53. if(number)return Number(number.replace(',', '.')).toFixed(toFixed);
  54. else return null;
  55. }
  56. static formatNumberWithoutFixed(number){
  57. if(typeof number == 'string')number = number.replace(',', '.');
  58. if(number)return Number(number);
  59. else return null;
  60. }
  61. static getUrlParameter(sParam) {
  62. var sPageURL = window.location.search.substring(1),
  63. sURLVariables = sPageURL.split('&'),
  64. sParameterName,
  65. i;
  66. for (i = 0; i < sURLVariables.length; i++) {
  67. sParameterName = sURLVariables[i].split('=');
  68. if (sParameterName[0] === sParam) {
  69. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  70. }
  71. }
  72. };
  73. }