Skip to content

Commit

Permalink
fix(ref: #188): rename types, remove zone js
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikamaldinov1 committed Oct 30, 2024
1 parent c91177f commit da6053a
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 127 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# 18.0.1(2024-10-29)

### Enhancement
### Breaking Changes

- add tailwind
- change interface to type, remove prefix "I"
- update dependencies
- add ESLint strict rules
- rename "IConfig" to "NgxMaskConfig"
- rename "optionsConfig" to "NgxMaskOptions"
- change interface to type

### Fix

Expand Down
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ bootstrapApplication(AppComponent, {
### Passing your own mask config options

```typescript
import { Config } from 'ngx-mask'
import { NgxMaskConfig } from 'ngx-mask'

const maskConfig: Partial<Config> = {
const maskConfig: Partial<NgxMaskConfig> = {
validation: false,
};

Expand All @@ -90,7 +90,7 @@ bootstrapApplication(AppComponent, {
### Using a function to configure:

```typescript
const maskConfigFunction: () => Partial<Config> = () => {
const maskConfigFunction: () => Partial<NgxMaskConfig> = () => {
return {
validation: false,
};
Expand Down Expand Up @@ -144,9 +144,9 @@ Import **ngx-mask** module in Angular app.
### With default mask config options

```typescript
import { NgxMaskModule, Config } from 'ngx-mask'
import { NgxMaskModule, NgxMaskConfig } from 'ngx-mask'

export const options: Partial<null|Config> | (() => Partial<Config>) = null;
export const options: Partial<null | NgxMaskConfig> | (() => Partial<NgxMaskConfig>) = null;

@NgModule({
imports: [
Expand All @@ -158,9 +158,9 @@ export const options: Partial<null|Config> | (() => Partial<Config>) = null;
### Passing in your own mask config options

```typescript
import { NgxMaskModule, Config } from 'ngx-mask'
import { NgxMaskModule, NgxMaskConfig } from 'ngx-mask'

const maskConfig: Partial<Config> = {
const maskConfig: Partial<NgxMaskConfig> = {
validation: false,
};

Expand All @@ -174,7 +174,7 @@ const maskConfig: Partial<Config> = {
Or using a function to get the config:

```typescript
const maskConfigFunction: () => Partial<Config> = () => {
const maskConfigFunction: () => Partial<NgxMaskConfig> = () => {
return {
validation: false,
};
Expand All @@ -193,12 +193,6 @@ Then, just define masks in inputs.

Text [documentation](https://github.com/JsDaddy/ngx-mask/blob/develop/USAGE.md)

## Setup hooks

```bash
$ npm run init:hooks
```

## Contributing

We would love some contributions! Check out this [document](https://github.com/JsDaddy/ngx-mask/blob/develop/CONTRIBUTING.md) to get started.
3 changes: 1 addition & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"extractLicenses": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true,
"polyfills": ["zone.js"]
"namedChunks": true
},
"configurations": {
"production": {
Expand Down
54 changes: 28 additions & 26 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
import { inject, Injectable } from '@angular/core';
import type { Config } from './ngx-mask.config';
import type { NgxMaskConfig } from './ngx-mask.config';
import { NGX_MASK_CONFIG } from './ngx-mask.config';
import { MaskExpression } from './ngx-mask-expression.enum';

@Injectable()
export class NgxMaskApplierService {
protected _config = inject<Config>(NGX_MASK_CONFIG);
protected _config = inject<NgxMaskConfig>(NGX_MASK_CONFIG);

public dropSpecialCharacters: Config['dropSpecialCharacters'] =
public dropSpecialCharacters: NgxMaskConfig['dropSpecialCharacters'] =
this._config.dropSpecialCharacters;

public hiddenInput: Config['hiddenInput'] = this._config.hiddenInput;
public hiddenInput: NgxMaskConfig['hiddenInput'] = this._config.hiddenInput;

public showTemplate!: Config['showTemplate'];
public showTemplate!: NgxMaskConfig['showTemplate'];

public clearIfNotMatch: Config['clearIfNotMatch'] = this._config.clearIfNotMatch;
public clearIfNotMatch: NgxMaskConfig['clearIfNotMatch'] = this._config.clearIfNotMatch;

public specialCharacters: Config['specialCharacters'] = this._config.specialCharacters;
public specialCharacters: NgxMaskConfig['specialCharacters'] = this._config.specialCharacters;

public patterns: Config['patterns'] = this._config.patterns;
public patterns: NgxMaskConfig['patterns'] = this._config.patterns;

public prefix: Config['prefix'] = this._config.prefix;
public prefix: NgxMaskConfig['prefix'] = this._config.prefix;

public suffix: Config['suffix'] = this._config.suffix;
public suffix: NgxMaskConfig['suffix'] = this._config.suffix;

public thousandSeparator: Config['thousandSeparator'] = this._config.thousandSeparator;
public thousandSeparator: NgxMaskConfig['thousandSeparator'] = this._config.thousandSeparator;

public decimalMarker: Config['decimalMarker'] = this._config.decimalMarker;
public decimalMarker: NgxMaskConfig['decimalMarker'] = this._config.decimalMarker;

public customPattern!: Config['patterns'];
public customPattern!: NgxMaskConfig['patterns'];

public showMaskTyped: Config['showMaskTyped'] = this._config.showMaskTyped;
public showMaskTyped: NgxMaskConfig['showMaskTyped'] = this._config.showMaskTyped;

public placeHolderCharacter: Config['placeHolderCharacter'] = this._config.placeHolderCharacter;
public placeHolderCharacter: NgxMaskConfig['placeHolderCharacter'] =
this._config.placeHolderCharacter;

public validation: Config['validation'] = this._config.validation;
public validation: NgxMaskConfig['validation'] = this._config.validation;

public separatorLimit: Config['separatorLimit'] = this._config.separatorLimit;
public separatorLimit: NgxMaskConfig['separatorLimit'] = this._config.separatorLimit;

public allowNegativeNumbers: Config['allowNegativeNumbers'] = this._config.allowNegativeNumbers;
public allowNegativeNumbers: NgxMaskConfig['allowNegativeNumbers'] =
this._config.allowNegativeNumbers;

public leadZeroDateTime: Config['leadZeroDateTime'] = this._config.leadZeroDateTime;
public leadZeroDateTime: NgxMaskConfig['leadZeroDateTime'] = this._config.leadZeroDateTime;

public leadZero: Config['leadZero'] = this._config.leadZero;
public leadZero: NgxMaskConfig['leadZero'] = this._config.leadZero;

public apm: Config['apm'] = this._config.apm;
public apm: NgxMaskConfig['apm'] = this._config.apm;

public inputTransformFn: Config['inputTransformFn'] = this._config.inputTransformFn;
public inputTransformFn: NgxMaskConfig['inputTransformFn'] = this._config.inputTransformFn;

public outputTransformFn: Config['outputTransformFn'] = this._config.outputTransformFn;
public outputTransformFn: NgxMaskConfig['outputTransformFn'] = this._config.outputTransformFn;

public keepCharacterPositions: Config['keepCharacterPositions'] =
public keepCharacterPositions: NgxMaskConfig['keepCharacterPositions'] =
this._config.keepCharacterPositions;

private _shift = new Set<number>();
Expand All @@ -73,7 +75,7 @@ export class NgxMaskApplierService {

public applyMaskWithPattern(
inputValue: string,
maskAndPattern: [string, Config['patterns']]
maskAndPattern: [string, NgxMaskConfig['patterns']]
): string {
const [mask, customPattern] = maskAndPattern;
this.customPattern = customPattern;
Expand Down Expand Up @@ -895,7 +897,7 @@ export class NgxMaskApplierService {
private checkInputPrecision = (
inputValue: string,
precision: number,
decimalMarker: Config['decimalMarker']
decimalMarker: NgxMaskConfig['decimalMarker']
): string => {
let processedInputValue = inputValue;
let processedDecimalMarker = decimalMarker;
Expand Down
13 changes: 6 additions & 7 deletions projects/ngx-mask-lib/src/lib/ngx-mask.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type InputTransformFn = (value: unknown) => string | number;

export type OutputTransformFn = (value: string | number | undefined | null) => unknown;

export type Config = {
export type NgxMaskConfig = {
suffix: string;
prefix: string;
thousandSeparator: string;
Expand Down Expand Up @@ -39,12 +39,12 @@ export type Config = {
>;
};

export type optionsConfig = Partial<Config>;
export const NGX_MASK_CONFIG = new InjectionToken<Config>('ngx-mask config');
export const NEW_CONFIG = new InjectionToken<Config>('new ngx-mask config');
export const INITIAL_CONFIG = new InjectionToken<Config>('initial ngx-mask config');
export type NgxMaskOptions = Partial<NgxMaskConfig>;
export const NGX_MASK_CONFIG = new InjectionToken<NgxMaskConfig>('ngx-mask config');
export const NEW_CONFIG = new InjectionToken<NgxMaskConfig>('new ngx-mask config');
export const INITIAL_CONFIG = new InjectionToken<NgxMaskConfig>('initial ngx-mask config');

export const initialConfig: Config = {
export const initialConfig: NgxMaskConfig = {
suffix: '',
prefix: '',
thousandSeparator: ' ',
Expand All @@ -59,7 +59,6 @@ export const initialConfig: Config = {
separatorLimit: '',
allowNegativeNumbers: false,
validation: true,

specialCharacters: ['-', '/', '(', ')', '.', ':', ' ', '+', ',', '@', '[', ']', '"', "'"],
leadZeroDateTime: false,
apm: false,
Expand Down
52 changes: 26 additions & 26 deletions projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';

import type { CustomKeyboardEvent } from './custom-keyboard-event';
import type { Config } from './ngx-mask.config';
import type { NgxMaskConfig } from './ngx-mask.config';
import { NGX_MASK_CONFIG, timeMasks, withoutValidation } from './ngx-mask.config';
import { NgxMaskService } from './ngx-mask.service';
import { MaskExpression } from './ngx-mask-expression.enum';
Expand All @@ -36,53 +36,53 @@ import { MaskExpression } from './ngx-mask-expression.enum';
export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Validator {
@Input('mask') public maskExpression: string | undefined | null = '';

@Input() public specialCharacters: Config['specialCharacters'] = [];
@Input() public specialCharacters: NgxMaskConfig['specialCharacters'] = [];

@Input() public patterns: Config['patterns'] = {};
@Input() public patterns: NgxMaskConfig['patterns'] = {};

@Input() public prefix: Config['prefix'] = '';
@Input() public prefix: NgxMaskConfig['prefix'] = '';

@Input() public suffix: Config['suffix'] = '';
@Input() public suffix: NgxMaskConfig['suffix'] = '';

@Input() public thousandSeparator: Config['thousandSeparator'] = ' ';
@Input() public thousandSeparator: NgxMaskConfig['thousandSeparator'] = ' ';

@Input() public decimalMarker: Config['decimalMarker'] = '.';
@Input() public decimalMarker: NgxMaskConfig['decimalMarker'] = '.';

@Input() public dropSpecialCharacters: Config['dropSpecialCharacters'] | null = null;
@Input() public dropSpecialCharacters: NgxMaskConfig['dropSpecialCharacters'] | null = null;

@Input() public hiddenInput: Config['hiddenInput'] | null = null;
@Input() public hiddenInput: NgxMaskConfig['hiddenInput'] | null = null;

@Input() public showMaskTyped: Config['showMaskTyped'] | null = null;
@Input() public showMaskTyped: NgxMaskConfig['showMaskTyped'] | null = null;

@Input() public placeHolderCharacter: Config['placeHolderCharacter'] | null = null;
@Input() public placeHolderCharacter: NgxMaskConfig['placeHolderCharacter'] | null = null;

@Input() public shownMaskExpression: Config['shownMaskExpression'] | null = null;
@Input() public shownMaskExpression: NgxMaskConfig['shownMaskExpression'] | null = null;

@Input() public showTemplate: Config['showTemplate'] | null = null;
@Input() public showTemplate: NgxMaskConfig['showTemplate'] | null = null;

@Input() public clearIfNotMatch: Config['clearIfNotMatch'] | null = null;
@Input() public clearIfNotMatch: NgxMaskConfig['clearIfNotMatch'] | null = null;

@Input() public validation: Config['validation'] | null = null;
@Input() public validation: NgxMaskConfig['validation'] | null = null;

@Input() public separatorLimit: Config['separatorLimit'] | null = null;
@Input() public separatorLimit: NgxMaskConfig['separatorLimit'] | null = null;

@Input() public allowNegativeNumbers: Config['allowNegativeNumbers'] | null = null;
@Input() public allowNegativeNumbers: NgxMaskConfig['allowNegativeNumbers'] | null = null;

@Input() public leadZeroDateTime: Config['leadZeroDateTime'] | null = null;
@Input() public leadZeroDateTime: NgxMaskConfig['leadZeroDateTime'] | null = null;

@Input() public leadZero: Config['leadZero'] | null = null;
@Input() public leadZero: NgxMaskConfig['leadZero'] | null = null;

@Input() public triggerOnMaskChange: Config['triggerOnMaskChange'] | null = null;
@Input() public triggerOnMaskChange: NgxMaskConfig['triggerOnMaskChange'] | null = null;

@Input() public apm: Config['apm'] | null = null;
@Input() public apm: NgxMaskConfig['apm'] | null = null;

@Input() public inputTransformFn: Config['inputTransformFn'] | null = null;
@Input() public inputTransformFn: NgxMaskConfig['inputTransformFn'] | null = null;

@Input() public outputTransformFn: Config['outputTransformFn'] | null = null;
@Input() public outputTransformFn: NgxMaskConfig['outputTransformFn'] | null = null;

@Input() public keepCharacterPositions: Config['keepCharacterPositions'] | null = null;
@Input() public keepCharacterPositions: NgxMaskConfig['keepCharacterPositions'] | null = null;

@Output() public maskFilled: Config['maskFilled'] = new EventEmitter<void>();
@Output() public maskFilled: NgxMaskConfig['maskFilled'] = new EventEmitter<void>();

private _maskValue = '';

Expand All @@ -107,7 +107,7 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida

public _maskService = inject(NgxMaskService, { self: true });

protected _config = inject<Config>(NGX_MASK_CONFIG);
protected _config = inject<NgxMaskConfig>(NGX_MASK_CONFIG);

// eslint-disable-next-line @typescript-eslint/no-empty-function
public onChange = (_: any) => {};
Expand Down
6 changes: 3 additions & 3 deletions projects/ngx-mask-lib/src/lib/ngx-mask.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PipeTransform } from '@angular/core';
import { inject, Pipe } from '@angular/core';

import type { Config } from './ngx-mask.config';
import type { NgxMaskConfig } from './ngx-mask.config';
import { NGX_MASK_CONFIG } from './ngx-mask.config';
import { NgxMaskService } from './ngx-mask.service';
import { MaskExpression } from './ngx-mask-expression.enum';
Expand All @@ -12,7 +12,7 @@ import { MaskExpression } from './ngx-mask-expression.enum';
standalone: true,
})
export class NgxMaskPipe implements PipeTransform {
private readonly defaultOptions = inject<Config>(NGX_MASK_CONFIG);
private readonly defaultOptions = inject<NgxMaskConfig>(NGX_MASK_CONFIG);

private readonly _maskService = inject(NgxMaskService);

Expand All @@ -23,7 +23,7 @@ export class NgxMaskPipe implements PipeTransform {
public transform(
value: string | number,
mask: string,
{ patterns, ...config }: Partial<Config> = {} as Partial<Config>
{ patterns, ...config }: Partial<NgxMaskConfig> = {} as Partial<NgxMaskConfig>
): string {
let processedValue: string | number = value;

Expand Down
12 changes: 6 additions & 6 deletions projects/ngx-mask-lib/src/lib/ngx-mask.providers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { EnvironmentProviders, Provider } from '@angular/core';
import { inject, makeEnvironmentProviders } from '@angular/core';

import type { optionsConfig } from './ngx-mask.config';
import type { NgxMaskOptions } from './ngx-mask.config';
import { NGX_MASK_CONFIG, INITIAL_CONFIG, initialConfig, NEW_CONFIG } from './ngx-mask.config';
import { NgxMaskService } from './ngx-mask.service';

/**
* @internal
*/
function _configFactory(): optionsConfig {
const initConfig = inject<optionsConfig>(INITIAL_CONFIG);
const configValue = inject<optionsConfig | (() => optionsConfig)>(NEW_CONFIG);
function _configFactory(): NgxMaskOptions {
const initConfig = inject<NgxMaskOptions>(INITIAL_CONFIG);
const configValue = inject<NgxMaskOptions | (() => NgxMaskOptions)>(NEW_CONFIG);

return configValue instanceof Function
? { ...initConfig, ...configValue() }
: { ...initConfig, ...configValue };
}

export function provideNgxMask(configValue?: optionsConfig | (() => optionsConfig)): Provider[] {
export function provideNgxMask(configValue?: NgxMaskOptions | (() => NgxMaskOptions)): Provider[] {
return [
{
provide: NEW_CONFIG,
Expand All @@ -36,7 +36,7 @@ export function provideNgxMask(configValue?: optionsConfig | (() => optionsConfi
}

export function provideEnvironmentNgxMask(
configValue?: optionsConfig | (() => optionsConfig)
configValue?: NgxMaskOptions | (() => NgxMaskOptions)
): EnvironmentProviders {
return makeEnvironmentProviders(provideNgxMask(configValue));
}
Loading

0 comments on commit da6053a

Please sign in to comment.