generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(kit): remove
DateRange
-specific logic from common date-utils
- Loading branch information
1 parent
54e7ec9
commit 97dc5a1
Showing
6 changed files
with
76 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1 @@ | ||
import {CHAR_EM_DASH, CHAR_EN_DASH, CHAR_HYPHEN, CHAR_MINUS} from './unicode-characters'; | ||
|
||
export const POSSIBLE_DATE_RANGE_SEPARATOR = [ | ||
CHAR_HYPHEN, | ||
CHAR_EN_DASH, | ||
CHAR_EM_DASH, | ||
CHAR_MINUS, | ||
]; | ||
|
||
export const POSSIBLE_DATE_TIME_SEPARATOR = [',', ' ']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
CHAR_EM_DASH, | ||
CHAR_EN_DASH, | ||
CHAR_HYPHEN, | ||
CHAR_JP_HYPHEN, | ||
CHAR_MINUS, | ||
} from '../../constants'; | ||
|
||
export const POSSIBLE_DATE_RANGE_SEPARATOR = [ | ||
CHAR_HYPHEN, | ||
CHAR_EN_DASH, | ||
CHAR_EM_DASH, | ||
CHAR_MINUS, | ||
CHAR_JP_HYPHEN, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
projects/kit/src/lib/masks/date-range/processors/preudo-range-separator-preprocessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {MaskitoPreprocessor} from '@maskito/core'; | ||
|
||
import {POSSIBLE_DATE_RANGE_SEPARATOR} from '../constants'; | ||
|
||
/** | ||
* It replaces pseudo range separators with valid one. | ||
* @example User types hyphen / en-dash / em-dash / minus => it is replaced with valid range separator. | ||
*/ | ||
export function createPseudoRangeSeparatorPreprocessor( | ||
rangeSeparator: string, | ||
): MaskitoPreprocessor { | ||
const pseudoSeparatorsRegExp = new RegExp( | ||
`[${POSSIBLE_DATE_RANGE_SEPARATOR.join('')}]`, | ||
'gi', | ||
); | ||
|
||
return ({elementState, data}) => { | ||
const {value, selection} = elementState; | ||
|
||
return { | ||
elementState: { | ||
selection, | ||
value: value.replace(pseudoSeparatorsRegExp, rangeSeparator), | ||
}, | ||
data: data.replace(pseudoSeparatorsRegExp, rangeSeparator), | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {MASKITO_DEFAULT_OPTIONS, MaskitoOptions, maskitoTransform} from '@maskito/core'; | ||
import {maskitoDateOptionsGenerator} from '@maskito/kit'; | ||
|
||
/** | ||
* If any of these tests fail, | ||
* it can mean that browser autofill or composition are not working properly | ||
* for Date mask | ||
*/ | ||
describe('Date (maskitoTransform)', () => { | ||
describe('[mode]="yyyy/mm/dd"', () => { | ||
let options: MaskitoOptions = MASKITO_DEFAULT_OPTIONS; | ||
|
||
beforeEach(() => { | ||
options = maskitoDateOptionsGenerator({ | ||
mode: 'yyyy/mm/dd', | ||
separator: '/', | ||
}); | ||
}); | ||
|
||
// TODO: fix this bug later | ||
xit('pads digit > 1 with zero for months (12345 => 1234/05)', () => { | ||
expect(maskitoTransform('12345', options)).toBe('1234/05'); | ||
}); | ||
|
||
// TODO: https://github.com/taiga-family/maskito/pull/907 | ||
xit('accepts full width characters', () => { | ||
expect(maskitoTransform('12345', options)).toBe('1234/05'); | ||
expect(maskitoTransform('12341226', options)).toBe('1234/12/26'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters