2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00
books/utils/index.js

30 lines
711 B
JavaScript
Raw Normal View History

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))
.catch((err) => {
2018-01-23 08:00:29 +00:00
console.log(err);
// handle error
2018-01-23 12:26:40 +00:00
res.status(err.status_code || 500).send({error: err.message});
});
2018-01-12 12:25:07 +00:00
},
async sleep(seconds) {
return new Promise(resolve => {
setTimeout(resolve, seconds * 1000);
});
}
});
module.exports = utils;