Skip to content

Commit

Permalink
work for #4842
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaLarina committed Dec 26, 2023
1 parent bafaa3c commit 907f3bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/mask/number_mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function splitString(str: string, reverse = false, n = 3): Array<string>
return arr;
}

export function getNumberMaskedValue(str: string | number, mask: string, option?: INumberMaskOption): string {
export function getNumberMaskedValue(str: string | number, option?: INumberMaskOption): string {
const decimalSeparator = option?.decimal || settings.numberOptions.decimal;
const thousandsSeparator = option?.thousands || settings.numberOptions.thousands;
const precision = option?.precision || settings.numberOptions.precision;
Expand All @@ -93,7 +93,7 @@ export function getNumberMaskedValue(str: string | number, mask: string, option?
}
}

export function getNumberUnmaskedValue(str: string, mask: string, option?: INumberMaskOption): number {
export function getNumberUnmaskedValue(str: string, option?: INumberMaskOption): number {
const decimalSeparator = option?.decimal || settings.numberOptions.decimal;
const thousandsSeparator = option?.thousands || settings.numberOptions.thousands;
const precision = option?.precision || settings.numberOptions.precision;
Expand All @@ -115,12 +115,12 @@ export class InputMaskNumber extends InputMaskBase {
}

protected getMaskedValue(mask: string): string {
return getNumberMaskedValue(getNumberUnmaskedValue(this.input.value, mask, this.options), mask, this.options);
return getNumberMaskedValue(getNumberUnmaskedValue(this.input.value, this.options), this.options);
}

protected processMaskedValue(mask: string): IMaskedValue {
// return processValueWithPattern(this.input.value, mask, this._prevSelectionStart, this.input.selectionStart);
const text = getNumberMaskedValue(getNumberUnmaskedValue(this.input.value, mask, this.options), mask, this.options);
const text = getNumberMaskedValue(getNumberUnmaskedValue(this.input.value, this.options), this.options);
return { text: text, cursorPosition: this.input.selectionStart };
}
}
29 changes: 13 additions & 16 deletions tests/mask/mask_number_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,23 @@ QUnit.test("parsing numeric mask simple pattern", function(assert) {
});

QUnit.test("get numeric masked valid text", function(assert) {
const customMask = "9+";
assert.equal(getNumberMaskedValue(123, customMask), "123");
assert.equal(getNumberMaskedValue(123456, customMask), "123,456");
assert.equal(getNumberMaskedValue(123456.78, customMask), "123,456.78");
assert.equal(getNumberMaskedValue(123456.789, customMask), "123,456.78");
assert.equal(getNumberMaskedValue(123), "123");
assert.equal(getNumberMaskedValue(123456), "123,456");
assert.equal(getNumberMaskedValue(123456.78), "123,456.78");
assert.equal(getNumberMaskedValue(123456.789), "123,456.78");
});

QUnit.test("get numeric masked invalid text", function(assert) {
const customMask = "9+";
assert.equal(getNumberMaskedValue("", customMask), "0");
assert.equal(getNumberMaskedValue("9", customMask), "9");
assert.equal(getNumberMaskedValue("123A", customMask), "123");
assert.equal(getNumberMaskedValue("123a", customMask), "123");
assert.equal(getNumberMaskedValue(""), "0");
assert.equal(getNumberMaskedValue("9"), "9");
assert.equal(getNumberMaskedValue("123A"), "123");
assert.equal(getNumberMaskedValue("123a"), "123");
});

QUnit.test("get numeric unmasked valid text", function(assert) {
const customMask = "9+";
assert.equal(getNumberUnmaskedValue("123", customMask), 123);
assert.equal(getNumberUnmaskedValue("123,456", customMask), 123456);
assert.equal(getNumberUnmaskedValue("123,456.78", customMask), 123456.78);
assert.equal(getNumberUnmaskedValue("123,456.789", customMask), 123456.78);
assert.equal(getNumberUnmaskedValue("123,456,789,1011.12", customMask), 1234567891011.12);
assert.equal(getNumberUnmaskedValue("123"), 123);
assert.equal(getNumberUnmaskedValue("123,456"), 123456);
assert.equal(getNumberUnmaskedValue("123,456.78"), 123456.78);
assert.equal(getNumberUnmaskedValue("123,456.789"), 123456.78);
assert.equal(getNumberUnmaskedValue("123,456,789,101.12"), 123456789101.12);
});

0 comments on commit 907f3bd

Please sign in to comment.