function timeOut(num = 30000) {

  setTimeout(() => {

    app.preloader.hide();

    app.dialog.alert('Operation timed out...', 'Time Out');

  }, num)

}

function promiseTimeout(ms, promise) {

  // Create a promise that rejects in <ms> milliseconds

  let timeout = new Promise((resolve, reject) => {

    let id = setTimeout(() => {

      clearTimeout(id);

      reject('Operation timed out in ' + (ms / 1000) + 's')

    }, ms)

  })

  // Returns a race between our timeout and the passed in promise

  return Promise.race([

    promise,

    timeout

  ])

}

String.prototype.replaceAt = function(index, char) {

  return this.substr(0, index - 1) + char + this.substr(index + char.length);

}



function copyToClipboard(element) {

  var $temp = $("<input>");

  $("body").append($temp);

  $temp.val($(element).text()).select();

  document.execCommand("copy");

  $temp.remove();

}







function showToast(message, type = 'Message', position = 'bottom') {

  app.toast.create({

    text: message,

    position: position,

    closeTimeout: 2000,

  }).open()

}