File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -13,4 +13,10 @@ describe('siret model', (): void => {
13
13
Siret ( '42' ) ;
14
14
} ) . toThrow ( new SiretError ( '42' ) ) ;
15
15
} ) ;
16
+
17
+ it ( 'should throw SiretError if siret contains spaces' , ( ) : void => {
18
+ expect ( ( ) : void => {
19
+ Siret ( '842 887 408 00' ) ;
20
+ } ) . toThrow ( new SiretError ( '84288740800' ) ) ;
21
+ } ) ;
16
22
} ) ;
Original file line number Diff line number Diff line change @@ -10,4 +10,7 @@ const throwSiretError = (siretNumber: string): Siret => {
10
10
export const isSiret = ( siret : string ) : siret is Siret => siret . length === 14 ;
11
11
12
12
/* eslint-disable-next-line @typescript-eslint/naming-convention */
13
- export const Siret = ( siret : string ) : Siret => ( isSiret ( siret ) ? siret : throwSiretError ( siret ) ) ;
13
+ export const Siret = ( siret : string ) : Siret => {
14
+ const siretWithoutSpaces : string = siret . replace ( / \s / gu, '' ) ;
15
+ return isSiret ( siretWithoutSpaces ) ? siretWithoutSpaces : throwSiretError ( siretWithoutSpaces ) ;
16
+ } ;
You can’t perform that action at this time.
0 commit comments