-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.ts
More file actions
33 lines (25 loc) · 763 Bytes
/
index.ts
File metadata and controls
33 lines (25 loc) · 763 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
import * as Resources from './apis'
class Paystack {
[index: string]: any
constructor(apiKey: string) {
this.extend(apiKey)
}
private extend(apiKey: string) {
for (const resource in Resources) {
if (Resources.hasOwnProperty(resource)) {
this[this.toCamelCase(resource)] = new Resources[resource][resource](apiKey);
}
}
}
private toCamelCase(resource: string): string {
const _resource = this.cleanResourceKey(resource)
_resource.toLowerCase()
.replace(/\W+(.)/g, (_, chr) => chr.toUpperCase());
return _resource
}
private cleanResourceKey(resource: string): string {
if(!resource) return null
return resource.toLowerCase().replace("api", "")
}
}
module.exports = Paystack