This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.addEventListener( | |
'click', | |
async (e) => { | |
const text = await navigator.clipboard.readText(); | |
console.log(text); | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(async () => { | |
const text = await navigator.clipboard.readText(); | |
console.log(text); | |
}, 2000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const text = await navigator.clipboard.readText(); | |
console.log(text); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pasteText = document.querySelector('#output'); | |
pasteText.focus(); | |
document.execCommand('paste'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inputElement = document.querySelector('#input'); | |
inputElement.select(); | |
document.execCommand('cut'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inputElement = document.querySelector('#input'); | |
inputElement.select(); | |
document.execCommand('copy'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
axios.all([ | |
axios.get('https://api.github.com/users/sabesansathananthan'), | |
axios.get('https://api.github.com/users/rcvaram') | |
]) | |
.then(axios.spread((obj1, obj2) => { | |
// Both requests are now complete | |
console.log(obj1.data.login + ' has ' + obj1.data.public_repos + ' public repos on GitHub'); | |
console.log(obj2.data.login + ' has ' + obj2.data.public_repos + ' public repos on GitHub'); | |
})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.all([ | |
fetch('https://api.github.com/users/sabesansathananthan'), | |
fetch('https://api.github.com/users/rcvaram') | |
]) | |
.then(async([res1, res2]) => { | |
const a = await res1.json(); | |
const b = await res2.json(); | |
console.log(a.login + ' has ' + a.public_repos + ' public repos on GitHub'); | |
console.log(b.login + ' has ' + b.public_repos + ' public repos on GitHub'); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {fetch as fetchPolyfill} from 'whatwg-fetch' | |
window.fetch(...) // use native browser version | |
fetchPolyfill(...) // use polyfill implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
axios({ | |
method: 'post', | |
url: '/login', | |
timeout: 5000, // 5 seconds timeout | |
data: { | |
firstName: 'Sabesan', | |
lastName: 'Sathananthan' | |
} | |
}) | |
.then(response => {/* handle the response */}) |