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.
fix: add colon convert preprocessor, add tests for it
- Loading branch information
1 parent
8a91586
commit 7ef851b
Showing
11 changed files
with
59 additions
and
1 deletion.
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
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
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
20 changes: 20 additions & 0 deletions
20
projects/kit/src/lib/processors/colon-convert-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,20 @@ | ||
import {MaskitoPreprocessor} from '@maskito/core'; | ||
|
||
import {toHalfWidthColon} from '../utils'; | ||
|
||
/** | ||
* Convert full width colon (:) to half width one (:) | ||
*/ | ||
export function createColonConvertPreprocessor(): MaskitoPreprocessor { | ||
return ({elementState, data}) => { | ||
const {value, selection} = elementState; | ||
|
||
return { | ||
elementState: { | ||
selection, | ||
value: toHalfWidthColon(value), | ||
}, | ||
data: toHalfWidthColon(data), | ||
}; | ||
}; | ||
} |
2 changes: 1 addition & 1 deletion
2
projects/kit/src/lib/processors/fullwidth-to-halfwidth-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
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
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
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,7 @@ | ||
import {toHalfWidthColon} from '../to-half-width-colon'; | ||
|
||
describe('`toHalfWidthColon` utility converts full width colon to half width colon', () => { | ||
it(': => :', () => { | ||
expect(toHalfWidthColon(':')).toBe(':'); | ||
}); | ||
}); |
File renamed without changes.
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,10 @@ | ||
import {CHAR_COLON, CHAR_JP_COLON} from '../constants'; | ||
|
||
/** | ||
* Replace fullwidth colon with half width colon | ||
* @param fullWidthColon full width colon | ||
* @returns processed half width colon | ||
*/ | ||
export function toHalfWidthColon(fullWidthColon: string): string { | ||
return fullWidthColon.replace(new RegExp(CHAR_JP_COLON, 'g'), CHAR_COLON); | ||
} |
File renamed without changes.