Skip to content

Commit

Permalink
feat(core): normalize non-lowercase type values
Browse files Browse the repository at this point in the history
See #225
  • Loading branch information
larsgw committed Apr 17, 2024
1 parent 29907aa commit 1ab0d2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/core/src/plugins/input/csl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DATE = 3
const TYPE = 4

/**
* Data from https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-data.json
* Possible values in the type field.
*
* - true if a valid type
* - string if another type should be used
Expand All @@ -16,6 +16,8 @@ const TYPE = 4
* @memberof module:@citation-js/core.plugins.input
*/
const entryTypes = {
// Valid types
// From https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-data.json
article: true,
'article-journal': true,
'article-magazine': true,
Expand Down Expand Up @@ -62,6 +64,7 @@ const entryTypes = {
treaty: true,
webpage: true,

// Invalid types, in use elsewhere
// From https://github.com/CrossRef/rest-api-doc/issues/187
'journal-article': 'article-journal',
'book-chapter': 'chapter',
Expand Down Expand Up @@ -321,11 +324,17 @@ function correctType (type, bestGuessConversions) {

if (entryTypes[type] === true) {
return type
} else if (bestGuessConversions && type in entryTypes) {
return entryTypes[type]
} else {
return undefined
}

if (bestGuessConversions) {
if (type in entryTypes) {
return entryTypes[type]
} else if (type.toLowerCase() !== type) {
return correctType(type.toLowerCase(), bestGuessConversions)
}
}

return undefined
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ describe('input', function () {
type: 'paper-conference'
}])
})
it('on non-lowercase types', function () {
expect(util.clean([{
type: 'Article'
}])).to.eql([{
type: 'article'
}])
})
it('on unparsed names', function () {
expect(util.clean([{
author: ['Lars G. Willighagen']
Expand Down

0 comments on commit 1ab0d2f

Please sign in to comment.