Skip to content

Commit

Permalink
fix(ref: no-ref): fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikamaldinov1 committed Dec 18, 2024
1 parent 0d3c51b commit 03635f5
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 98 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 19.0.5(2024-12-17)

### Fix

- Fix ([#1481](https://github.com/JsDaddy/ngx-mask/issues/1481))

# 19.0.4(2024-12-13)

### Feature
Expand Down
Binary file modified bun.lockb
Binary file not shown.
62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "19.0.4",
"version": "19.0.5",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down Expand Up @@ -60,67 +60,67 @@
"url": "https://github.com/JsDaddy/ngx-mask.git"
},
"dependencies": {
"@angular/animations": "19.0.3",
"@angular/common": "19.0.3",
"@angular/compiler": "19.0.3",
"@angular/core": "19.0.3",
"@angular/forms": "19.0.3",
"@angular/platform-browser": "19.0.3",
"@angular/platform-browser-dynamic": "19.0.3",
"@angular/router": "19.0.3",
"@angular/animations": "19.0.4",
"@angular/common": "19.0.4",
"@angular/compiler": "19.0.4",
"@angular/core": "19.0.4",
"@angular/forms": "19.0.4",
"@angular/platform-browser": "19.0.4",
"@angular/platform-browser-dynamic": "19.0.4",
"@angular/router": "19.0.4",
"@types/jest": "^29.5.14",
"@types/mocha": "^10.0.10",
"ajv": "^8.17.1",
"cypress": "^13.16.1",
"highlight.js": "11.10.0",
"highlight.js": "11.11.0",
"ngx-highlightjs": "12.0.0",
"ngxtension": "^4.1.0",
"ngxtension": "^4.2.0",
"rxjs": "7.8.1",
"semantic-release": "24.2.0",
"semantic-release-export-data": "^1.1.0",
"snyk": "^1.1294.2"
"snyk": "^1.1294.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "19.0.3",
"@angular-eslint/builder": "19.0.0",
"@angular-eslint/eslint-plugin": "19.0.0",
"@angular-eslint/eslint-plugin-template": "19.0.0",
"@angular-eslint/schematics": "19.0.0",
"@angular-eslint/template-parser": "19.0.0",
"@angular/cli": "19.0.3",
"@angular/compiler-cli": "19.0.3",
"@angular/language-service": "19.0.3",
"@commitlint/cli": "19.6.0",
"@angular-devkit/build-angular": "19.0.5",
"@angular-eslint/builder": "19.0.2",
"@angular-eslint/eslint-plugin": "19.0.2",
"@angular-eslint/eslint-plugin-template": "19.0.2",
"@angular-eslint/schematics": "19.0.2",
"@angular-eslint/template-parser": "19.0.2",
"@angular/cli": "19.0.5",
"@angular/compiler-cli": "19.0.4",
"@angular/language-service": "19.0.4",
"@commitlint/cli": "19.6.1",
"@commitlint/config-conventional": "19.6.0",
"@jscutlery/cypress-angular": "^0.9.22",
"@types/highlight.js": "9.12.4",
"@types/jasmine": "5.1.5",
"@types/node": "22.10.1",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"@types/node": "22.10.2",
"@typescript-eslint/eslint-plugin": "8.18.1",
"@typescript-eslint/parser": "8.18.1",
"@web/test-runner": "^0.19.0",
"angular-cli-ghpages": "2.0.3",
"angular-http-server": "1.12.0",
"eslint": "9.16.0",
"eslint": "9.17.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-json": "4.0.1",
"eslint-plugin-prettier": "5.2.1",
"jasmine-core": "5.5.0",
"jasmine-spec-reporter": "7.0.0",
"lint-staged": "15.2.10",
"lint-staged": "15.2.11",
"markdownlint-cli": "0.43.0",
"ng-packagr": "19.0.1",
"npm-check-updates": "^17.1.11",
"prettier": "3.4.2",
"puppeteer": "23.10.1",
"stylelint": "16.11.0",
"puppeteer": "23.10.4",
"stylelint": "16.12.0",
"stylelint-config-prettier": "9.0.5",
"stylelint-config-recommended-scss": "14.1.0",
"stylelint-prettier": "5.0.2",
"type-coverage": "^2.29.7",
"typescript": "5.6.3",
"angular-eslint": "^19.0.0",
"typescript-eslint": "^8.17.0",
"angular-eslint": "^19.0.2",
"typescript-eslint": "^8.18.1",
"tailwindcss": "^3.4.16",
"bun-types": "^1.1.38",
"postcss": "8.4.49",
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "19.0.4",
"version": "19.0.5",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
144 changes: 79 additions & 65 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,62 @@ export class NgxMaskApplierService {
}

const precision: number = this.getPrecision(maskExpression);
const decimalMarker = Array.isArray(this.decimalMarker)
? this.thousandSeparator === MaskExpression.DOT
? MaskExpression.COMMA
: MaskExpression.DOT
: this.decimalMarker;
let decimalMarker = this.decimalMarker;

if (Array.isArray(this.decimalMarker)) {
const marker = this.decimalMarker.find((dm) => dm !== this.thousandSeparator);

decimalMarker = marker
? marker
: this.actualValue.includes(this.decimalMarker[0])
? this.decimalMarker[0]
: this.decimalMarker[1];
}

if (backspaced) {
const { decimalMarkerIndex, nonZeroIndex } = this._findFirstNonZeroAndDecimalIndex(
processedValue,
decimalMarker as '.' | ','
);
const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
const firstIndexDecimalMarker = processedValue[1] === decimalMarker;

if (
(zeroIndexDecimalMarker && !nonZeroIndex) ||
(zeroIndexMinus && firstIndexDecimalMarker && !nonZeroIndex) ||
(zeroIndexNumberZero && !decimalMarkerIndex && !nonZeroIndex)
) {
processedValue = MaskExpression.NUMBER_ZERO;
}

if (
decimalMarkerIndex &&
nonZeroIndex &&
zeroIndexMinus &&
processedPosition === 1
) {
if (decimalMarkerIndex < nonZeroIndex || decimalMarkerIndex > nonZeroIndex) {
processedValue = MaskExpression.MINUS + processedValue.slice(nonZeroIndex);
}
}

if (!decimalMarkerIndex && nonZeroIndex && processedValue.length > nonZeroIndex) {
processedValue = zeroIndexMinus
? MaskExpression.MINUS + processedValue.slice(nonZeroIndex)
: processedValue.slice(nonZeroIndex);
}

if (decimalMarkerIndex && nonZeroIndex && processedPosition === 0) {
if (decimalMarkerIndex < nonZeroIndex) {
processedValue = processedValue.slice(decimalMarkerIndex - 1);
}
if (decimalMarkerIndex > nonZeroIndex) {
processedValue = processedValue.slice(nonZeroIndex);
}
}
}

if (precision === 0) {
processedValue = this.allowNegativeNumbers
Expand Down Expand Up @@ -240,7 +291,8 @@ export class NgxMaskApplierService {
if (
processedValue[0] === MaskExpression.NUMBER_ZERO &&
processedValue[1] !== decimalMarker &&
processedValue[1] !== this.thousandSeparator
processedValue[1] !== this.thousandSeparator &&
!backspaced
) {
processedValue =
processedValue.length > 1
Expand All @@ -252,6 +304,7 @@ export class NgxMaskApplierService {
}
if (
this.allowNegativeNumbers &&
!backspaced &&
processedValue[0] === MaskExpression.MINUS &&
(processedValue[1] === decimalMarker ||
processedValue[1] === MaskExpression.NUMBER_ZERO)
Expand All @@ -272,61 +325,6 @@ export class NgxMaskApplierService {
}
}

if (backspaced) {
const inputValueAfterZero = processedValue.slice(
this._findFirstNonZeroDigitIndex(processedValue),
processedValue.length
);
const positionOfZeroOrDecimalMarker =
processedValue[processedPosition] === MaskExpression.NUMBER_ZERO ||
processedValue[processedPosition] === decimalMarker;
const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
const firstIndexNumberZero = processedValue[1] === MaskExpression.NUMBER_ZERO;
const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
const zeroIndexThousand = processedValue[0] === this.thousandSeparator;
const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
const secondIndexDecimalMarker = processedValue[2] === decimalMarker;

if (zeroIndexNumberZero && firstIndexDecimalMarker && processedPosition === 0) {
return processedValue;
}

if (zeroIndexDecimalMarker && processedPosition === 0) {
processedValue = inputValueAfterZero;
}

if (
zeroIndexNumberZero &&
firstIndexDecimalMarker &&
positionOfZeroOrDecimalMarker &&
processedPosition < 2
) {
processedValue = inputValueAfterZero;
}
if (
zeroIndexMinus &&
firstIndexNumberZero &&
secondIndexDecimalMarker &&
positionOfZeroOrDecimalMarker &&
processedPosition < 3
) {
processedValue = MaskExpression.MINUS + inputValueAfterZero;
}

if (
inputValueAfterZero !== MaskExpression.MINUS &&
((processedPosition === 0 && (zeroIndexNumberZero || zeroIndexThousand)) ||
(this.allowNegativeNumbers &&
processedPosition === 1 &&
zeroIndexMinus &&
!firstIndexNumberZero))
) {
processedValue = zeroIndexMinus
? MaskExpression.MINUS + inputValueAfterZero
: inputValueAfterZero;
}
}
// TODO: we had different rexexps here for the different cases... but tests dont seam to bother - check this
// separator: no COMMA, dot-sep: no SPACE, COMMA OK, comma-sep: no SPACE, COMMA OK

Expand Down Expand Up @@ -1036,13 +1034,29 @@ export class NgxMaskApplierService {
}
}

private _findFirstNonZeroDigitIndex(inputString: string): number {
private _findFirstNonZeroAndDecimalIndex(inputString: string, decimalMarker: '.' | ',') {
let decimalMarkerIndex: number | null = null;
let nonZeroIndex: number | null = null;

for (let i = 0; i < inputString.length; i++) {
const char = inputString[i];
if (char && char >= '1' && char <= '9') {
return i;

if (char === decimalMarker && decimalMarkerIndex === null) {
decimalMarkerIndex = i;
}

if (char && char >= '1' && char <= '9' && nonZeroIndex === null) {
nonZeroIndex = i;
}

if (decimalMarkerIndex !== null && nonZeroIndex !== null) {
break;
}
}
return -1;

return {
decimalMarkerIndex,
nonZeroIndex,
};
}
}
46 changes: 45 additions & 1 deletion projects/ngx-mask-lib/src/test/separator.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Test Date Hh:m0', () => {
.type('{leftArrow}'.repeat(2))
.type('{backspace}')
.should('have.value', '-0.14')
.type('{leftArrow}'.repeat(2))
.type('{leftArrow}')
.type('{backspace}')
.should('have.value', '-14');
});
Expand All @@ -317,6 +317,7 @@ describe('Test Date Hh:m0', () => {
.type('{leftArrow}'.repeat(2))
.type('{backspace}')
.should('have.value', '-1')
.type('{rightArrow}')
.type('{backspace}')
.should('have.value', '-');
});
Expand Down Expand Up @@ -462,4 +463,47 @@ describe('Test Date Hh:m0', () => {
.type('{backspace}')
.should('have.value', '5');
});

it('should correct work after backspace separator.2 when after first digit 0', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('separator.2'),
decimalMarker: signal(','),
thousandSeparator: signal(' '),
},
});

cy.get('#masked')
.type('1 000 000,05')
.should('have.value', '1 000 000,05')
.type('{leftArrow}'.repeat(11))
.type('{backspace}')
.should('have.value', '0,05');

cy.get('#masked').clear();

cy.get('#masked')
.type('60,05')
.should('have.value', '60,05')
.type('{leftArrow}'.repeat(4))
.type('{backspace}')
.should('have.value', '0,05');
});

it('should correct work after backspace separator.2 when after first digit 0', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('separator.2'),
decimalMarker: signal('.'),
thousandSeparator: signal(' '),
},
});

cy.get('#masked')
.type('200.05')
.should('have.value', '200.05')
.type('{leftArrow}'.repeat(5))
.type('{backspace}')
.should('have.value', '0.05');
});
});

0 comments on commit 03635f5

Please sign in to comment.