Skip to content

Commit

Permalink
fix: clean presentation fields to have a better csv ouput format (#107)
Browse files Browse the repository at this point in the history
* fix: clean presentation fields to have a better csv ouput format

* fix: prettier

* fix: add more replacing to presentation fields
  • Loading branch information
abelkhay authored Jul 25, 2023
1 parent 54dc224 commit 953adeb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/transformer/fields/presentation/presentation.field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ describe('presentation fields', (): void => {
detail: 'Ceci est une description avec plus de détails'
});
});

it('should replace all newline in presentation fields', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
presentation_detail: {
colonne: 'presentation_detail'
},
presentation_resume: {
colonne: 'presentation_resume'
}
} as LieuxMediationNumeriqueMatching;

const source: DataSource = {
presentation_detail: 'Courte description,\nOu il y a une,\nou plusieurs newlines',
presentation_resume:
'Ceci est une description\n avec plus de détails,\n\n ou il peut y avoir une ou plusieurs newlines\n\n\n'
};

const presentation: Presentation = processPresentation(source, matching);

expect(presentation).toStrictEqual({
detail: 'Courte description,Ou il y a une,ou plusieurs newlines',
resume: 'Ceci est une description avec plus de détails, ou il peut y avoir une ou plusieurs newlines'
});
});
});
7 changes: 5 additions & 2 deletions src/transformer/fields/presentation/presentation.field.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { LieuxMediationNumeriqueMatching, DataSource } from '../../input';

const cleanPresentationFormat = (presentation: string): string =>
presentation.replace(/\n/gu, '').replace(/\\/gu, '').replace(/\r/gu, '');

const resumeIfAny = (source: DataSource, colonne?: string): { resume?: string } =>
colonne == null ? {} : { resume: source[colonne] ?? '' };
colonne == null ? {} : { resume: cleanPresentationFormat(source[colonne] ?? '') };

const detailIfAny = (source: DataSource, colonne?: string): { detail?: string } =>
colonne == null ? {} : { detail: source[colonne] ?? '' };
colonne == null ? {} : { detail: cleanPresentationFormat(source[colonne] ?? '') };

export const processPresentation = (
source: DataSource,
Expand Down

0 comments on commit 953adeb

Please sign in to comment.