Skip to content

Commit

Permalink
Merge pull request #2 from kolplattformen/feat/comment
Browse files Browse the repository at this point in the history
feat: 🎸 It now handles comments
  • Loading branch information
JohanObrink authored Apr 12, 2021
2 parents 8d3614e + 065e0e9 commit bf299ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,18 @@ describe('parse', () => {
name: 'Övriga språk',
})
})
it('handles comments', () => {
expect(parse('NO a)')).toEqual({
code: 'NO',
category: '',
name: 'Naturorienterande ämnen',
comment: 'a)',
})
expect(parse('MTID Arbetslagsråd 7C')).toEqual({
code: 'MTID',
category: 'Okänd',
name: 'MTID',
comment: 'Arbetslagsråd 7C',
})
})
})
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,18 @@ const parseNativeLanguage: Parser = (code) => {
}

const parse = (code: string): Subject => {
return (
parseSubject(code) ||
const [subjectCode, ...rest] = code.split(' ')
const result: Subject = parseSubject(subjectCode) ||
parseTrainingSubject(code) ||
parseLanguage(code) ||
parseAltLanguage(code) ||
parseNativeLanguage(code) || { code, category: 'Okänd', name: code }
)
parseNativeLanguage(code) || {
code: subjectCode,
category: 'Okänd',
name: subjectCode,
}
if (rest.length) result.comment = rest.join(' ').trim()
return result
}

export default parse

0 comments on commit bf299ea

Please sign in to comment.