Skip to content

Commit

Permalink
refactor!: simplify output fields where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Jan 25, 2024
1 parent 4475b65 commit 34ce5ef
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ function formatRecord ({ fields }, lineEnding) {
return record
}

function translateRecord (record) {
const fields = translator.convertToSource(record)

for (const field in fields) {
if (Array.isArray(fields[field]) && fields[field].length === 1) {
fields[field] = fields[field][0]
}
}

return { scheme: 'enw', fields }
}

export default {
enw (csl, options = {}) {
const { format = 'text', lineEnding = '\n' } = options
const records = csl.map(record => ({ scheme: 'enw', fields: translator.convertToSource(record) }))
const records = csl.map(translateRecord)

if (format === 'object') {
return records
Expand Down

0 comments on commit 34ce5ef

Please sign in to comment.