diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index 4e0a593a..712ab755 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -2,10 +2,6 @@ name: build and quality on: [push] -env: - snyk_token: ${{ secrets.SNYK_TOKEN }} - REF: ${{ github.head_ref || github.ref_name }} - jobs: quality-check: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 87c3b4e7..1de51cb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 17.0.9(2024-07-02) + +### Fix + +- Fix ([#1349](https://github.com/JsDaddy/ngx-mask/issues/1349)) +- Fix ([#1354](https://github.com/JsDaddy/ngx-mask/issues/1354)) +- Fix ([#1369](https://github.com/JsDaddy/ngx-mask/issues/1369)) +- Fix ([#1378](https://github.com/JsDaddy/ngx-mask/issues/1378)) +- Fix ([#1377](https://github.com/JsDaddy/ngx-mask/issues/1377)) + + + # 17.0.8(2024-04-30) ### Fix diff --git a/bun.lockb b/bun.lockb index 16c3efdb..021709b4 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/cypress.config.ts b/cypress.config.ts index ffc94696..61b37c42 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'cypress'; + export default defineConfig({ projectId: 'qhyo66', component: { diff --git a/package.json b/package.json index 8c9d3f39..d142a801 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.0.8", + "version": "17.0.9", "description": "Awesome ngx mask", "license": "MIT", "engines": { @@ -68,6 +68,8 @@ "@angular/platform-browser": "17.3.8", "@angular/platform-browser-dynamic": "17.3.8", "@angular/router": "17.3.8", + "ajv": "^8.16.0", + "cypress": "^13.13.0", "highlight.js": "11.9.0", "ngx-highlightjs": "10.0.0", "rxjs": "7.8.1", @@ -96,7 +98,6 @@ "@web/test-runner": "^0.18.1", "angular-cli-ghpages": "1.0.7", "angular-http-server": "1.12.0", - "cypress": "13.9.0", "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-json": "3.1.0", diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index 465c4a25..d38772ad 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "17.0.8", + "version": "17.0.9", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts index 821a2a3f..4cbdc5a2 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts @@ -87,7 +87,7 @@ export class NgxMaskApplierService { position = 0, justPasted = false, backspaced = false, - // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any cb: (...args: any[]) => any = () => {} ): string { if (!maskExpression || typeof inputValue !== 'string') { @@ -116,7 +116,6 @@ export class NgxMaskApplierService { this.allowNegativeNumbers && inputValue.slice(cursor, cursor + 1) === MaskExpression.MINUS ) { - // eslint-disable-next-line no-param-reassign result += inputValue.slice(cursor, cursor + 1); } if (maskExpression === MaskExpression.IP) { @@ -223,7 +222,6 @@ export class NgxMaskApplierService { ? inputValue.slice(1, inputValue.length) : inputValue; } else { - // eslint-disable-next-line no-param-reassign if (inputValue[0] === decimalMarker && inputValue.length > 1) { // eslint-disable-next-line no-param-reassign inputValue = @@ -287,14 +285,6 @@ export class NgxMaskApplierService { // eslint-disable-next-line no-param-reassign inputValue = MaskExpression.MINUS + inputValue.slice(3, inputValue.length); } - // eslint-disable-next-line no-param-reassign - inputValue = this._compareOrIncludes( - inputValue[inputValue.length - 1], - this.decimalMarker, - this.thousandSeparator - ) - ? inputValue.slice(0, inputValue.length - 1) - : inputValue; } // 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 @@ -359,7 +349,8 @@ export class NgxMaskApplierService { result[position - 1] === this.decimalMarker || shiftStep === -4 || shiftStep === -3 || - result[position] === MaskExpression.COMMA + result[position] === MaskExpression.COMMA || + result[position] === MaskExpression.WHITE_SPACE ) { this._shift.clear(); this._shift.add(position - 1); @@ -381,7 +372,6 @@ export class NgxMaskApplierService { } } else { for ( - // eslint-disable-next-line let i: number = 0, inputSymbol: string = inputArray[0]!; i < inputArray.length; i++, inputSymbol = inputArray[i] ?? MaskExpression.EMPTY_STRING diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts b/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts index edec4d84..279ca6dc 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts @@ -42,7 +42,6 @@ import { MaskExpression } from './ngx-mask-expression.enum'; exportAs: 'mask,ngxMask', }) export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Validator { - // eslint-disable-next-line @angular-eslint/no-input-rename @Input('mask') public maskExpression: string | undefined | null = ''; @Input() public specialCharacters: IConfig['specialCharacters'] = []; @@ -116,10 +115,9 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida protected _config = inject(NGX_MASK_CONFIG); - // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any public onChange = (_: any) => {}; - // eslint-disable-next-line @typescript-eslint/no-empty-function public onTouch = () => {}; public ngOnChanges(changes: SimpleChanges): void { @@ -263,7 +261,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida this._applyMask(); } - // eslint-disable-next-line complexity public validate({ value }: FormControl): ValidationErrors | null { if (!this._maskService.validation || !this._maskValue) { return null; @@ -778,7 +775,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida } } - // eslint-disable-next-line complexity @HostListener('keydown', ['$event']) public onKeyDown(e: CustomKeyboardEvent): void { if (!this._maskValue) { @@ -913,17 +909,15 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida this._maskService._currentValue = ''; this._maskService._previousValue = ''; } - // eslint-disable-next-line no-param-reassign + let inputValue: string | number | null | undefined = controlValue; if ( typeof inputValue === 'number' || this._maskValue.startsWith(MaskExpression.SEPARATOR) ) { - // eslint-disable-next-line no-param-reassign inputValue = String(inputValue); const localeDecimalMarker = this._maskService.currentLocaleDecimalMarker(); if (!Array.isArray(this._maskService.decimalMarker)) { - // eslint-disable-next-line no-param-reassign inputValue = this._maskService.decimalMarker !== localeDecimalMarker ? inputValue.replace( @@ -932,26 +926,23 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida ) : inputValue; } - if ( - Array.isArray(this._maskService.decimalMarker) && - this.decimalMarker === MaskExpression.DOT - ) { - this._maskService.decimalMarker = MaskExpression.COMMA; - } + if ( this._maskService.leadZero && inputValue && this.maskExpression && this.dropSpecialCharacters !== false ) { - // eslint-disable-next-line no-param-reassign inputValue = this._maskService._checkPrecision( this._maskService.maskExpression, inputValue as string ); } - if (this._maskService.decimalMarker === MaskExpression.COMMA) { - // eslint-disable-next-line no-param-reassign + if ( + this.decimalMarker === MaskExpression.COMMA || + (Array.isArray(this._maskService.decimalMarker) && + this.thousandSeparator === MaskExpression.DOT) + ) { inputValue = inputValue .toString() .replace(MaskExpression.DOT, MaskExpression.COMMA); @@ -968,7 +959,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida } if (typeof inputValue !== 'string') { - // eslint-disable-next-line no-param-reassign inputValue = ''; } diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts index 1f4880ce..7b42ca0b 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts @@ -36,7 +36,7 @@ export class NgxMaskService extends NgxMaskApplierService { private _end!: number; - // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any public onChange = (_: any) => {}; public readonly _elementRef = inject(ElementRef, { optional: true }); @@ -47,14 +47,13 @@ export class NgxMaskService extends NgxMaskApplierService { private readonly _renderer = inject(Renderer2, { optional: true }); - // eslint-disable-next-line complexity public override applyMask( inputValue: string, maskExpression: string, position = 0, justPasted = false, backspaced = false, - // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any cb: (...args: any[]) => any = () => {} ): string { if (!maskExpression) { @@ -85,7 +84,7 @@ export class NgxMaskService extends NgxMaskApplierService { ? inputValue.split(MaskExpression.EMPTY_STRING) : this.actualValue.split(MaskExpression.EMPTY_STRING); // eslint-disable @typescript-eslint/no-unused-expressions - // eslint-disable-next-line @typescript-eslint/no-unused-expressions + if (typeof this.selStart === 'object' && typeof this.selEnd === 'object') { this.selStart = Number(this.selStart); this.selEnd = Number(this.selEnd); @@ -137,7 +136,7 @@ export class NgxMaskService extends NgxMaskApplierService { // eslint-disable-next-line no-param-reassign position = position - 2; } - // eslint-disable-next-line no-param-reassign + this.deletedSpecialCharacter = false; } if ( @@ -184,7 +183,6 @@ export class NgxMaskService extends NgxMaskApplierService { ) { this.decimalMarker = MaskExpression.COMMA; } - // b) remove decimal marker from list of special characters to mask if ( this.maskExpression.startsWith(MaskExpression.SEPARATOR) && @@ -249,7 +247,7 @@ export class NgxMaskService extends NgxMaskApplierService { position: number, justPasted: boolean, backspaced: boolean, - // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any cb: (...args: any[]) => any = () => {} ): void { const formElement = this._elementRef?.nativeElement; diff --git a/projects/ngx-mask-lib/src/test/separator.spec.ts b/projects/ngx-mask-lib/src/test/separator.spec.ts index 1795fb69..0ff2d767 100644 --- a/projects/ngx-mask-lib/src/test/separator.spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.spec.ts @@ -1635,4 +1635,79 @@ describe('Separator: Mask', () => { expect(inputTarget.value).toBe('1.255,78'); }); })); + + it('should work when decimalMarker have default value separator.2', fakeAsync(() => { + component.mask = 'separator.2'; + component.thousandSeparator = ','; + fixture.detectChanges(); + + equal('1', '1', fixture); + equal('12', '12', fixture); + equal('123', '123', fixture); + equal('1234', '1,234', fixture); + })); + + it('should work when decimalMarker have default value separator.3', fakeAsync(() => { + component.mask = 'separator.3'; + component.thousandSeparator = ','; + fixture.detectChanges(); + + equal('1', '1', fixture); + equal('12', '12', fixture); + equal('123', '123', fixture); + equal('1234', '1,234', fixture); + })); + + it('should work when decimalMarker have default value separator.1', fakeAsync(() => { + component.mask = 'separator.3'; + component.thousandSeparator = ','; + fixture.detectChanges(); + + equal('1', '1', fixture); + equal('12', '12', fixture); + equal('123', '123', fixture); + equal('1234', '1,234', fixture); + })); + + it('should not delete decimalMarker ,', () => { + component.mask = 'separator.2'; + component.decimalMarker = ','; + const inputElement = fixture.nativeElement.querySelector('input'); + + inputElement.value = '1,23'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(4, 4); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '1,2'; + inputElement.setSelectionRange(3, 3); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '1,'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('1,'); + }); + + it('should not delete decimalMarker .', () => { + component.mask = 'separator.2'; + component.decimalMarker = '.'; + const inputElement = fixture.nativeElement.querySelector('input'); + + inputElement.value = '12.23'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + inputElement.setSelectionRange(4, 4); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '12.2'; + inputElement.setSelectionRange(3, 3); + inputElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace' })); + inputElement.value = '12.'; + inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + + expect(inputElement.value).toBe('12.'); + }); }); diff --git a/src/libraries b/src/libraries index f402f517..bb8749e7 160000 --- a/src/libraries +++ b/src/libraries @@ -1 +1 @@ -Subproject commit f402f51789609e8de8500d39ff80cdcb68f89bb9 +Subproject commit bb8749e7465ce43652ddc4d3272b233435a5df7d