Skip to content

Commit

Permalink
feat(scraps): add random date option ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 23, 2020
1 parent 03473c8 commit 5a12320
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/helpers/montaineRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ exports.setParams = (s) => {
Object.keys(s).forEach((key) => {
const func = String(s[key]).split('(')[0] || '';
const params = String(s[key]).split('(')[1] ? String(s[key]).split('(')[1].slice(0, -1).split(',') : [];

switch (func) {
case 'DATE':
try {
result[key] = moment().add(Number(params[0]), 'days').format(String(params[1]));
let number;
if (params[0].indexOf('-') > -1) number = Math.floor(Math.random() * Number(params[0].split('-')[1])) + Number(params[0].split('-')[0]);
else number = Number(params[0]);
result[key] = moment().add(number, String(params[1])).format(String(params[2]));
} catch (err) {
throw new AppError('Typing : format DATE error', { code: 'HELPERS_ERROR', details: err });
}
Expand Down

0 comments on commit 5a12320

Please sign in to comment.