-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create oneTrustAssessmentToJson helper
- Loading branch information
1 parent
d11609e
commit 7647c02
Showing
4 changed files
with
50 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { OneTrustEnrichedAssessment } from '../codecs'; | ||
|
||
/** | ||
* Converts the assessment into a json entry. | ||
* | ||
* @param param - information about the assessment and amount of entries | ||
* @returns a stringified json entry ready to be appended to a file | ||
*/ | ||
export const oneTrustAssessmentToJson = ({ | ||
assessment, | ||
index, | ||
total, | ||
}: { | ||
/** The assessment to convert */ | ||
assessment: OneTrustEnrichedAssessment; | ||
/** The position of the assessment in the final Json object */ | ||
index: number; | ||
/** The total amount of the assessments in the final Json object */ | ||
total: number; | ||
}): string => { | ||
let jsonEntry = ''; | ||
// start with an opening bracket | ||
if (index === 0) { | ||
jsonEntry = '[\n'; | ||
} | ||
|
||
const stringifiedAssessment = JSON.stringify(assessment, null, 2); | ||
|
||
// Add comma for all items except the last one | ||
const comma = index < total - 1 ? ',' : ''; | ||
|
||
// write to file | ||
jsonEntry = jsonEntry + stringifiedAssessment + comma; | ||
|
||
// end with closing bracket | ||
if (index === total - 1) { | ||
jsonEntry += ']'; | ||
} | ||
|
||
return jsonEntry; | ||
}; |
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