function p5Utils__format(str, args) { return args.reduce( function (ret, arg, idx) { return ret.replace(new RegExp('\\{' + idx + '\\}', 'gm'), arg) }, str ) } function p5Utils__parseFloatOrZero(strToParse) { if (!strToParse) return 0 if ("string" === typeof strToParse) { strToParse = strToParse.replace(/,/g, '.') strToParse = strToParse.replace(/ /g, '') } var floatVal = parseFloat(strToParse) return (!isNaN(floatVal))? floatVal : 0 } function p5Utils__pricePrint(value, defaultValue) { return p5Utils__pricePrintFormat(value, defaultValue, '.', ','); } function p5Utils__pricePrintPL(value, defaultValue) { return p5Utils__pricePrintFormat(value, defaultValue, ',', ' '); } function p5Utils__pricePrintFormat(value, defaultValue, decPoint, thousands_sep) { if (undefined === defaultValue) defaultValue = ''; if (!value && value !== 0 && value !== '0') return defaultValue; if ("number" === typeof value) { } else if ("string" === typeof value) { value = p5Utils__parseFloatOrZero(value); if (isNaN(value)) { return defaultValue; } } else { return defaultValue; } var valueParts = value.toFixed(2).split('.'), firstPart = valueParts[0], secondPart = valueParts[1], parts = [], minus = '' ; if ('-' === firstPart.substr(0, 1)) { minus = '-'; firstPart = firstPart.substr(1); } var len = firstPart.length, str = firstPart, i = 0 ; while (len > 3) { parts.unshift(str.substr(-3)); len -= 3; str = str.substr(0, len); i++; } if (len > 0) { parts.unshift(str); } return '' + minus + parts.join(thousands_sep) + decPoint + secondPart; } function p5Utils__clearNode(node) { if (!node || !node.lastChild) return; var lastNode; while (lastNode = node.lastChild) node.removeChild(lastNode); } function p5Utils__nodeStyle(node, style) { if (!node || !style) return; for (i in style) node.style[i] = style[i]; } global.p5Utils__format = p5Utils__format global.p5Utils__parseFloatOrZero = p5Utils__parseFloatOrZero global.p5Utils__pricePrint = p5Utils__pricePrint global.p5Utils__pricePrintPL = p5Utils__pricePrintPL global.p5Utils__pricePrintFormat = p5Utils__pricePrintFormat global.p5Utils__clearNode = p5Utils__clearNode global.p5Utils__nodeStyle = p5Utils__nodeStyle