/
index.ts
35 lines (32 loc) · 927 Bytes
/
index.ts
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
/**
* Parses object in format { "key.key2.key3" : value } into { key: { key2: {key3: value } } }
* @param object object to parse
* @param key string to split
* @param value value to make it equal to
*/
export function set(object, key, value) {
let current = object;
const tokens = key.split('.');
const last = tokens.pop();
tokens.forEach(token => {
current[token] = typeof current[token] == 'object' ? current[token] : {};
current = current[token];
});
current[last] = value;
return object;
}
/**
* Should invert the object (keys becomes values and values becomes keys)
* @param object
*/
export function invert(object) {
const returnee = {};
for (const key in object) {
if (!object.hasOwnProperty(key)) continue;
returnee[object[key]] = key;
}
return returnee;
}
export function signedInfuraLink(infura: string): string {
return `https://mainnet.infura.com/v3/${infura}`;
}