Skip to content

Commit

Permalink
fix: no whitespaces in siret (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gavanier authored Dec 19, 2023
1 parent 146129c commit a56f138
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/models/siret/siret.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ describe('siret model', (): void => {
Siret('42');
}).toThrow(new SiretError('42'));
});

it('should throw SiretError if siret contains spaces', (): void => {
expect((): void => {
Siret('842 887 408 00');
}).toThrow(new SiretError('84288740800'));
});
});
5 changes: 4 additions & 1 deletion src/models/siret/siret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ const throwSiretError = (siretNumber: string): Siret => {
export const isSiret = (siret: string): siret is Siret => siret.length === 14;

/* eslint-disable-next-line @typescript-eslint/naming-convention */
export const Siret = (siret: string): Siret => (isSiret(siret) ? siret : throwSiretError(siret));
export const Siret = (siret: string): Siret => {
const siretWithoutSpaces: string = siret.replace(/\s/gu, '');
return isSiret(siretWithoutSpaces) ? siretWithoutSpaces : throwSiretError(siretWithoutSpaces);
};

0 comments on commit a56f138

Please sign in to comment.