Skip to content

Commit

Permalink
add demo-utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Apr 24, 2018
1 parent cfe3334 commit 1225bdd
Show file tree
Hide file tree
Showing 2 changed files with 529 additions and 523 deletions.
31 changes: 31 additions & 0 deletions demo/demo-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export function sortObject(obj) {
if(typeof obj !== 'object') {
return obj;
}
let temp = {};
let keys = [];
for(let key in obj) {
keys.push(key);
}
keys.sort();
for(let index in keys) {
temp[keys[index]] = sortObject(obj[keys[index]]);
}
return temp;
}

export function copyTextToClipboard(text) {
let textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
let successful = document.execCommand('copy');
let msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}

Loading

0 comments on commit 1225bdd

Please sign in to comment.