Skip to content

Commit a56f138

Browse files
fix: no whitespaces in siret (#46)
1 parent 146129c commit a56f138

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/models/siret/siret.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ describe('siret model', (): void => {
1313
Siret('42');
1414
}).toThrow(new SiretError('42'));
1515
});
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+
});
1622
});

src/models/siret/siret.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ const throwSiretError = (siretNumber: string): Siret => {
1010
export const isSiret = (siret: string): siret is Siret => siret.length === 14;
1111

1212
/* 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+
};

0 commit comments

Comments
 (0)