-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcustom-processing.js
46 lines (41 loc) · 971 Bytes
/
custom-processing.js
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
const { renderFn } = require('../')
function beforeLookup(path) {
switch (path.toLowerCase()) {
case 'one':
return 1
case 'two':
return 2
case 'three':
return 3
default:
return 0
}
}
function afterLookup(path) {
return '*'.repeat(path)
}
console.log(
'This is some semi-advanced processing here.',
'We process the paths to map them to numbers.',
'Then treat those numbers as array indexes to some scope.',
'Then we replace those variables with a few stars',
'the number of which correspond to the value of the elements in the array.'
)
const arr = [0, 10, 20, 30]
console.log(
renderFn(
'zero={{Zero}}\nOne={{one}}\nTwo={{two}}\nThree={{three}}',
(path, scope) => {
const arrIndex = beforeLookup(path)
const numStars = scope[arrIndex]
return afterLookup(numStars)
},
arr
)
)
/* output:
zero=
One=**********
Two=********************
Three=******************************
*/