larsgw / citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.
https://citation.js.org/
MIT License
222 stars 30 forks source link

Don't use [].concat() #145

Closed larsgw closed 5 years ago

larsgw commented 6 years ago

Throughout the repository, [].concat(param) is used quite a lot for parameters or other options that can either be a certain type, or an array of that type. Array#concat() normalises this, but in an implicit way. Making this explicit, either with an if-statement or the ternary operator, depending on the context, will improve readability and as a bonus will make code coverage tools be able to work more precisely.

larsgw commented 6 years ago

On the other hand, there's verbosity.

let option = Array.isArray(options.thisOption) ? options.thisOption : [options.thisOption]

and

let option = options.thisOption
option = Array.isArray(option) ? option : [option]

are both pretty verbose, and duplicated code.