2018-01-25 10:04:48 +00:00
|
|
|
let utils = {};
|
|
|
|
|
|
|
|
Object.assign(utils, require('./number_format'));
|
|
|
|
|
|
|
|
Object.assign(utils, {
|
2018-01-12 12:25:07 +00:00
|
|
|
slug(text) {
|
|
|
|
return text.toLowerCase().replace(/ /g, '_');
|
|
|
|
},
|
|
|
|
|
2018-02-01 11:07:36 +00:00
|
|
|
get_random_name() {
|
|
|
|
return Math.random().toString(36).substr(3);
|
|
|
|
},
|
|
|
|
|
2018-01-12 12:25:07 +00:00
|
|
|
async_handler(fn) {
|
|
|
|
return (req, res, next) => Promise.resolve(fn(req, res, next))
|
2018-01-15 11:55:31 +00:00
|
|
|
.catch((err) => {
|
2018-01-23 08:00:29 +00:00
|
|
|
console.log(err);
|
2018-01-15 11:55:31 +00:00
|
|
|
// handle error
|
2018-01-23 12:26:40 +00:00
|
|
|
res.status(err.status_code || 500).send({error: err.message});
|
2018-01-15 11:55:31 +00:00
|
|
|
});
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
async sleep(seconds) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
setTimeout(resolve, seconds * 1000);
|
|
|
|
});
|
|
|
|
}
|
2018-01-25 10:04:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = utils;
|