2018-02-07 13:23:52 +00:00
|
|
|
module.exports = {
|
2018-02-06 17:14:07 +00:00
|
|
|
format(value, field) {
|
|
|
|
if (field.fieldtype==='Currency') {
|
|
|
|
return frappe.format_number(value);
|
|
|
|
} else {
|
2018-02-07 13:23:52 +00:00
|
|
|
if (value===null || value===undefined) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return value + '';
|
|
|
|
}
|
2018-02-06 17:14:07 +00:00
|
|
|
}
|
|
|
|
},
|
2018-02-07 13:23:52 +00:00
|
|
|
|
2018-01-12 12:25:07 +00:00
|
|
|
slug(text) {
|
|
|
|
return text.toLowerCase().replace(/ /g, '_');
|
|
|
|
},
|
|
|
|
|
2018-02-08 06:46:38 +00:00
|
|
|
getRandomName() {
|
2018-02-01 11:07:36 +00:00
|
|
|
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-02-07 13:23:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_(text, args) {
|
|
|
|
// should return translated text
|
|
|
|
return this.string_replace(text, args);
|
|
|
|
},
|
|
|
|
|
|
|
|
string_replace(str, args) {
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
args = [args];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(str==undefined) return str;
|
|
|
|
|
|
|
|
let unkeyed_index = 0;
|
|
|
|
return str.replace(/\{(\w*)\}/g, (match, key) => {
|
|
|
|
if (key === '') {
|
|
|
|
key = unkeyed_index;
|
|
|
|
unkeyed_index++
|
|
|
|
}
|
|
|
|
if (key == +key) {
|
|
|
|
return args[key] !== undefined
|
|
|
|
? args[key]
|
|
|
|
: match;
|
|
|
|
}
|
|
|
|
});
|
2018-01-12 12:25:07 +00:00
|
|
|
}
|
2018-01-25 10:04:48 +00:00
|
|
|
|
2018-02-07 13:23:52 +00:00
|
|
|
};
|