]>
git.r.bdr.sh - rbdr/corona-regeln/blob - lib/rule_generator.js
742c9159cb54dae87f92afb32c5616fbbab4c599
1 const { readdir
} = require('fs');
2 const { join
, resolve
} = require('path');
13 'the next day divisible by 7',
15 'next fiscal quarter',
21 kRulesDirectory: resolve(__dirname
, './rules'),
25 const ruleFiles
= await internals
.readdir(internals
.kRulesDirectory
);
26 const rules
= ruleFiles
27 .filter((file
) => file
.match(/.js$/))
28 .map((file
) => require(join(internals
.kRulesDirectory
, file
)));
30 internals
.rules
= rules
.sort(() => Math
.random() - 0.5)
34 return new Promise((resolve
, reject
) => {
36 readdir(path
, (err
, files
) => {
42 return resolve(files
);
51 if (!internals
.rules
) {
52 await internals
.readRules();
55 const rule
= internals
.rules
[internals
.currentIndex
];
56 const time
= internals
.dates
[Math
.floor(Math
.random() * internals
.dates
.length
)];
57 internals
.currentIndex
= (internals
.currentIndex
+ 1) % internals
.rules
.length