Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Feb 27, 2024
1 parent 818d9b1 commit 5b5eed3
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 56 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
files: ['*.ts'],
rules: {
'@taiga-ui/experience/strict-tui-doc-example': 'off',
'@taiga-ui/experience/prefer-inject-decorator': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
},
},
Expand Down
19 changes: 7 additions & 12 deletions projects/angular/src/lib/maskito.directive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
Directive,
ElementRef,
Inject,
inject,
Input,
NgZone,
OnChanges,
OnDestroy,
Optional,
Self,
} from '@angular/core';
import {DefaultValueAccessor} from '@angular/forms';
import {
Expand All @@ -21,6 +19,8 @@ import {

@Directive({standalone: true, selector: '[maskito]'})
export class MaskitoDirective implements OnDestroy, OnChanges {
private readonly elementRef: HTMLElement = inject(ElementRef).nativeElement;
private readonly ngZone = inject(NgZone);
private maskedElement: Maskito | null = null;

@Input()
Expand All @@ -29,14 +29,9 @@ export class MaskitoDirective implements OnDestroy, OnChanges {
@Input()
maskitoElement: MaskitoElementPredicate = MASKITO_DEFAULT_ELEMENT_PREDICATE;

constructor(
@Inject(NgZone) private readonly ngZone: NgZone,
@Inject(ElementRef) private readonly elementRef: ElementRef<HTMLElement>,
@Inject(DefaultValueAccessor)
@Self()
@Optional()
accessor: DefaultValueAccessor | null,
) {
constructor() {
const accessor = inject(DefaultValueAccessor, {self: true, optional: true});

if (accessor) {
const original = accessor.writeValue.bind(accessor);

Expand All @@ -54,7 +49,7 @@ export class MaskitoDirective implements OnDestroy, OnChanges {
this.maskedElement?.destroy();

const predicate = this.maskitoElement;
const predicateResult = await predicate(this.elementRef.nativeElement);
const predicateResult = await predicate(this.elementRef);

if (this.maskitoElement !== predicate) {
// Ignore the result of the predicate if the
Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/app/app.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const APP_PROVIDERS: Provider[] = [

return `${link}/${context.package.toLowerCase()}/src/lib/masks/${(
context.header[0].toLowerCase() + context.header.slice(1)
).replace(/[A-Z]/g, m => `-${m.toLowerCase()}`)}`;
).replaceAll(/[A-Z]/g, m => `-${m.toLowerCase()}`)}`;
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DateRangeMaskDocComponent implements GeneratorOptions {
dateSeparator: string,
rangeSeparator: string,
): string {
const datePlaceholder = mode.replace(/\//g, dateSeparator);
const datePlaceholder = mode.replaceAll('/', dateSeparator);

return `${datePlaceholder}${rangeSeparator}${datePlaceholder}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class DateTimeMaskDocComponent implements GeneratorOptions {
): string {
const dateTimeSep = `,${CHAR_NO_BREAK_SPACE}`;

return `${dateMode.replace(/\//g, separator)}${dateTimeSep}${timeMode}`;
return `${dateMode.replaceAll('/', separator)}${dateTimeSep}${timeMode}`;
}

updateOptions(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChangeDetectionStrategy, Component, Inject} from '@angular/core';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {MaskitoDirective} from '@maskito/angular';
import {maskitoGetCountryFromNumber} from '@maskito/phone';
Expand Down Expand Up @@ -46,15 +46,15 @@ import mask from './mask';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PhoneMaskDocExample3 {
private readonly isApple = inject(TUI_IS_APPLE);

value = '';
readonly mask = mask;

get countryIsoCode(): string {
return maskitoGetCountryFromNumber(this.value, metadata) || '';
}

constructor(@Inject(TUI_IS_APPLE) private readonly isApple: boolean) {}

get pattern(): string {
return this.isApple ? '+[0-9-]{1,20}' : '';
}
Expand Down
6 changes: 3 additions & 3 deletions projects/demo/src/pages/phone/phone-doc.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChangeDetectionStrategy, Component, Inject} from '@angular/core';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {DocExamplePrimaryTab} from '@demo/constants';
import {MaskitoDirective} from '@maskito/angular';
Expand Down Expand Up @@ -37,6 +37,8 @@ type GeneratorOptions = Required<Parameters<typeof maskitoPhoneOptionsGenerator>
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PhoneDocComponent implements GeneratorOptions {
private readonly isApple = inject(TUI_IS_APPLE);

apiPageControl = new FormControl('');

readonly basic: TuiDocExample = {
Expand Down Expand Up @@ -84,8 +86,6 @@ export class PhoneDocComponent implements GeneratorOptions {

maskitoOptions = maskitoPhoneOptionsGenerator(this);

constructor(@Inject(TUI_IS_APPLE) private readonly isApple: boolean) {}

get pattern(): string {
return this.isApple ? '+[0-9-]{1,20}' : '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
// Paste "89123456789" => "+7 (912) 345-67-89"
function createCompletePhoneInsertionPreprocessor(): MaskitoPreprocessor {
const trimPrefix = (value: string): string => value.replace(/^(\+?7?\s?8?)\s?/, '');
const countDigits = (value: string): number => value.replace(/\D/g, '').length;
const countDigits = (value: string): number => value.replaceAll(/\D/g, '').length;

return ({elementState, data}) => {
const {value, selection} = elementState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {MaskitoOptions} from '@maskito/core';

export default {
mask: ({value}) => {
const digitsMask = Array.from(value.replace(/%/g, '')).map(() => /\d/);
const digitsMask = Array.from(value.replaceAll('%', '')).map(() => /\d/);

if (!digitsMask.length) {
return [/\d/];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {MaskitoOptions} from '@maskito/core';

export default {
mask: ({value}) => {
const digitsCount = value.replace(/\D/g, '').length;
const digitsCount = value.replaceAll(/\D/g, '').length;

return ['$', ...new Array(digitsCount || 1).fill(/\d/)];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {isPlatformBrowser} from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Inject,
inject,
OnInit,
PLATFORM_ID,
} from '@angular/core';
Expand All @@ -28,10 +28,8 @@ import {StackblitzService} from '../../stackblitz.service';
providers: [StackblitzService],
})
export class StackblitzStarterComponent implements OnInit {
constructor(
@Inject(PLATFORM_ID) private readonly platformId: Record<string, unknown>,
private readonly stackblitz: StackblitzService,
) {}
private readonly platformId = inject(PLATFORM_ID);
private readonly stackblitz = inject(StackblitzService);

async ngOnInit(): Promise<void> {
if (isPlatformBrowser(this.platformId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export function createRepeatedDecimalSeparatorPreprocessor({
!cleanValue.includes(decimalSeparator) ||
value.slice(from, to + 1).includes(decimalSeparator)
? data
: data.replace(new RegExp(escapeRegExp(decimalSeparator), 'gi'), ''),
: data.replaceAll(
new RegExp(escapeRegExp(decimalSeparator), 'gi'),
'',
),
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function generateMaskExpression({
? `[${CHAR_MINUS}${pseudoMinuses.map(x => `\\${x}`).join('')}]?`
: '';
const integerPart = thousandSeparator
? `[${digit}${escapeRegExp(thousandSeparator).replace(/\s/g, '\\s')}]*`
? `[${digit}${escapeRegExp(thousandSeparator).replaceAll(/\s/g, '\\s')}]*`
: `[${digit}]*`;
const decimalPart =
precision > 0
Expand Down
4 changes: 2 additions & 2 deletions projects/kit/src/lib/masks/number/utils/parse-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export function maskitoParseNumber(maskedNumber: string, decimalSeparator = '.')

const unmaskedNumber = maskedNumber
// drop all decimal separators not followed by a digit
.replace(new RegExp(`${escapedDecimalSeparator}(?!\\d)`, 'g'), '')
.replaceAll(new RegExp(`${escapedDecimalSeparator}(?!\\d)`, 'g'), '')
// drop all non-digit characters except decimal separator
.replace(new RegExp(`[^\\d${escapedDecimalSeparator}]`, 'g'), '')
.replaceAll(new RegExp(`[^\\d${escapedDecimalSeparator}]`, 'g'), '')
.replace(decimalSeparator, '.');

return unmaskedNumber
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/src/lib/processors/valid-date-preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createValidDatePreprocessor({
};
}

const newCharacters = data.replace(
const newCharacters = data.replaceAll(
new RegExp(
`[^\\d${escapeRegExp(dateSegmentsSeparator)}${rangeSeparator}]`,
'g',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createZeroPlaceholdersPreprocessor(): MaskitoPreprocessor {

const [from, to] = selection;

const zeroes = value.slice(from, to).replace(/\d/g, '0');
const zeroes = value.slice(from, to).replaceAll(/\d/g, '0');
const newValue = value.slice(0, from) + zeroes + value.slice(to);

if (actionType === 'validation' || (actionType === 'insert' && from === to)) {
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/src/lib/utils/count-digits.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function countDigits(str: string): number {
return str.replace(/\W/g, '').length;
return str.replaceAll(/\W/g, '').length;
}
4 changes: 2 additions & 2 deletions projects/kit/src/lib/utils/date/parse-date-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function parseDateString(
dateString: string,
fullMode: string,
): Partial<MaskitoDateSegments> {
const cleanMode = fullMode.replace(/[^dmy]/g, '');
const onlyDigitsDate = dateString.replace(/\D+/g, '');
const cleanMode = fullMode.replaceAll(/[^dmy]/g, '');
const onlyDigitsDate = dateString.replaceAll(/\D+/g, '');

const dateSegments: MaskitoDateSegments = {
day: onlyDigitsDate.slice(cleanMode.indexOf('d'), cleanMode.lastIndexOf('d') + 1),
Expand Down
18 changes: 9 additions & 9 deletions projects/kit/src/lib/utils/date/to-date-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export function toDateString(
const fullMode = dateMode + (timeMode ? DATE_TIME_SEPARATOR + timeMode : '');

return fullMode
.replace(/d+/g, day ?? '')
.replace(/m+/g, month ?? '')
.replace(/y+/g, safeYear ?? '')
.replace(/H+/g, hours ?? '')
.replace(/MSS/g, milliseconds ?? '')
.replace(/M+/g, minutes ?? '')
.replace(/S+/g, seconds ?? '')
.replace(/^\D+/g, '')
.replace(/\D+$/g, '');
.replaceAll(/d+/g, day ?? '')
.replaceAll(/m+/g, month ?? '')
.replaceAll(/y+/g, safeYear ?? '')
.replaceAll(/H+/g, hours ?? '')
.replaceAll('MSS', milliseconds ?? '')
.replaceAll(/M+/g, minutes ?? '')
.replaceAll(/S+/g, seconds ?? '')
.replaceAll(/^\D+/g, '')
.replaceAll(/\D+$/g, '');
}
2 changes: 1 addition & 1 deletion projects/kit/src/lib/utils/escape-reg-exp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
const reHasRegExpChar = new RegExp(reRegExpChar.source);

export function escapeRegExp(str: string): string {
return str && reHasRegExpChar.test(str) ? str.replace(reRegExpChar, '\\$&') : str;
return str && reHasRegExpChar.test(str) ? str.replaceAll(reRegExpChar, '\\$&') : str;
}
2 changes: 1 addition & 1 deletion projects/kit/src/lib/utils/time/parse-time-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {MaskitoTimeSegments} from '../../types';
* @param timeString can be with/without fixed characters
*/
export function parseTimeString(timeString: string): Partial<MaskitoTimeSegments> {
const onlyDigits = timeString.replace(/\D+/g, '');
const onlyDigits = timeString.replaceAll(/\D+/g, '');

const timeSegments = {
hours: onlyDigits.slice(0, 2),
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/src/lib/utils/to-half-width-colon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import {CHAR_COLON, CHAR_JP_COLON} from '../constants';
* @returns processed half width colon
*/
export function toHalfWidthColon(fullWidthColon: string): string {
return fullWidthColon.replace(new RegExp(CHAR_JP_COLON, 'g'), CHAR_COLON);
return fullWidthColon.replaceAll(new RegExp(CHAR_JP_COLON, 'g'), CHAR_COLON);
}
2 changes: 1 addition & 1 deletion projects/kit/src/lib/utils/to-half-width-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @returns processed half width number
*/
export function toHalfWidthNumber(fullWidthNumber: string): string {
return fullWidthNumber.replace(/[0-9]/g, s =>
return fullWidthNumber.replaceAll(/[0-9]/g, s =>
String.fromCharCode(s.charCodeAt(0) - 0xfee0),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function maskitoPhoneNonStrictOptionsGenerator({
...MASKITO_DEFAULT_OPTIONS,
mask: ({value}) => {
const newTemplate = getPhoneTemplate(formatter, value, separator);
const newPhoneLength = value.replace(/\D/g, '').length;
const newPhoneLength = value.replaceAll(/\D/g, '').length;

currentTemplate = selectTemplate({
currentTemplate,
Expand Down
2 changes: 1 addition & 1 deletion projects/phone/src/lib/masks/phone/phone-mask-strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function maskitoPhoneStrictOptionsGenerator({
...MASKITO_DEFAULT_OPTIONS,
mask: ({value}) => {
const newTemplate = getPhoneTemplate(formatter, value, separator);
const newPhoneLength = value.replace(/\D/g, '').length;
const newPhoneLength = value.replaceAll(/\D/g, '').length;

currentTemplate = selectTemplate({
currentTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function getPhoneTemplate(
value: string,
separator: string,
): string {
formatter.input(value.replace(/[^\d+]/g, ''));
formatter.input(value.replaceAll(/[^\d+]/g, ''));

const initialTemplate = formatter.getTemplate();
const split = initialTemplate.split(' ');
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-demo-routes-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const EXCEPTIONS = ['/', `${DemoPath.Angular}/Setup`, `${DemoPath.PhonePackage}/
const routes =
demoPathEnumContent
.match(/['"`](.*)['"`]/g)
?.map(route => route.replace(/['"`]/g, '')) || [];
?.map(route => route.replaceAll(/['"`]/g, '')) || [];

routes.forEach(route => {
if (route.startsWith('kit')) {
Expand Down

0 comments on commit 5b5eed3

Please sign in to comment.