Skip to content

Commit

Permalink
fix(kit): fixes by review
Browse files Browse the repository at this point in the history
  • Loading branch information
namereva committed Aug 8, 2023
1 parent 44963d5 commit 6b03315
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const DEFAULT_PSEUDO_SEPARATORS = ['.', ',', 'б', 'ю'];
export const DEFAULT_DECIMAL_PSEUDO_SEPARATORS = ['.', ',', 'б', 'ю'];
4 changes: 2 additions & 2 deletions projects/kit/src/lib/masks/number/number-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
createThousandSeparatorPostprocessor,
createZeroPrecisionPreprocessor,
} from './processors';
import {generateMaskExpression, validatePseudoSeparators} from './utils';
import {generateMaskExpression, validateDecimalPseudoSeparators} from './utils';

export function maskitoNumberOptionsGenerator({
max = Number.MAX_SAFE_INTEGER,
Expand All @@ -53,7 +53,7 @@ export function maskitoNumberOptionsGenerator({
const pseudoMinuses = [CHAR_HYPHEN, CHAR_EN_DASH, CHAR_EM_DASH].filter(
char => char !== thousandSeparator && char !== decimalSeparator,
);
const validatedDecimalPseudoSeparators = validatePseudoSeparators({
const validatedDecimalPseudoSeparators = validateDecimalPseudoSeparators({
decimalSeparator,
thousandSeparator,
decimalPseudoSeparators,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Number (maskitoTransform)', () => {
});
});

describe('`precision` is `2` with custom thousandSeparator', () => {
describe('`thousandSeparator` is equal to the item from `decimalPseudoSeparators`', () => {
let options: MaskitoOptions = MASKITO_DEFAULT_OPTIONS;

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/src/lib/masks/number/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './generate-mask-expression';
export * from './parse-number';
export * from './stringify-number-without-exp';
export * from './validate-pseudo-separators';
export * from './validate-decimal-pseudo-separators';
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {DEFAULT_PSEUDO_SEPARATORS} from '../../../../constants';
import {validatePseudoSeparators} from '../validate-pseudo-separators';
import {DEFAULT_DECIMAL_PSEUDO_SEPARATORS} from '../../../../constants';
import {validateDecimalPseudoSeparators} from '../validate-decimal-pseudo-separators';

describe('validate decimal pseudo separators or return default', () => {
it('should return no empty array if decimalPseudoSeparators === `undefined`', () => {
expect(
validatePseudoSeparators({decimalSeparator: ',', thousandSeparator: ' '}),
).toEqual(DEFAULT_PSEUDO_SEPARATORS.filter(char => char !== ','));
validateDecimalPseudoSeparators({
decimalSeparator: ',',
thousandSeparator: ' ',
}),
).toEqual(DEFAULT_DECIMAL_PSEUDO_SEPARATORS.filter(char => char !== ','));
});

it('should exclude decimalSeparator and thousandSeparator from decimalPseudoSeparators', () => {
Expand All @@ -14,16 +17,12 @@ describe('validate decimal pseudo separators or return default', () => {
const thousandSeparator = 'b';

expect(
validatePseudoSeparators({
validateDecimalPseudoSeparators({
decimalSeparator,
thousandSeparator,
decimalPseudoSeparators,
}),
).toEqual(
decimalPseudoSeparators.filter(
char => char !== decimalSeparator && char !== thousandSeparator,
),
);
).toEqual([',', '.']);
});

it('should return original decimalPseudoSeparators', () => {
Expand All @@ -32,7 +31,7 @@ describe('validate decimal pseudo separators or return default', () => {
const thousandSeparator = ' ';

expect(
validatePseudoSeparators({
validateDecimalPseudoSeparators({
decimalSeparator,
thousandSeparator,
decimalPseudoSeparators,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {DEFAULT_DECIMAL_PSEUDO_SEPARATORS} from '../../../constants';

export function validateDecimalPseudoSeparators({
decimalSeparator,
thousandSeparator,
decimalPseudoSeparators = DEFAULT_DECIMAL_PSEUDO_SEPARATORS,
}: {
decimalSeparator: string;
thousandSeparator: string;
decimalPseudoSeparators?: string[];
}): string[] {
return decimalPseudoSeparators.filter(
char => char !== thousandSeparator && char !== decimalSeparator,
);
}

This file was deleted.

0 comments on commit 6b03315

Please sign in to comment.