2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 01:14:03 +00:00
books/utils/format.js
2018-06-25 13:19:11 +05:30

37 lines
1.0 KiB
JavaScript

const number_format = require('./number_format');
const markdown = new (require('showdown').Converter)();
const moment = require('moment');
const frappe = require('frappejs');
module.exports = {
format(value, field) {
if (typeof field === 'string') {
field = { fieldtype: field };
}
if (field.fieldtype === 'Currency') {
value = number_format.format_number(value);
} 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;
}
value = moment(value).format(dateFormat.toUpperCase());
} else {
if (value === null || value === undefined) {
value = '';
} else {
value = value + '';
}
}
return value;
}
}