-
Notifications
You must be signed in to change notification settings - Fork 0
/
showavatar.js
30 lines (26 loc) · 871 Bytes
/
showavatar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fetch from "node-fetch";//Only needed if the node version is less than 18
function loadJson(url) {
return fetch(url)
.then(response => response.json());
}
function loadGithubUser(name) {
return loadJson(`https://api.github.com/users/${name}`);
}
function showAvatar(githubUser) {
return new Promise(function(resolve, reject) {
console.log(githubUser.avatar_url)
/*let img = document.createElement('img');
img.src = githubUser.avatar_url;
img.className = "promise-avatar-example";
document.body.append(img);*/
setTimeout(() => {
//img.remove();
resolve(githubUser);
}, 3000);
});
}
// Use them:
loadJson('../user.json')
.then(user => loadGithubUser(user.name))
.then(showAvatar)
.then(githubUser => alert(`Finished showing ${githubUser.name}`));