/** @module Formatters */
/**
* Remove HTML-tags from html-string
* @author Jeroen Rijkse <jeroen@notanumber.digital>
* @param {string} text String to be stripeed
* @example
* import { stripHtml } from "nan-design-system/utils";
* const text = stripHtml("<div> This is a <b>test</b> </div>"); //returns "This is a test"
* @returns {string | false} String without HTML-tags or false when input does not contain text
*/
export function stripHtml(text) {
if (text === null || text === "") {
return false;
} else {
text = text.toString();
}
return text.replace(/(<([^>]+)>)/gi, "");
}
/**
* Converts number to euro price.
* @author Moreno van Rooijen <moreno@notanumber.digital>
* @param {*} price price to be converted
* @param {*} text where or not euro should be a sign in front or text behind the price.
*/
export function toEuroFormat(price, text = false) {
if (typeof price == "undefined" || price == null) {
return "";
}
if (text) {
return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".") + " euro";
}
return "€ " + price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
/**
* adds dots on the appropriate places for numbers.
* @author Moreno van Rooijen <moreno@notanumber.digital>
* @param {*} number number to be converted
*/
export function addThousandSeperator(number) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
Source