Skip to content

Commit 03635f5

Browse files
fix(ref: no-ref): fix issues
1 parent 0d3c51b commit 03635f5

File tree

6 files changed

+162
-98
lines changed

6 files changed

+162
-98
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 19.0.5(2024-12-17)
2+
3+
### Fix
4+
5+
- Fix ([#1481](https://github.com/JsDaddy/ngx-mask/issues/1481))
6+
17
# 19.0.4(2024-12-13)
28

39
### Feature

bun.lockb

3.84 KB
Binary file not shown.

package.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mask",
3-
"version": "19.0.4",
3+
"version": "19.0.5",
44
"description": "Awesome ngx mask",
55
"license": "MIT",
66
"engines": {
@@ -60,67 +60,67 @@
6060
"url": "https://github.com/JsDaddy/ngx-mask.git"
6161
},
6262
"dependencies": {
63-
"@angular/animations": "19.0.3",
64-
"@angular/common": "19.0.3",
65-
"@angular/compiler": "19.0.3",
66-
"@angular/core": "19.0.3",
67-
"@angular/forms": "19.0.3",
68-
"@angular/platform-browser": "19.0.3",
69-
"@angular/platform-browser-dynamic": "19.0.3",
70-
"@angular/router": "19.0.3",
63+
"@angular/animations": "19.0.4",
64+
"@angular/common": "19.0.4",
65+
"@angular/compiler": "19.0.4",
66+
"@angular/core": "19.0.4",
67+
"@angular/forms": "19.0.4",
68+
"@angular/platform-browser": "19.0.4",
69+
"@angular/platform-browser-dynamic": "19.0.4",
70+
"@angular/router": "19.0.4",
7171
"@types/jest": "^29.5.14",
7272
"@types/mocha": "^10.0.10",
7373
"ajv": "^8.17.1",
7474
"cypress": "^13.16.1",
75-
"highlight.js": "11.10.0",
75+
"highlight.js": "11.11.0",
7676
"ngx-highlightjs": "12.0.0",
77-
"ngxtension": "^4.1.0",
77+
"ngxtension": "^4.2.0",
7878
"rxjs": "7.8.1",
7979
"semantic-release": "24.2.0",
8080
"semantic-release-export-data": "^1.1.0",
81-
"snyk": "^1.1294.2"
81+
"snyk": "^1.1294.3"
8282
},
8383
"devDependencies": {
84-
"@angular-devkit/build-angular": "19.0.3",
85-
"@angular-eslint/builder": "19.0.0",
86-
"@angular-eslint/eslint-plugin": "19.0.0",
87-
"@angular-eslint/eslint-plugin-template": "19.0.0",
88-
"@angular-eslint/schematics": "19.0.0",
89-
"@angular-eslint/template-parser": "19.0.0",
90-
"@angular/cli": "19.0.3",
91-
"@angular/compiler-cli": "19.0.3",
92-
"@angular/language-service": "19.0.3",
93-
"@commitlint/cli": "19.6.0",
84+
"@angular-devkit/build-angular": "19.0.5",
85+
"@angular-eslint/builder": "19.0.2",
86+
"@angular-eslint/eslint-plugin": "19.0.2",
87+
"@angular-eslint/eslint-plugin-template": "19.0.2",
88+
"@angular-eslint/schematics": "19.0.2",
89+
"@angular-eslint/template-parser": "19.0.2",
90+
"@angular/cli": "19.0.5",
91+
"@angular/compiler-cli": "19.0.4",
92+
"@angular/language-service": "19.0.4",
93+
"@commitlint/cli": "19.6.1",
9494
"@commitlint/config-conventional": "19.6.0",
9595
"@jscutlery/cypress-angular": "^0.9.22",
9696
"@types/highlight.js": "9.12.4",
9797
"@types/jasmine": "5.1.5",
98-
"@types/node": "22.10.1",
99-
"@typescript-eslint/eslint-plugin": "8.17.0",
100-
"@typescript-eslint/parser": "8.17.0",
98+
"@types/node": "22.10.2",
99+
"@typescript-eslint/eslint-plugin": "8.18.1",
100+
"@typescript-eslint/parser": "8.18.1",
101101
"@web/test-runner": "^0.19.0",
102102
"angular-cli-ghpages": "2.0.3",
103103
"angular-http-server": "1.12.0",
104-
"eslint": "9.16.0",
104+
"eslint": "9.17.0",
105105
"eslint-config-prettier": "9.1.0",
106106
"eslint-plugin-json": "4.0.1",
107107
"eslint-plugin-prettier": "5.2.1",
108108
"jasmine-core": "5.5.0",
109109
"jasmine-spec-reporter": "7.0.0",
110-
"lint-staged": "15.2.10",
110+
"lint-staged": "15.2.11",
111111
"markdownlint-cli": "0.43.0",
112112
"ng-packagr": "19.0.1",
113113
"npm-check-updates": "^17.1.11",
114114
"prettier": "3.4.2",
115-
"puppeteer": "23.10.1",
116-
"stylelint": "16.11.0",
115+
"puppeteer": "23.10.4",
116+
"stylelint": "16.12.0",
117117
"stylelint-config-prettier": "9.0.5",
118118
"stylelint-config-recommended-scss": "14.1.0",
119119
"stylelint-prettier": "5.0.2",
120120
"type-coverage": "^2.29.7",
121121
"typescript": "5.6.3",
122-
"angular-eslint": "^19.0.0",
123-
"typescript-eslint": "^8.17.0",
122+
"angular-eslint": "^19.0.2",
123+
"typescript-eslint": "^8.18.1",
124124
"tailwindcss": "^3.4.16",
125125
"bun-types": "^1.1.38",
126126
"postcss": "8.4.49",

projects/ngx-mask-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-mask",
3-
"version": "19.0.4",
3+
"version": "19.0.5",
44
"description": "awesome ngx mask",
55
"keywords": [
66
"ng2-mask",

projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts

Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,62 @@ export class NgxMaskApplierService {
197197
}
198198

199199
const precision: number = this.getPrecision(maskExpression);
200-
const decimalMarker = Array.isArray(this.decimalMarker)
201-
? this.thousandSeparator === MaskExpression.DOT
202-
? MaskExpression.COMMA
203-
: MaskExpression.DOT
204-
: this.decimalMarker;
200+
let decimalMarker = this.decimalMarker;
201+
202+
if (Array.isArray(this.decimalMarker)) {
203+
const marker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator);
204+
205+
decimalMarker = marker
206+
? marker
207+
: this.actualValue.includes(this.decimalMarker[0])
208+
? this.decimalMarker[0]
209+
: this.decimalMarker[1];
210+
}
211+
212+
if (backspaced) {
213+
const { decimalMarkerIndex, nonZeroIndex } = this._findFirstNonZeroAndDecimalIndex(
214+
processedValue,
215+
decimalMarker as '.' | ','
216+
);
217+
const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
218+
const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
219+
const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
220+
const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
221+
222+
if (
223+
(zeroIndexDecimalMarker && !nonZeroIndex) ||
224+
(zeroIndexMinus && firstIndexDecimalMarker && !nonZeroIndex) ||
225+
(zeroIndexNumberZero && !decimalMarkerIndex && !nonZeroIndex)
226+
) {
227+
processedValue = MaskExpression.NUMBER_ZERO;
228+
}
229+
230+
if (
231+
decimalMarkerIndex &&
232+
nonZeroIndex &&
233+
zeroIndexMinus &&
234+
processedPosition === 1
235+
) {
236+
if (decimalMarkerIndex < nonZeroIndex || decimalMarkerIndex > nonZeroIndex) {
237+
processedValue = MaskExpression.MINUS + processedValue.slice(nonZeroIndex);
238+
}
239+
}
240+
241+
if (!decimalMarkerIndex && nonZeroIndex && processedValue.length > nonZeroIndex) {
242+
processedValue = zeroIndexMinus
243+
? MaskExpression.MINUS + processedValue.slice(nonZeroIndex)
244+
: processedValue.slice(nonZeroIndex);
245+
}
246+
247+
if (decimalMarkerIndex && nonZeroIndex && processedPosition === 0) {
248+
if (decimalMarkerIndex < nonZeroIndex) {
249+
processedValue = processedValue.slice(decimalMarkerIndex - 1);
250+
}
251+
if (decimalMarkerIndex > nonZeroIndex) {
252+
processedValue = processedValue.slice(nonZeroIndex);
253+
}
254+
}
255+
}
205256

206257
if (precision === 0) {
207258
processedValue = this.allowNegativeNumbers
@@ -240,7 +291,8 @@ export class NgxMaskApplierService {
240291
if (
241292
processedValue[0] === MaskExpression.NUMBER_ZERO &&
242293
processedValue[1] !== decimalMarker &&
243-
processedValue[1] !== this.thousandSeparator
294+
processedValue[1] !== this.thousandSeparator &&
295+
!backspaced
244296
) {
245297
processedValue =
246298
processedValue.length > 1
@@ -252,6 +304,7 @@ export class NgxMaskApplierService {
252304
}
253305
if (
254306
this.allowNegativeNumbers &&
307+
!backspaced &&
255308
processedValue[0] === MaskExpression.MINUS &&
256309
(processedValue[1] === decimalMarker ||
257310
processedValue[1] === MaskExpression.NUMBER_ZERO)
@@ -272,61 +325,6 @@ export class NgxMaskApplierService {
272325
}
273326
}
274327

275-
if (backspaced) {
276-
const inputValueAfterZero = processedValue.slice(
277-
this._findFirstNonZeroDigitIndex(processedValue),
278-
processedValue.length
279-
);
280-
const positionOfZeroOrDecimalMarker =
281-
processedValue[processedPosition] === MaskExpression.NUMBER_ZERO ||
282-
processedValue[processedPosition] === decimalMarker;
283-
const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
284-
const firstIndexNumberZero = processedValue[1] === MaskExpression.NUMBER_ZERO;
285-
const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
286-
const zeroIndexThousand = processedValue[0] === this.thousandSeparator;
287-
const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
288-
const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
289-
const secondIndexDecimalMarker = processedValue[2] === decimalMarker;
290-
291-
if (zeroIndexNumberZero && firstIndexDecimalMarker && processedPosition === 0) {
292-
return processedValue;
293-
}
294-
295-
if (zeroIndexDecimalMarker && processedPosition === 0) {
296-
processedValue = inputValueAfterZero;
297-
}
298-
299-
if (
300-
zeroIndexNumberZero &&
301-
firstIndexDecimalMarker &&
302-
positionOfZeroOrDecimalMarker &&
303-
processedPosition < 2
304-
) {
305-
processedValue = inputValueAfterZero;
306-
}
307-
if (
308-
zeroIndexMinus &&
309-
firstIndexNumberZero &&
310-
secondIndexDecimalMarker &&
311-
positionOfZeroOrDecimalMarker &&
312-
processedPosition < 3
313-
) {
314-
processedValue = MaskExpression.MINUS + inputValueAfterZero;
315-
}
316-
317-
if (
318-
inputValueAfterZero !== MaskExpression.MINUS &&
319-
((processedPosition === 0 && (zeroIndexNumberZero || zeroIndexThousand)) ||
320-
(this.allowNegativeNumbers &&
321-
processedPosition === 1 &&
322-
zeroIndexMinus &&
323-
!firstIndexNumberZero))
324-
) {
325-
processedValue = zeroIndexMinus
326-
? MaskExpression.MINUS + inputValueAfterZero
327-
: inputValueAfterZero;
328-
}
329-
}
330328
// TODO: we had different rexexps here for the different cases... but tests dont seam to bother - check this
331329
// separator: no COMMA, dot-sep: no SPACE, COMMA OK, comma-sep: no SPACE, COMMA OK
332330

@@ -1036,13 +1034,29 @@ export class NgxMaskApplierService {
10361034
}
10371035
}
10381036

1039-
private _findFirstNonZeroDigitIndex(inputString: string): number {
1037+
private _findFirstNonZeroAndDecimalIndex(inputString: string, decimalMarker: '.' | ',') {
1038+
let decimalMarkerIndex: number | null = null;
1039+
let nonZeroIndex: number | null = null;
1040+
10401041
for (let i = 0; i < inputString.length; i++) {
10411042
const char = inputString[i];
1042-
if (char && char >= '1' && char <= '9') {
1043-
return i;
1043+
1044+
if (char === decimalMarker && decimalMarkerIndex === null) {
1045+
decimalMarkerIndex = i;
1046+
}
1047+
1048+
if (char && char >= '1' && char <= '9' && nonZeroIndex === null) {
1049+
nonZeroIndex = i;
1050+
}
1051+
1052+
if (decimalMarkerIndex !== null && nonZeroIndex !== null) {
1053+
break;
10441054
}
10451055
}
1046-
return -1;
1056+
1057+
return {
1058+
decimalMarkerIndex,
1059+
nonZeroIndex,
1060+
};
10471061
}
10481062
}

projects/ngx-mask-lib/src/test/separator.cy-spec.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe('Test Date Hh:m0', () => {
297297
.type('{leftArrow}'.repeat(2))
298298
.type('{backspace}')
299299
.should('have.value', '-0.14')
300-
.type('{leftArrow}'.repeat(2))
300+
.type('{leftArrow}')
301301
.type('{backspace}')
302302
.should('have.value', '-14');
303303
});
@@ -317,6 +317,7 @@ describe('Test Date Hh:m0', () => {
317317
.type('{leftArrow}'.repeat(2))
318318
.type('{backspace}')
319319
.should('have.value', '-1')
320+
.type('{rightArrow}')
320321
.type('{backspace}')
321322
.should('have.value', '-');
322323
});
@@ -462,4 +463,47 @@ describe('Test Date Hh:m0', () => {
462463
.type('{backspace}')
463464
.should('have.value', '5');
464465
});
466+
467+
it('should correct work after backspace separator.2 when after first digit 0', () => {
468+
cy.mount(CypressTestMaskComponent, {
469+
componentProperties: {
470+
mask: signal('separator.2'),
471+
decimalMarker: signal(','),
472+
thousandSeparator: signal(' '),
473+
},
474+
});
475+
476+
cy.get('#masked')
477+
.type('1 000 000,05')
478+
.should('have.value', '1 000 000,05')
479+
.type('{leftArrow}'.repeat(11))
480+
.type('{backspace}')
481+
.should('have.value', '0,05');
482+
483+
cy.get('#masked').clear();
484+
485+
cy.get('#masked')
486+
.type('60,05')
487+
.should('have.value', '60,05')
488+
.type('{leftArrow}'.repeat(4))
489+
.type('{backspace}')
490+
.should('have.value', '0,05');
491+
});
492+
493+
it('should correct work after backspace separator.2 when after first digit 0', () => {
494+
cy.mount(CypressTestMaskComponent, {
495+
componentProperties: {
496+
mask: signal('separator.2'),
497+
decimalMarker: signal('.'),
498+
thousandSeparator: signal(' '),
499+
},
500+
});
501+
502+
cy.get('#masked')
503+
.type('200.05')
504+
.should('have.value', '200.05')
505+
.type('{leftArrow}'.repeat(5))
506+
.type('{backspace}')
507+
.should('have.value', '0.05');
508+
});
465509
});

0 commit comments

Comments
 (0)