2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00
books/utils/format.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-07-14 16:12:34 +00:00
const numberFormat = require('./numberFormat');
const markdown = new (require('showdown').Converter)();
2018-07-17 18:43:51 +00:00
const luxon = require('luxon');
const frappe = require('frappejs');
2018-02-14 12:50:56 +00:00
module.exports = {
format(value, field) {
if (typeof field === 'string') {
2018-06-25 07:49:11 +00:00
field = { fieldtype: field };
}
2018-06-25 07:49:11 +00:00
if (field.fieldtype === 'Currency') {
2018-07-14 16:12:34 +00:00
value = numberFormat.formatNumber(value);
} else if (field.fieldtype === 'Text') {
2018-03-05 16:45:21 +00:00
value = markdown.makeHtml(value || '');
} else if (field.fieldtype === 'Date') {
let dateFormat;
if (!frappe.SystemSettings) {
dateFormat = 'yyyy-MM-dd';
} else {
dateFormat = frappe.SystemSettings.dateFormat;
}
2018-07-17 18:43:51 +00:00
value = luxon.DateTime.fromISO(value).toFormat(dateFormat);
2018-02-14 12:50:56 +00:00
} else {
2018-06-25 07:49:11 +00:00
if (value === null || value === undefined) {
2018-02-14 12:50:56 +00:00
value = '';
} else {
value = value + '';
}
}
return value;
}
}