-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (27 loc) · 824 Bytes
/
index.js
File metadata and controls
27 lines (27 loc) · 824 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Resources = require("./apis");
class Paystack {
constructor(apiKey) {
this.extend(apiKey);
}
extend(apiKey) {
for (const resource in Resources) {
if (Resources.hasOwnProperty(resource)) {
this[this.toCamelCase(resource)] = new Resources[resource][resource](apiKey);
}
}
}
toCamelCase(resource) {
const _resource = this.cleanResourceKey(resource);
_resource.toLowerCase()
.replace(/\W+(.)/g, (_, chr) => chr.toUpperCase());
return _resource;
}
cleanResourceKey(resource) {
if (!resource)
return null;
return resource.toLowerCase().replace("api", "");
}
}
module.exports = Paystack;