2
0
mirror of https://github.com/frappe/books.git synced 2025-01-27 17:18:27 +00:00
books/utils/format.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-14 21:42:34 +05:30
const numberFormat = require('./numberFormat');
// const markdown = new (require('showdown').Converter)();
2018-07-18 00:13:51 +05:30
const luxon = require('luxon');
const frappe = require('frappejs');
2018-02-14 18:20:56 +05:30
module.exports = {
2019-07-17 15:32:49 +05:30
format(value, field) {
if (typeof field === 'string') {
field = { fieldtype: field };
}
if (field.fieldtype === 'Currency') {
2019-09-17 13:44:09 +05:30
value = numberFormat.formatNumber(value);
2019-07-17 15:32:49 +05:30
} 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;
}
2019-07-17 15:32:49 +05:30
value = luxon.DateTime.fromISO(value).toFormat(dateFormat);
if (value === 'Invalid DateTime') {
value = '';
}
} else if (field.fieldtype === 'Check') {
typeof parseInt(value) === 'number'
? (value = parseInt(value))
: (value = Boolean(value));
2019-07-17 15:32:49 +05:30
} else {
if (value === null || value === undefined) {
value = '';
} else {
value = value + '';
}
2018-02-14 18:20:56 +05:30
}
2019-07-17 15:32:49 +05:30
return value;
}
};