-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
50 lines (44 loc) · 1.16 KB
/
example.js
File metadata and controls
50 lines (44 loc) · 1.16 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
47
48
49
import loadConfig from './overloadfig.js';
// Example overloadfig
const exampleSpec = {
"action": {
"string": (val) => {
console.log("hello " + val);
},
"number": (val) => {
console.log("number: " + val);
},
"object": {
"http": (val) => {
console.log("making a http get! (not really obviously)" );
return "abc"; // Could return the actual value here
},
},
},
"msg": { // Note don't have to specify that it's an object
"name": (name) => {
console.log(`hello ${name}!`);
return `hello ${name}!`;
}
},
}
// Basic callbacks on values
loadConfig(exampleSpec, {
"action": "to new overloadfig user!",
"msg": {
"name": "root"
}
});
// Outputs ->
// hello to new overloadfig user!
// hello root!
// Return values
// Also all keys are optional, best effort approach with minimal erroring
console.log(loadConfig(exampleSpec, {
"action": {
"http": "asdf"
},
}));
// Outputs ->
// making a http get! (not really obviously)
// { action: { http: 'abc' } }