forked from kentcdodds/ng2-random-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipboard.js
103 lines (90 loc) · 2.07 KB
/
clipboard.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// This is just stuff to copy/paste during the presentation
// because nobody wants to watch someone type out data...
var userCardTemplate = `
<div class="user-card">
<div class="user-avatar-container">
<img src="fred.png" alt="User Avatar"/>
</div>
<div class="user-properties">
<div>
<strong>Name:</strong> Fred Mertz
</div>
<div>
<strong>Username:</strong> TheFredMertz
</div>
<div>
<strong>Email:</strong> [email protected]
</div>
</div>
</div>
`;
var fred = {
name: {
first: 'Fred',
last: 'Mertz'
},
username: 'TheFredMertz',
email: '[email protected]',
picture: {
medium: 'fred.png'
}
};
var ethel = {
name: {
first: 'Ethel',
last: 'Mertz'
},
username: 'maegrl',
email: '[email protected]',
picture: {
medium: 'ethel.png'
}
};
var buttonTemplate = `
<div class="new-user-button">
<button class="ru-button --primary" autofocus>
<i class="fa fa-user"></i>
Get New User
</button>
</div>
`;
// Random User API URL
var url = 'http://api.randomuser.me';
// just in case there's no internet...
var url = 'http://localhost:3000';
// copy this only if you're running out of time...
this.properties = [
{
title: 'Name',
getVal: user => upperWords(`${user.name.first} ${user.name.last}`)
},
{
title: 'Username',
getVal: user => user.username
},
{
title: 'Email',
getVal: user => user.email
},
{
title: 'Address',
getVal: user => (
upperWords(`${user.location.street}, ${user.location.city}, ${user.location.state} ${user.location.zip}`)
)
},
{
title: 'Birthday',
getVal: user => moment(user.dob * 1000).format('MMMM Do, YYYY')
},
{
title: 'Cell Phone Number',
getVal: user => user.cell
}
];
// Function to make the names/addresses be upper case
// use only if there's time...
function upperWords(string) {
return string.split(' ').map(word => {
return word.substr(0, 1).toUpperCase() + word.substr(1);
}).join(' ');
}