demo-utils.js 744 B

123456789101112131415161718192021222324252627282930
  1. export function sortObject(obj) {
  2. if (typeof obj !== 'object') {
  3. return obj;
  4. }
  5. let temp = {};
  6. let keys = [];
  7. for (let key in obj) {
  8. keys.push(key);
  9. }
  10. keys.sort();
  11. for (let index in keys) {
  12. temp[keys[index]] = sortObject(obj[keys[index]]);
  13. }
  14. return temp;
  15. }
  16. export function copyTextToClipboard(text) {
  17. let textArea = document.createElement('textarea');
  18. textArea.value = text;
  19. document.body.appendChild(textArea);
  20. textArea.select();
  21. try {
  22. let successful = document.execCommand('copy');
  23. let msg = successful ? 'successful' : 'unsuccessful';
  24. console.log('Copying text command was ' + msg);
  25. } catch (err) {
  26. console.log('Oops, unable to copy');
  27. }
  28. document.body.removeChild(textArea);
  29. }