2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/utils/index.js
2018-02-01 16:39:37 +05:30

30 lines
711 B
JavaScript

let utils = {};
Object.assign(utils, require('./number_format'));
Object.assign(utils, {
slug(text) {
return text.toLowerCase().replace(/ /g, '_');
},
get_random_name() {
return Math.random().toString(36).substr(3);
},
async_handler(fn) {
return (req, res, next) => Promise.resolve(fn(req, res, next))
.catch((err) => {
console.log(err);
// handle error
res.status(err.status_code || 500).send({error: err.message});
});
},
async sleep(seconds) {
return new Promise(resolve => {
setTimeout(resolve, seconds * 1000);
});
}
});
module.exports = utils;