UNPKG

@ngodings/ngx-rupiah

Version:

Angular directive mask for currency Rupiah/IDR support for NgModule or Reactive forms, pipe for currency Rupiah/IDR & pipe for terbilang in Rupiah/IDR

810 lines (797 loc) 35.2 kB
import * as i0 from '@angular/core'; import { InjectionToken, forwardRef, Directive, Optional, Inject, Input, HostListener, Injectable, Pipe, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { registerLocaleData, formatCurrency, CommonModule } from '@angular/common'; import localeID from '@angular/common/locales/id'; var RupiahMaskInputMode; (function (RupiahMaskInputMode) { RupiahMaskInputMode[RupiahMaskInputMode["FINANCIAL"] = 0] = "FINANCIAL"; RupiahMaskInputMode[RupiahMaskInputMode["NATURAL"] = 1] = "NATURAL"; })(RupiahMaskInputMode || (RupiahMaskInputMode = {})); let RUPIAH_MASK_CONFIG = new InjectionToken("currency.mask.config"); class InputManager { constructor(htmlInputElement) { this.htmlInputElement = htmlInputElement; } setCursorAt(position) { if (this.htmlInputElement.setSelectionRange) { this.htmlInputElement.focus(); this.htmlInputElement.setSelectionRange(position, position); } else if (this.htmlInputElement.createTextRange) { let textRange = this.htmlInputElement.createTextRange(); textRange.collapse(true); textRange.moveEnd("character", position); textRange.moveStart("character", position); textRange.select(); } } updateValueAndCursor(newRawValue, oldLength, selectionStart) { this.rawValue = newRawValue; let newLength = newRawValue.length; selectionStart = selectionStart - (oldLength - newLength); this.setCursorAt(selectionStart); } get canInputMoreNumbers() { let onlyNumbers = this.rawValue.replace(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g, ""); let haventReachedMaxLength = !(onlyNumbers.length >= this.htmlInputElement.maxLength && this.htmlInputElement.maxLength >= 0); let selectionStart = this.inputSelection.selectionStart; let selectionEnd = this.inputSelection.selectionEnd; let haveNumberSelected = !!(selectionStart != selectionEnd && this.htmlInputElement.value.substring(selectionStart, selectionEnd).match(/[^0-9\u0660-\u0669\u06F0-\u06F9]/)); let startWithZero = (this.htmlInputElement.value.substring(0, 1) == "0"); return haventReachedMaxLength || haveNumberSelected || startWithZero; } get inputSelection() { let selectionStart = 0; let selectionEnd = 0; if (typeof this.htmlInputElement.selectionStart == "number" && typeof this.htmlInputElement.selectionEnd == "number") { selectionStart = this.htmlInputElement.selectionStart; selectionEnd = this.htmlInputElement.selectionEnd; } else { let range = document.selection.createRange(); if (range && range.parentElement() == this.htmlInputElement) { let lenght = this.htmlInputElement.value.length; let normalizedValue = this.htmlInputElement.value.replace(/\r\n/g, "\n"); let startRange = this.htmlInputElement.createTextRange(); startRange.moveToBookmark(range.getBookmark()); let endRange = this.htmlInputElement.createTextRange(); endRange.collapse(false); if (startRange.compareEndPoints("StartToEnd", endRange) > -1) { selectionStart = selectionEnd = lenght; } else { selectionStart = -startRange.moveStart("character", -lenght); selectionStart += normalizedValue.slice(0, selectionStart).split("\n").length - 1; if (startRange.compareEndPoints("EndToEnd", endRange) > -1) { selectionEnd = lenght; } else { selectionEnd = -startRange.moveEnd("character", -lenght); selectionEnd += normalizedValue.slice(0, selectionEnd).split("\n").length - 1; } } } } return { selectionStart: selectionStart, selectionEnd: selectionEnd }; } get rawValue() { return this.htmlInputElement && this.htmlInputElement.value; } set rawValue(value) { this._storedRawValue = value; if (this.htmlInputElement) { this.htmlInputElement.value = value; } } get storedRawValue() { return this._storedRawValue || ''; } } class InputService { constructor(htmlInputElement, options) { this.htmlInputElement = htmlInputElement; this.options = options; this.SINGLE_DIGIT_REGEX = new RegExp(/^[0-9\u0660-\u0669\u06F0-\u06F9]$/); this.ONLY_NUMBERS_REGEX = new RegExp(/[^0-9\u0660-\u0669\u06F0-\u06F9]/g); this.PER_AR_NUMBER = new Map(); this.inputManager = new InputManager(htmlInputElement); this.initialize(); } initialize() { this.PER_AR_NUMBER.set("\u06F0", "0"); this.PER_AR_NUMBER.set("\u06F1", "1"); this.PER_AR_NUMBER.set("\u06F2", "2"); this.PER_AR_NUMBER.set("\u06F3", "3"); this.PER_AR_NUMBER.set("\u06F4", "4"); this.PER_AR_NUMBER.set("\u06F5", "5"); this.PER_AR_NUMBER.set("\u06F6", "6"); this.PER_AR_NUMBER.set("\u06F7", "7"); this.PER_AR_NUMBER.set("\u06F8", "8"); this.PER_AR_NUMBER.set("\u06F9", "9"); this.PER_AR_NUMBER.set("\u0660", "0"); this.PER_AR_NUMBER.set("\u0661", "1"); this.PER_AR_NUMBER.set("\u0662", "2"); this.PER_AR_NUMBER.set("\u0663", "3"); this.PER_AR_NUMBER.set("\u0664", "4"); this.PER_AR_NUMBER.set("\u0665", "5"); this.PER_AR_NUMBER.set("\u0666", "6"); this.PER_AR_NUMBER.set("\u0667", "7"); this.PER_AR_NUMBER.set("\u0668", "8"); this.PER_AR_NUMBER.set("\u0669", "9"); } addNumber(keyCode) { const { decimal, precision, inputMode } = this.options; let keyChar = String.fromCharCode(keyCode); const isDecimalChar = keyChar === this.options.decimal; if (!this.rawValue) { this.rawValue = this.applyMask(false, keyChar); let selectionStart = 0; if (inputMode === RupiahMaskInputMode.NATURAL && precision > 0) { selectionStart = this.rawValue.indexOf(decimal); if (isDecimalChar) { selectionStart++; } } this.updateFieldValue(selectionStart); } else { let selectionStart = this.inputSelection.selectionStart; let selectionEnd = this.inputSelection.selectionEnd; const rawValueStart = this.rawValue.substring(0, selectionStart); let rawValueEnd = this.rawValue.substring(selectionEnd, this.rawValue.length); // In natural mode, replace decimals instead of shifting them. const inDecimalPortion = rawValueStart.indexOf(decimal) !== -1; if (inputMode === RupiahMaskInputMode.NATURAL && inDecimalPortion && selectionStart === selectionEnd) { rawValueEnd = rawValueEnd.substring(1); } const newValue = rawValueStart + keyChar + rawValueEnd; let nextSelectionStart = selectionStart + 1; const isDecimalOrThousands = isDecimalChar || keyChar === this.options.thousands; if (isDecimalOrThousands && keyChar === rawValueEnd[0]) { // If the cursor is just before the decimal or thousands separator and the user types the // decimal or thousands separator, move the cursor past it. nextSelectionStart++; } else if (!this.SINGLE_DIGIT_REGEX.test(keyChar)) { // Ignore other non-numbers. return; } this.rawValue = newValue; this.updateFieldValue(nextSelectionStart); } } applyMask(isNumber, rawValue, disablePadAndTrim = false) { let { allowNegative, decimal, precision, prefix, suffix, thousands, min, max, inputMode } = this.options; rawValue = isNumber ? new Number(rawValue).toFixed(precision) : rawValue; let onlyNumbers = rawValue.replace(this.ONLY_NUMBERS_REGEX, ""); if (!onlyNumbers && rawValue !== decimal) { return ""; } if (inputMode === RupiahMaskInputMode.NATURAL && !isNumber && !disablePadAndTrim) { rawValue = this.padOrTrimPrecision(rawValue); onlyNumbers = rawValue.replace(this.ONLY_NUMBERS_REGEX, ""); } let integerPart = onlyNumbers.slice(0, onlyNumbers.length - precision) .replace(/^\u0660*/g, "") .replace(/^\u06F0*/g, "") .replace(/^0*/g, ""); if (integerPart == "") { integerPart = "0"; } let integerValue = parseInt(integerPart); integerPart = integerPart.replace(/\B(?=([0-9\u0660-\u0669\u06F0-\u06F9]{3})+(?![0-9\u0660-\u0669\u06F0-\u06F9]))/g, thousands); if (thousands && integerPart.startsWith(thousands)) { integerPart = integerPart.substring(1); } let newRawValue = integerPart; let decimalPart = onlyNumbers.slice(onlyNumbers.length - precision); let decimalValue = parseInt(decimalPart) || 0; let isNegative = rawValue.indexOf("-") > -1; // Ensure max is at least as large as min. max = (this.isNullOrUndefined(max) || this.isNullOrUndefined(min)) ? max : Math.max(max, min); // Ensure precision number works well with more than 2 digits // 23 / 100... 233 / 1000 and so on const divideBy = Number('1'.padEnd(precision + 1, '0')); // Restrict to the min and max values. let newValue = integerValue + (decimalValue / divideBy); newValue = isNegative ? -newValue : newValue; if (!this.isNullOrUndefined(max) && newValue > max) { return this.applyMask(true, max + ''); } else if (!this.isNullOrUndefined(min) && newValue < min) { return this.applyMask(true, min + ''); } if (precision > 0) { if (newRawValue == "0" && decimalPart.length < precision) { newRawValue += decimal + "0".repeat(precision - 1) + decimalPart; } else { newRawValue += decimal + decimalPart; } } // let isZero = newValue == 0; let operator = (isNegative && allowNegative /*&& !isZero */) ? "-" : ""; return operator + prefix + newRawValue + suffix; } padOrTrimPrecision(rawValue) { let { decimal, precision } = this.options; let decimalIndex = rawValue.lastIndexOf(decimal); if (decimalIndex === -1) { decimalIndex = rawValue.length; rawValue += decimal; } let decimalPortion = rawValue.substring(decimalIndex).replace(this.ONLY_NUMBERS_REGEX, ""); const actualPrecision = decimalPortion.length; if (actualPrecision < precision) { for (let i = actualPrecision; i < precision; i++) { decimalPortion += '0'; } } else if (actualPrecision > precision) { decimalPortion = decimalPortion.substring(0, decimalPortion.length + precision - actualPrecision); } return rawValue.substring(0, decimalIndex) + decimal + decimalPortion; } clearMask(rawValue) { if (this.isNullable() && rawValue === "") return 0; let value = (rawValue || "0").replace(this.options.prefix, "").replace(this.options.suffix, ""); if (this.options.thousands) { value = value.replace(new RegExp("\\" + this.options.thousands, "g"), ""); } if (this.options.decimal) { value = value.replace(this.options.decimal, "."); } this.PER_AR_NUMBER.forEach((val, key) => { const re = new RegExp(key, "g"); value = value.replace(re, val); }); return parseFloat(value); } changeToNegative() { if (this.options.allowNegative /*&& this.rawValue != ""*/ && this.rawValue.charAt(0) != "-" /*&& this.value != 0*/) { // Apply the mask to ensure the min and max values are enforced. this.rawValue = this.applyMask(false, "-" + (this.rawValue ? this.rawValue : '0')); } } changeToPositive() { // Apply the mask to ensure the min and max values are enforced. this.rawValue = this.applyMask(false, this.rawValue.replace("-", "")); } removeNumber(keyCode) { let { decimal, thousands, prefix, suffix, inputMode } = this.options; if (this.isNullable() && this.value == 0) { this.rawValue = ''; return; } let selectionEnd = this.inputSelection.selectionEnd; let selectionStart = this.inputSelection.selectionStart; const suffixStart = this.rawValue.length - suffix.length; selectionEnd = Math.min(suffixStart, Math.max(selectionEnd, prefix.length)); selectionStart = Math.min(suffixStart, Math.max(selectionStart, prefix.length)); // Check if selection was entirely in the prefix or suffix. if (selectionStart === selectionEnd && this.inputSelection.selectionStart !== this.inputSelection.selectionEnd) { this.updateFieldValue(selectionStart); return; } let decimalIndex = this.rawValue.indexOf(decimal); if (decimalIndex === -1) { decimalIndex = this.rawValue.length; } let shiftSelection = 0; let insertChars = ''; const isCursorInDecimals = decimalIndex < selectionEnd; const isCursorImmediatelyAfterDecimalPoint = decimalIndex + 1 === selectionEnd; if (selectionEnd === selectionStart) { if (keyCode == 8) { if (selectionStart <= prefix.length) { return; } selectionStart--; // If previous char isn't a number, go back one more. if (!this.rawValue.substr(selectionStart, 1).match(/\d/)) { selectionStart--; } // In natural mode, jump backwards when in decimal portion of number. if (inputMode === RupiahMaskInputMode.NATURAL && isCursorInDecimals) { shiftSelection = -1; // when removing a single whole number, replace it with 0 if (isCursorImmediatelyAfterDecimalPoint && this.value < 10 && this.value > -10) { insertChars += '0'; } } } else if (keyCode == 46 || keyCode == 63272) { if (selectionStart === suffixStart) { return; } selectionEnd++; // If next char isn't a number, go one more. if (!this.rawValue.substr(selectionStart, 1).match(/\d/)) { selectionStart++; selectionEnd++; } } } // In natural mode, replace decimals with 0s. if (inputMode === RupiahMaskInputMode.NATURAL && selectionStart > decimalIndex) { const replacedDecimalCount = selectionEnd - selectionStart; for (let i = 0; i < replacedDecimalCount; i++) { insertChars += '0'; } } let selectionFromEnd = this.rawValue.length - selectionEnd; this.rawValue = this.rawValue.substring(0, selectionStart) + insertChars + this.rawValue.substring(selectionEnd); // Remove leading thousand separator from raw value. const startChar = this.rawValue.substr(prefix.length, 1); if (startChar === thousands) { this.rawValue = this.rawValue.substring(0, prefix.length) + this.rawValue.substring(prefix.length + 1); selectionFromEnd = Math.min(selectionFromEnd, this.rawValue.length - prefix.length); } this.updateFieldValue(this.rawValue.length - selectionFromEnd + shiftSelection, true); } updateFieldValue(selectionStart, disablePadAndTrim = false) { let newRawValue = this.applyMask(false, this.rawValue || "", disablePadAndTrim); selectionStart = selectionStart == undefined ? this.rawValue.length : selectionStart; selectionStart = Math.max(this.options.prefix.length, Math.min(selectionStart, this.rawValue.length - this.options.suffix.length)); this.inputManager.updateValueAndCursor(newRawValue, this.rawValue.length, selectionStart); } updateOptions(options) { let value = this.value; this.options = options; this.value = value; } prefixLength() { return this.options.prefix.length; } suffixLength() { return this.options.suffix.length; } isNullable() { return this.options.nullable; } get canInputMoreNumbers() { return this.inputManager.canInputMoreNumbers; } get inputSelection() { return this.inputManager.inputSelection; } get rawValue() { return this.inputManager.rawValue; } set rawValue(value) { this.inputManager.rawValue = value; } get storedRawValue() { return this.inputManager.storedRawValue; } get value() { return this.clearMask(this.rawValue); } set value(value) { this.rawValue = this.applyMask(true, "" + value); } isNullOrUndefined(value) { return value === null || value === undefined; } } class InputHandler { constructor(htmlInputElement, options) { this.inputService = new InputService(htmlInputElement, options); } handleCut(event) { setTimeout(() => { this.inputService.updateFieldValue(); this.setValue(this.inputService.value); this.onModelChange(this.inputService.value); }, 0); } handleInput(event) { let selectionStart = this.inputService.inputSelection.selectionStart; let keyCode = this.inputService.rawValue.charCodeAt(selectionStart - 1); let rawValueLength = this.inputService.rawValue.length; let storedRawValueLength = this.inputService.storedRawValue.length; if (Math.abs(rawValueLength - storedRawValueLength) != 1) { this.inputService.updateFieldValue(selectionStart); this.onModelChange(this.inputService.value); return; } // Restore the old value. this.inputService.rawValue = this.inputService.storedRawValue; if (rawValueLength < storedRawValueLength) { // Chrome Android seems to move the cursor in response to a backspace AFTER processing the // input event, so we need to wrap this in a timeout. this.timer(() => { // Move the cursor to just after the deleted value. this.inputService.updateFieldValue(selectionStart + 1); // Then backspace it. this.inputService.removeNumber(8); this.onModelChange(this.inputService.value); }, 0); } if (rawValueLength > storedRawValueLength) { // Move the cursor to just before the new value. this.inputService.updateFieldValue(selectionStart - 1); // Process the character like a keypress. this.handleKeypressImpl(keyCode); } } handleKeydown(event) { let keyCode = event.which || event.charCode || event.keyCode; if (keyCode == 8 || keyCode == 46 || keyCode == 63272) { event.preventDefault(); if (this.inputService.inputSelection.selectionStart <= this.inputService.prefixLength() && this.inputService.inputSelection.selectionEnd >= this.inputService.rawValue.length - this.inputService.suffixLength()) { this.clearValue(); } else { this.inputService.removeNumber(keyCode); this.onModelChange(this.inputService.value); } } } clearValue() { this.setValue(this.inputService.isNullable() ? 0 : 0); this.onModelChange(this.inputService.value); } handleKeypress(event) { let keyCode = event.which || event.charCode || event.keyCode; event.preventDefault(); if (keyCode === 97 && event.ctrlKey) { return; } this.handleKeypressImpl(keyCode); } handleKeypressImpl(keyCode) { switch (keyCode) { case undefined: case 9: case 13: return; case 43: this.inputService.changeToPositive(); break; case 45: this.inputService.changeToNegative(); break; default: if (this.inputService.canInputMoreNumbers) { let selectionRangeLength = Math.abs(this.inputService.inputSelection.selectionEnd - this.inputService.inputSelection.selectionStart); if (selectionRangeLength == this.inputService.rawValue.length) { this.setValue(0); } this.inputService.addNumber(keyCode); } break; } this.onModelChange(this.inputService.value); } handlePaste(event) { setTimeout(() => { this.inputService.updateFieldValue(); this.setValue(this.inputService.value); this.onModelChange(this.inputService.value); }, 1); } updateOptions(options) { this.inputService.updateOptions(options); } getOnModelChange() { return this.onModelChange; } setOnModelChange(callbackFunction) { this.onModelChange = callbackFunction; } getOnModelTouched() { return this.onModelTouched; } setOnModelTouched(callbackFunction) { this.onModelTouched = callbackFunction; } setValue(value) { this.inputService.value = value; } /** * Passthrough to setTimeout that can be stubbed out in tests. */ timer(callback, delayMillis) { setTimeout(callback, delayMillis); } } const RUPIAHMASKDIRECTIVE_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => RupiahMaskDirective), multi: true, }; class RupiahMaskDirective { constructor(currencyMaskConfig, elementRef, keyValueDiffers) { this.currencyMaskConfig = currencyMaskConfig; this.elementRef = elementRef; this.keyValueDiffers = keyValueDiffers; this.options = {}; this.optionsTemplate = { align: "right", allowNegative: true, allowZero: true, decimal: ".", precision: 2, prefix: "Rp ", suffix: "", thousands: ",", nullable: false, inputMode: RupiahMaskInputMode.FINANCIAL }; if (currencyMaskConfig) { this.optionsTemplate = currencyMaskConfig; } this.keyValueDiffer = keyValueDiffers.find({}).create(); } ngAfterViewInit() { this.elementRef.nativeElement.style.textAlign = this.options && this.options.align ? this.options.align : this.optionsTemplate.align; } ngDoCheck() { if (this.keyValueDiffer.diff(this.options)) { this.elementRef.nativeElement.style.textAlign = this.options.align ? this.options.align : this.optionsTemplate.align; this.inputHandler.updateOptions(Object.assign({}, this.optionsTemplate, this.options)); } } ngOnInit() { this.inputHandler = new InputHandler(this.elementRef.nativeElement, Object.assign({}, this.optionsTemplate, this.options)); } handleBlur(event) { this.inputHandler.getOnModelTouched().apply(event); } handleCut(event) { if (!this.isChromeAndroid()) { !this.isReadOnly() && this.inputHandler.handleCut(event); } } handleInput(event) { if (this.isChromeAndroid()) { !this.isReadOnly() && this.inputHandler.handleInput(event); } } handleKeydown(event) { if (!this.isChromeAndroid()) { !this.isReadOnly() && this.inputHandler.handleKeydown(event); } } handleKeypress(event) { if (!this.isChromeAndroid()) { !this.isReadOnly() && this.inputHandler.handleKeypress(event); } } handlePaste(event) { if (!this.isChromeAndroid()) { !this.isReadOnly() && this.inputHandler.handlePaste(event); } } handleDrop(event) { if (!this.isChromeAndroid()) { event.preventDefault(); } } isChromeAndroid() { return /chrome/i.test(navigator.userAgent) && /android/i.test(navigator.userAgent); } isReadOnly() { return this.elementRef.nativeElement.hasAttribute('readonly'); } registerOnChange(callbackFunction) { this.inputHandler.setOnModelChange(callbackFunction); } registerOnTouched(callbackFunction) { this.inputHandler.setOnModelTouched(callbackFunction); } setDisabledState(value) { this.elementRef.nativeElement.disabled = value; } writeValue(value) { this.inputHandler.setValue(value); } } RupiahMaskDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahMaskDirective, deps: [{ token: RUPIAH_MASK_CONFIG, optional: true }, { token: i0.ElementRef }, { token: i0.KeyValueDiffers }], target: i0.ɵɵFactoryTarget.Directive }); RupiahMaskDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.0.4", type: RupiahMaskDirective, selector: "[rupiahMask]", inputs: { options: "options" }, host: { listeners: { "blur": "handleBlur($event)", "cut": "handleCut($event)", "input": "handleInput($event)", "keydown": "handleKeydown($event)", "keypress": "handleKeypress($event)", "paste": "handlePaste($event)", "drop": "handleDrop($event)" } }, providers: [RUPIAHMASKDIRECTIVE_VALUE_ACCESSOR], ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahMaskDirective, decorators: [{ type: Directive, args: [{ selector: "[rupiahMask]", providers: [RUPIAHMASKDIRECTIVE_VALUE_ACCESSOR] }] }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [RUPIAH_MASK_CONFIG] }] }, { type: i0.ElementRef }, { type: i0.KeyValueDiffers }]; }, propDecorators: { options: [{ type: Input }], handleBlur: [{ type: HostListener, args: ["blur", ["$event"]] }], handleCut: [{ type: HostListener, args: ["cut", ["$event"]] }], handleInput: [{ type: HostListener, args: ["input", ["$event"]] }], handleKeydown: [{ type: HostListener, args: ["keydown", ["$event"]] }], handleKeypress: [{ type: HostListener, args: ["keypress", ["$event"]] }], handlePaste: [{ type: HostListener, args: ["paste", ["$event"]] }], handleDrop: [{ type: HostListener, args: ["drop", ["$event"]] }] } }); class RupiahService { getTerbilang(value) { let valueString = String(value); let result = ''; let i = 0; let j = 0; const angka = new Array('0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'); const kata = new Array('', 'Satu', 'Dua', 'Tiga', 'Empat', 'Lima', 'Enam', 'Tujuh', 'Delapan', 'Sembilan'); const tingkat = new Array('', 'Ribu', 'Juta', 'Milyar', 'Triliun'); const panjang_valueString = valueString.length; /* pengujian panjang valueString */ if (panjang_valueString > 15) { result = "Diluar Batas"; return result; } /* mengambil angka-angka yang ada dalam valueString, dimasukkan ke dalam array */ for (i = 1; i <= panjang_valueString; i++) { angka[i] = valueString.substr(-(i), 1); } i = 1; j = 0; result = ""; /* mulai proses iterasi terhadap array angka */ while (i <= panjang_valueString) { let subresult = ""; let kata1 = ""; let kata2 = ""; let kata3 = ""; /* untuk Ratusan */ if (angka[i + 2] != "0") { if (angka[i + 2] == "1") { kata1 = "Seratus"; } else { kata1 = kata[angka[i + 2]] + " Ratus"; } } /* untuk Puluhan atau Belasan */ if (angka[i + 1] != "0") { if (angka[i + 1] == "1") { if (angka[i] == "0") { kata2 = "Sepuluh"; } else if (angka[i] == "1") { kata2 = "Sebelas"; } else { kata2 = kata[angka[i]] + " Belas"; } } else { kata2 = kata[angka[i + 1]] + " Puluh"; } } /* untuk Satuan */ if (angka[i] != "0") { if (angka[i + 1] != "1") { kata3 = kata[angka[i]]; } } /* pengujian angka apakah tidak nol semua, lalu ditambahkan tingkat */ if ((angka[i] != "0") || (angka[i + 1] != "0") || (angka[i + 2] != "0")) { subresult = kata1 + " " + kata2 + " " + kata3 + " " + tingkat[j] + " "; } /* gabungkan variabe sub result (untuk Satu blok 3 angka) ke variabel result */ result = subresult + result; i = i + 3; j = j + 1; } /* mengganti Satu Ribu jadi Seribu jika diperlukan */ if ((angka[5] == "0") && (angka[6] == "0")) { result = result.replace("Satu Ribu", "Seribu"); } return result + "Rupiah"; } } RupiahService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); RupiahService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }] }); class TerbilangPipe { constructor(rupiahService) { this.rupiahService = rupiahService; } transform(value) { if (value == undefined || value == null) { return '-'; } return this.rupiahService.getTerbilang(value); } } TerbilangPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: TerbilangPipe, deps: [{ token: RupiahService }], target: i0.ɵɵFactoryTarget.Pipe }); TerbilangPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: TerbilangPipe, name: "terbilangPipe" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: TerbilangPipe, decorators: [{ type: Pipe, args: [{ name: 'terbilangPipe' }] }], ctorParameters: function () { return [{ type: RupiahService }]; } }); class RupiahPipe { constructor() { registerLocaleData(localeID, 'id'); } transform(value, position = 'start') { if (value == undefined || value == null) { return '-'; } let price = formatCurrency(value, 'id-ID', '', 'IDR', '1.2-2'); let result = ''; if (position === 'start') { result = 'Rp' + price; } else if (position === 'end') { result = price + ' Rupiah'; } else { result = price; } return result; } } RupiahPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); RupiahPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: RupiahPipe, name: "rupiahPipe" }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: RupiahPipe, decorators: [{ type: Pipe, args: [{ name: 'rupiahPipe' }] }], ctorParameters: function () { return []; } }); class NgxRupiahModule { static forRoot(config) { return { ngModule: NgxRupiahModule, providers: [{ provide: RUPIAH_MASK_CONFIG, useValue: config, }] }; } } NgxRupiahModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: NgxRupiahModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); NgxRupiahModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.4", ngImport: i0, type: NgxRupiahModule, declarations: [RupiahMaskDirective, TerbilangPipe, RupiahPipe], imports: [CommonModule, FormsModule], exports: [RupiahMaskDirective, TerbilangPipe, RupiahPipe] }); NgxRupiahModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: NgxRupiahModule, imports: [CommonModule, FormsModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.4", ngImport: i0, type: NgxRupiahModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, FormsModule], declarations: [RupiahMaskDirective, TerbilangPipe, RupiahPipe], exports: [RupiahMaskDirective, TerbilangPipe, RupiahPipe] }] }] }); /* * Public API Surface of ngx-rupiah */ /** * Generated bundle index. Do not edit. */ export { InputHandler, InputManager, InputService, NgxRupiahModule, RUPIAHMASKDIRECTIVE_VALUE_ACCESSOR, RUPIAH_MASK_CONFIG, RupiahMaskDirective, RupiahMaskInputMode, RupiahPipe, RupiahService, TerbilangPipe }; //# sourceMappingURL=ngodings-ngx-rupiah.mjs.map //# sourceMappingURL=ngodings-ngx-rupiah.mjs.map