Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

110 lines
3.9KB

  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. static readFlashMessages(flashMessages){
  74. var currentFlash =new Array();
  75. for (var type in flashMessages) {
  76. for (var key in flashMessages[type]) {
  77. if(!currentFlash.includes(flashMessages[type][key])) {
  78. currentFlash.push(flashMessages[type][key]);
  79. SovNotification.add(type, flashMessages[type][key]);
  80. }
  81. }
  82. }
  83. }
  84. static checkFormValidity(formId){
  85. if(!document.getElementById(formId.substr(1)).checkValidity()){
  86. document.getElementById(formId.substr(1)).reportValidity()
  87. return false;
  88. }else{
  89. return true;
  90. }
  91. }
  92. }