bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
51 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PipeCantidadMoneda = void 0;
var core_1 = require("@angular/core");
var i0 = require("@angular/core");
var PADDING = "000000";
var PipeCantidadMoneda = /** @class */ (function () {
function PipeCantidadMoneda() {
this.DECIMAL_SEPARATOR = ",";
this.DECIMAL_SEPARATOR_INPUT = ".";
this.THOUSANDS_SEPARATOR = ".";
}
PipeCantidadMoneda.prototype.transform = function (value, fractionSize) {
if (fractionSize === void 0) { fractionSize = 2; }
var svalue = String(value);
var regexp = new RegExp("^[1-9]+[0-9]*([.]([0-9]+)?)?$");
var test = regexp.test(svalue);
if (!test) {
return svalue;
}
var _a = (value || "").toString().split(this.DECIMAL_SEPARATOR_INPUT), integer = _a[0], _b = _a[1], fraction = _b === void 0 ? "" : _b;
fraction = fractionSize > 0 ? this.DECIMAL_SEPARATOR + (fraction + PADDING).substring(0, fractionSize) : "";
integer = integer.replace(/\B(?=(\d{3})+(?!\d))/g, this.THOUSANDS_SEPARATOR);
return integer + fraction;
};
PipeCantidadMoneda.prototype.parse = function (value, previous, event, fractionSize) {
if (fractionSize === void 0) { fractionSize = 2; }
var svalue = String(value);
var regexp = new RegExp("^[1-9]+[0-9]*([.][0-9]{3})*(,([0-9]+)?)?$");
var test = regexp.test(svalue);
if (!test) {
return svalue;
}
var _a = (value || "").split(this.DECIMAL_SEPARATOR), integer = _a[0], _b = _a[1], fraction = _b === void 0 ? "" : _b;
integer = integer.replace(/\./g, "");
fraction =
parseInt(fraction, 10) > 0 && fractionSize > 0
? this.DECIMAL_SEPARATOR_INPUT + (fraction + PADDING).substring(0, fractionSize)
: "";
return integer + fraction;
};
PipeCantidadMoneda.ɵfac = function PipeCantidadMoneda_Factory(t) { return new (t || PipeCantidadMoneda)(); };
PipeCantidadMoneda.ɵpipe = i0.ɵɵdefinePipe({ name: "pipeCantidadMoneda", type: PipeCantidadMoneda, pure: true });
return PipeCantidadMoneda;
}());
exports.PipeCantidadMoneda = PipeCantidadMoneda;
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PipeCantidadMoneda, [{
type: core_1.Pipe,
args: [{ name: "pipeCantidadMoneda" }]
}], function () { return []; }, null); })();
//# sourceMappingURL=pipe-cantidadmoneda.pipe.js.map