This repository was archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconfig.js
More file actions
46 lines (40 loc) · 1.36 KB
/
config.js
File metadata and controls
46 lines (40 loc) · 1.36 KB
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
40
41
42
43
44
45
46
// Conditional features that are currently supported by wstrade-api
const supportedFeatures = ['implicit_token_refresh', 'securities_cache'];
const supported = (feature) => {
if (!feature?.startsWith('no_')) {
return supportedFeatures.includes(feature);
}
return supportedFeatures.includes(feature.substring('no_'.length));
};
// Holds optional features that have been disabled.
const disabled = ['securities_cache'];
export const configEnabled = (feature) => !disabled.includes(feature);
/**
* Enable or disable an optional feature within wstrade-api.
*
* Examples:
* ---
* config('implicit_token_refresh')
* Enables implicit refreshing of tokens.
*
* config('no_implicit_token_refresh')
* Disables implicit refreshing of tokens.
*
* @param {*} feature The string identifier for the feature, starting with "no_" if
* you wish to disable it.
*/
export default function config(feature) {
if (!supported(feature)) {
throw new Error(`'${feature}' is not supported!`);
}
if (feature?.startsWith('no_')) {
const cut = feature.substring(feature.indexOf('_') + 1);
// We will only append this if it isn't already in there.
if (configEnabled(cut)) {
disabled.push(cut);
}
// Only delete the feature if it's already disabled.
} else if (!configEnabled(feature)) {
disabled.splice(disabled.indexOf(feature), 1);
}
}