Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Parse folios to name and number
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaasonen committed Jul 9, 2018
1 parent 3e1f77d commit 48efad7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/parseCsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ function parseJoins (joins) {
}

function parseFolio (folio) {
return folio ? folio.split(poundSeparator) : []
return folio
? folio.split(poundSeparator).map(entry => {
const match = /^(?:(?<name>.*) )(?<number>[^ ]+)$/.exec(entry)
return {
name: match.groups.name || '',
number: match.groups.number
}
})
: []
}

function parseScript (script) {
Expand Down
10 changes: 9 additions & 1 deletion spec/parseCsv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ describe('parseCsv', () => {
})

it('parses ₤ folio', () => {
expectCsv({folio: 'folio1 ₤ folio2'}).toParseTo({folio: ['folio1', 'folio2']})
expectCsv({folio: 'ABC folio1 ₤ folio2'}).toParseTo({folio: [
{
name: 'ABC',
number: 'folio1'
}, {
name: '',
number: 'folio2'
}
]})
})

it('parses record', () => {
Expand Down

0 comments on commit 48efad7

Please sign in to comment.