2018-07-14 16:12:34 +00:00
|
|
|
const numberFormat = require('./numberFormat');
|
2018-10-22 20:50:35 +00:00
|
|
|
// const markdown = new (require('showdown').Converter)();
|
2018-07-17 18:43:51 +00:00
|
|
|
const luxon = require('luxon');
|
2018-02-21 09:38:56 +00:00
|
|
|
const frappe = require('frappejs');
|
2018-02-14 12:50:56 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2019-07-17 10:02:49 +00:00
|
|
|
format(value, field) {
|
|
|
|
if (typeof field === 'string') {
|
|
|
|
field = { fieldtype: field };
|
|
|
|
}
|
|
|
|
if (field.fieldtype === 'Currency') {
|
2019-09-17 08:14:09 +00:00
|
|
|
value = numberFormat.formatNumber(value);
|
2019-07-17 10:02:49 +00:00
|
|
|
} else if (field.fieldtype === 'Text') {
|
|
|
|
// value = markdown.makeHtml(value || '');
|
|
|
|
} else if (field.fieldtype === 'Date') {
|
|
|
|
let dateFormat;
|
|
|
|
if (!frappe.SystemSettings) {
|
|
|
|
dateFormat = 'yyyy-MM-dd';
|
|
|
|
} else {
|
|
|
|
dateFormat = frappe.SystemSettings.dateFormat;
|
|
|
|
}
|
2018-02-21 09:38:56 +00:00
|
|
|
|
2019-07-17 10:02:49 +00:00
|
|
|
value = luxon.DateTime.fromISO(value).toFormat(dateFormat);
|
|
|
|
if (value === 'Invalid DateTime') {
|
|
|
|
value = '';
|
|
|
|
}
|
2019-08-14 07:48:04 +00:00
|
|
|
} else if (field.fieldtype === 'Check') {
|
|
|
|
typeof parseInt(value) === 'number'
|
|
|
|
? (value = parseInt(value))
|
|
|
|
: (value = Boolean(value));
|
2019-07-17 10:02:49 +00:00
|
|
|
} else {
|
|
|
|
if (value === null || value === undefined) {
|
|
|
|
value = '';
|
|
|
|
} else {
|
|
|
|
value = value + '';
|
|
|
|
}
|
2018-02-14 12:50:56 +00:00
|
|
|
}
|
2019-07-17 10:02:49 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|