2
0
mirror of https://github.com/frappe/books.git synced 2025-01-26 16:48:28 +00:00
books/utils/format.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-02-14 18:20:56 +05:30
const number_format = require('./number_format');
const markdown = new (require('showdown').Converter)();
const moment = require('moment');
const frappe = require('frappejs');
2018-02-14 18:20:56 +05:30
module.exports = {
format(value, field) {
if (typeof field === 'string') {
field = {fieldtype: field};
}
2018-02-14 18:20:56 +05:30
if (field.fieldtype==='Currency') {
value = number_format.format_number(value);
} else if (field.fieldtype === 'Text') {
2018-03-05 22:15:21 +05:30
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());
2018-02-14 18:20:56 +05:30
} else {
if (value===null || value===undefined) {
value = '';
} else {
value = value + '';
}
}
return value;
}
}