Skip to content

Commit

Permalink
fix(ref: no-ref): fix issues
Browse files Browse the repository at this point in the history
* fix(ref: no-ref): fix issues

* fix(ref: no-ref): fix issues

* fix(ref: no-ref): fix issues

* fix(ref: no-ref): fix issues

* fix(ref: no-ref): fix issues

* fix(ref: no-ref): fix comment
  • Loading branch information
andriikamaldinov1 authored Jul 3, 2024
1 parent ccf3963 commit 34fbb6c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 46 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'cypress';

export default defineConfig({
projectId: 'qhyo66',
component: {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "17.0.8",
"version": "17.0.9",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
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": "17.0.8",
"version": "17.0.9",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
16 changes: 3 additions & 13 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
26 changes: 8 additions & 18 deletions projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [];
Expand Down Expand Up @@ -116,10 +115,9 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida

protected _config = inject<IConfig>(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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -968,7 +959,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
}

if (typeof inputValue !== 'string') {
// eslint-disable-next-line no-param-reassign
inputValue = '';
}

Expand Down
12 changes: 5 additions & 7 deletions projects/ngx-mask-lib/src/lib/ngx-mask.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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;
Expand Down
75 changes: 75 additions & 0 deletions projects/ngx-mask-lib/src/test/separator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});
});

0 comments on commit 34fbb6c

Please sign in to comment.