-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 949 Bytes
/
index.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
const mapKeys = require('./mapKeys')
module.exports = class User {
constructor (options = {}) {
const normalizedOptions = mapKeys({
in: options,
mappings: [
{from: 'uuid', to: 'id'},
{from: 'login', to: 'username'},
{from: 'display_name', to: 'name'},
{from: ['avatar_url', 'links.avatar.href'], to: 'avatarUrl'},
{from: ['created_on', 'created_at'], to: 'createdAt'},
{from: ['website', 'url', 'links.self.href'], to: 'apiUrl'},
{from: ['html_url', 'web_url', 'links.html.href'], to: 'accountUrl'},
],
})
Object.assign(this, normalizedOptions)
}
get fullName () {
return this.user + '/' + this.name
}
get object () {
const {id, name, username, accountUrl} = this
return {id, name, username, accountUrl}
}
toJSON () {
return this.object
}
get string () {
return this.url
}
toString () {
return this.string
}
}