Library.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. let library ={
  2. formatSeconds(value) {
  3. let result = parseInt(value);
  4. // let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
  5. // let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  6. let m = Math.floor((result / 60 % 60)) < 10 ? '' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  7. let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  8. let res = '';
  9. // if(h !== '00') res += `${h}h`;
  10. // if(m !== '00') res += `${m}min`;
  11. // res += `${s}s`;
  12. // if(h !== '00') res += `${h}:`;
  13. res += `${m}:`;
  14. res += `${s}`;
  15. return res;
  16. },
  17. randomInt(min, max){
  18. return Math.floor(Math.random() * (max - min)) + min;
  19. },
  20. removeObj(arr,obj)
  21. {
  22. let index = this.indexOf(arr,obj);
  23. if (index > -1) {
  24. arr.splice(index, 1);
  25. }
  26. },
  27. indexOf(arr,obj) {
  28. for (var i = 0; i < arr.length; i++) {
  29. if (arr[i] == obj) return i;
  30. }
  31. return -1;
  32. },
  33. insert(arr,index, item) {
  34. arr.splice(index, 0, item);
  35. },
  36. };
  37. module.exports = library;