Skip to content

Commit

Permalink
feat(ref: no-ref): chane @input, @Ouput to signal
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikamaldinov1 committed Nov 28, 2024
1 parent 566b948 commit 3bd6957
Show file tree
Hide file tree
Showing 8 changed files with 1,017 additions and 830 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"cypress": "^13.16.0",
"highlight.js": "11.10.0",
"ngx-highlightjs": "12.0.0",
"ngxtension": "^4.1.0",
"rxjs": "7.8.1",
"semantic-release": "24.2.0",
"semantic-release-export-data": "^1.1.0",
Expand Down
392 changes: 187 additions & 205 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts

Large diffs are not rendered by default.

1,003 changes: 600 additions & 403 deletions projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions projects/ngx-mask-lib/src/lib/ngx-mask.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PipeTransform } from '@angular/core';
import { signal } from '@angular/core';
import { inject, Pipe } from '@angular/core';

import type { NgxMaskConfig } from './ngx-mask.config';
Expand All @@ -12,14 +13,12 @@ import { MaskExpression } from './ngx-mask-expression.enum';
standalone: true,
})
export class NgxMaskPipe implements PipeTransform {
private readonly defaultOptions = inject<NgxMaskConfig>(NGX_MASK_CONFIG);
private _maskExpressionArray = signal<string[]>([]);
private mask = signal<string>('');

private readonly defaultOptions = inject<NgxMaskConfig>(NGX_MASK_CONFIG);
private readonly _maskService = inject(NgxMaskService);

private _maskExpressionArray: string[] = [];

private mask = '';

public transform(
value: string | number,
mask: string,
Expand All @@ -32,7 +31,7 @@ export class NgxMaskPipe implements PipeTransform {
...this.defaultOptions,
...config,
patterns: {
...this._maskService.patterns,
...this._maskService.patterns(),
...patterns,
},
};
Expand All @@ -44,14 +43,14 @@ export class NgxMaskPipe implements PipeTransform {
if (mask.includes('||')) {
const maskParts = mask.split('||');
if (maskParts.length > 1) {
this._maskExpressionArray = maskParts.sort(
(a: string, b: string) => a.length - b.length
this._maskExpressionArray.set(
maskParts.sort((a: string, b: string) => a.length - b.length)
);
this._setMask(processedValue as string);
return this._maskService.applyMask(`${processedValue}`, this.mask);
return this._maskService.applyMask(`${processedValue}`, this.mask());
} else {
this._maskExpressionArray = [];
return this._maskService.applyMask(`${processedValue}`, this.mask);
this._maskExpressionArray.set([]);
return this._maskService.applyMask(`${processedValue}`, this.mask());
}
}

Expand All @@ -64,44 +63,44 @@ export class NgxMaskPipe implements PipeTransform {

if (mask.startsWith(MaskExpression.SEPARATOR)) {
if (config.decimalMarker) {
this._maskService.decimalMarker = config.decimalMarker;
this._maskService.decimalMarker.set(config.decimalMarker);
}
if (config.thousandSeparator) {
this._maskService.thousandSeparator = config.thousandSeparator;
this._maskService.thousandSeparator.set(config.thousandSeparator);
}
if (config.leadZero) {
this._maskService.leadZero = config.leadZero;
this._maskService.leadZero.set(config.leadZero);
}

processedValue = String(processedValue);
const localeDecimalMarker = this._maskService.currentLocaleDecimalMarker();

if (!Array.isArray(this._maskService.decimalMarker)) {
if (!Array.isArray(this._maskService.decimalMarker())) {
processedValue =
this._maskService.decimalMarker !== localeDecimalMarker
this._maskService.decimalMarker() !== localeDecimalMarker
? (processedValue as string).replace(
localeDecimalMarker,
this._maskService.decimalMarker
this._maskService.decimalMarker() as string
)
: processedValue;
}

if (
this._maskService.leadZero &&
this._maskService.leadZero() &&
processedValue &&
this._maskService.dropSpecialCharacters !== false
this._maskService.dropSpecialCharacters() !== false
) {
processedValue = this._maskService._checkPrecision(mask, processedValue as string);
}

if (this._maskService.decimalMarker === MaskExpression.COMMA) {
if (this._maskService.decimalMarker() === MaskExpression.COMMA) {
processedValue = (processedValue as string).replace(
MaskExpression.DOT,
MaskExpression.COMMA
);
}

this._maskService.isNumberValue = true;
this._maskService.isNumberValue.set(true);
}

if (processedValue === null || typeof processedValue === 'undefined') {
Expand All @@ -113,18 +112,18 @@ export class NgxMaskPipe implements PipeTransform {

private _setMask(value: string) {
if (this._maskExpressionArray.length > 0) {
this._maskExpressionArray.some((mask): boolean | void => {
this._maskExpressionArray().some((mask): boolean | void => {
const test =
this._maskService.removeMask(value)?.length <=
this._maskService.removeMask(mask)?.length;
if (value && test) {
this.mask = mask;
this.mask.set(mask);
return test;
} else {
const expression =
this._maskExpressionArray[this._maskExpressionArray.length - 1] ??
this._maskExpressionArray()[this._maskExpressionArray().length - 1] ??
MaskExpression.EMPTY_STRING;
this.mask = expression;
this.mask.set(expression);
}
});
}
Expand Down
Loading

0 comments on commit 3bd6957

Please sign in to comment.