2018-07-14 21:42:34 +05:30
|
|
|
const numberFormat = require('./numberFormat');
|
2018-02-21 15:08:56 +05:30
|
|
|
const markdown = new (require('showdown').Converter)();
|
2018-07-18 00:13:51 +05:30
|
|
|
const luxon = require('luxon');
|
2018-02-21 15:08:56 +05:30
|
|
|
const frappe = require('frappejs');
|
2018-02-14 18:20:56 +05:30
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
format(value, field) {
|
2018-02-21 15:08:56 +05:30
|
|
|
if (typeof field === 'string') {
|
2018-06-25 13:19:11 +05:30
|
|
|
field = { fieldtype: field };
|
2018-02-21 15:08:56 +05:30
|
|
|
}
|
|
|
|
|
2018-06-25 13:19:11 +05:30
|
|
|
if (field.fieldtype === 'Currency') {
|
2018-07-14 21:42:34 +05:30
|
|
|
value = numberFormat.formatNumber(value);
|
2018-02-21 15:08:56 +05:30
|
|
|
|
|
|
|
} else if (field.fieldtype === 'Text') {
|
2018-03-05 22:15:21 +05:30
|
|
|
value = markdown.makeHtml(value || '');
|
2018-02-21 15:08:56 +05:30
|
|
|
|
|
|
|
} else if (field.fieldtype === 'Date') {
|
2018-04-15 00:44:02 +05:30
|
|
|
let dateFormat;
|
|
|
|
if (!frappe.SystemSettings) {
|
2018-09-20 18:09:21 +05:30
|
|
|
dateFormat = 'yyyy-MM-dd';
|
2018-04-15 00:44:02 +05:30
|
|
|
} else {
|
|
|
|
dateFormat = frappe.SystemSettings.dateFormat;
|
|
|
|
}
|
|
|
|
|
2018-07-18 00:13:51 +05:30
|
|
|
value = luxon.DateTime.fromISO(value).toFormat(dateFormat);
|
2018-02-21 15:08:56 +05:30
|
|
|
|
2018-02-14 18:20:56 +05:30
|
|
|
} else {
|
2018-06-25 13:19:11 +05:30
|
|
|
if (value === null || value === undefined) {
|
2018-02-14 18:20:56 +05:30
|
|
|
value = '';
|
|
|
|
} else {
|
|
|
|
value = value + '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2018-09-20 18:09:21 +05:30
|
|
|
}
|