2023-09-11 07:14:56 +00:00

48 lines
1.4 KiB
JavaScript
Vendored
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default {
methods: {
formatPrice(price, prec=2, dots=true, label=true) {
price = Number(price);
if(price == 0 && label) {
return this.$t('front_externMP.on_request')
}else{
if(price != Math.floor(price) && prec > 0) {
return 'CHF ' + this.splitAndPad(price.toFixed(prec));
}
if(dots) {
return 'CHF ' + this.splitAndPad(price.toFixed(0)) + '.-';
}else{
return 'CHF ' + this.splitAndPad(price.toFixed(0));
}
}
},
splitAndPad(number) {
number = number + '';
var x = number.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '' + '$2');
}
return x1 + x2;
},
isContentHtml(input) {
var htmlRegex = new RegExp(/<[a-z/][\s\S]*>/i);
return htmlRegex.test(input);
},
formatDate(value) {
if(!value) {
return '-';
}
const date = new Date(value);
if(!date instanceof Date || isNaN(date)) {
return '-';
}
return new Intl.DateTimeFormat("de-CH", {year: 'numeric', month: '2-digit', day: '2-digit' }).format(date);
},
formatNum(price, digits = 0){
var options = { maximumFractionDigits: digits, minimumFractionDigits: digits }
return Intl.NumberFormat("de-CH", options).format(price);
},
}
};