-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (35 loc) · 883 Bytes
/
index.js
File metadata and controls
36 lines (35 loc) · 883 Bytes
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
class Gomni {
constructor(opts = {}){
this.id = opts.id ? opts.id : 'id'
}
rand(){
return Math.random().toString(36).substring(2)
}
iden(){
return Date.now() + '-' + Math.random().toString(36).substring(2)
}
idenFromStamp(stamp){
return stamp + '-' + Math.random().toString(36).substring(2)
}
toProp(data){
return {[this.iden()]: data}
}
toStamp(iden){
return iden.substring(iden.indexOf('-'), 0)
}
toData(data){
data[this.id] = this.iden()
return data
}
toBoth(data){
data[this.id] = this.iden()
return {[this.iden()]: data}
}
arrToObj(arr){
return arr.reduce((acc, item) => {return {...acc, [item.id]: item}}, {})
}
objToArr(indexedObj){
return Object.values(indexedObj);
}
}
module.exports = Gomni