Skip to content

Commit

Permalink
[Cite:output] Small fix and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgw committed Jul 6, 2017
1 parent 7ac66e1 commit 68e8e7e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/Cite/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var get = function get(options) {
} else if (type === 'html' && typeof document !== 'undefined' && document.createElement) {
var tmp = document.createElement('div');
tmp.innerHTML = result;
result = tmp.childNodes;
result = tmp.firstChild;
}
}

Expand Down
35 changes: 18 additions & 17 deletions lib/get/bibtex/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,60 @@ var getBibTeXJSON = function getBibTeXJSON(src) {
label: src.label || (0, _label2.default)(src),
type: (0, _type2.default)(src.type)
};

var props = {};

if (src.hasOwnProperty('author')) {
if (Array.isArray(src.author)) {
props.author = src.author.map(_name2.default).join(' and ');
}
if (src.hasOwnProperty('event')) {
if (src.event) {
props.organization = src.event;
}
if (src.hasOwnProperty('accessed')) {
if (Array.isArray(src.accessed)) {
props.note = '[Online; accesed ' + (0, _date2.default)(src.accessed) + ']';
}
if (src.hasOwnProperty('DOI')) {
if (src.DOI) {
props.doi = src.DOI;
}
if (src.hasOwnProperty('editor')) {
if (Array.isArray(src.editor)) {
props.editor = src.editor.map(_name2.default).join(' and ');
}
if (src.hasOwnProperty('ISBN')) {
if (src.ISBN) {
props.isbn = src.ISBN;
}
if (src.hasOwnProperty('ISSN')) {
if (src.ISSN) {
props.issn = src.ISSN;
}
if (src.hasOwnProperty('container-title')) {
if (src['container-title']) {
props.journal = src['container-title'];
}
if (src.hasOwnProperty('issue')) {
if (src.issue || src.issue === 0) {
props.issue = src.issue.toString();
}
if (src.hasOwnProperty('page')) {
if (typeof src.page === 'string') {
props.pages = src.page.replace('-', '--');
}
if (src.hasOwnProperty('publisher-place')) {
if (src['publisher-place']) {
props.address = src['publisher-place'];
}
if (src.hasOwnProperty('edition')) {
if (src.edition || src.edition === 0) {
props.edition = src.edition.toString();
}
if (src.hasOwnProperty('publisher')) {
if (src.publisher) {
props.publisher = src.publisher;
}
if (src.hasOwnProperty('title')) {
if (src.title) {
props.title = src['title'];
}
if (src.hasOwnProperty('url')) {
if (src.url) {
props.url = src.url;
}
if (src.hasOwnProperty('volume')) {
if (src.volume || src.volume === 0) {
props.volume = src.volume.toString();
}
if (Array.isArray(src.issued) && src.issued[0]['date-parts'].length === 3) {
props.year = src.issued[0]['date-parts'][0].toString();
} else if (src.hasOwnProperty('year')) {
} else if (src.year || src.year === 0) {
props.year = src.year;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cite/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const get = function (options) {
} else if (type === 'html' && typeof document !== 'undefined' && document.createElement) {
const tmp = document.createElement('div')
tmp.innerHTML = result
result = tmp.childNodes
result = tmp.firstChild
}
}

Expand Down
35 changes: 18 additions & 17 deletions src/get/bibtex/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ const getBibTeXJSON = function (src) {
label: src.label || getBibTeXLabel(src),
type: fetchBibTeXType(src.type)
}

const props = {}

if (src.hasOwnProperty('author')) { props.author = src.author.map(getName).join(' and ') }
if (src.hasOwnProperty('event')) { props.organization = src.event }
if (src.hasOwnProperty('accessed')) { props.note = '[Online; accesed ' + getDate(src.accessed) + ']' }
if (src.hasOwnProperty('DOI')) { props.doi = src.DOI }
if (src.hasOwnProperty('editor')) { props.editor = src.editor.map(getName).join(' and ') }
if (src.hasOwnProperty('ISBN')) { props.isbn = src.ISBN }
if (src.hasOwnProperty('ISSN')) { props.issn = src.ISSN }
if (src.hasOwnProperty('container-title')) { props.journal = src['container-title'] }
if (src.hasOwnProperty('issue')) { props.issue = src.issue.toString() }
if (src.hasOwnProperty('page')) { props.pages = src.page.replace('-', '--') }
if (src.hasOwnProperty('publisher-place')) { props.address = src['publisher-place'] }
if (src.hasOwnProperty('edition')) { props.edition = src.edition.toString() }
if (src.hasOwnProperty('publisher')) { props.publisher = src.publisher }
if (src.hasOwnProperty('title')) { props.title = src['title'] }
if (src.hasOwnProperty('url')) { props.url = src.url }
if (src.hasOwnProperty('volume')) { props.volume = src.volume.toString() }
if (Array.isArray(src.author)) { props.author = src.author.map(getName).join(' and ') }
if (src.event) { props.organization = src.event }
if (Array.isArray(src.accessed)) { props.note = '[Online; accesed ' + getDate(src.accessed) + ']' }
if (src.DOI) { props.doi = src.DOI }
if (Array.isArray(src.editor)) { props.editor = src.editor.map(getName).join(' and ') }
if (src.ISBN) { props.isbn = src.ISBN }
if (src.ISSN) { props.issn = src.ISSN }
if (src['container-title']) { props.journal = src['container-title'] }
if (src.issue || src.issue === 0) { props.issue = src.issue.toString() }
if (typeof src.page === 'string') { props.pages = src.page.replace('-', '--') }
if (src['publisher-place']) { props.address = src['publisher-place'] }
if (src.edition || src.edition === 0) { props.edition = src.edition.toString() }
if (src.publisher) { props.publisher = src.publisher }
if (src.title) { props.title = src['title'] }
if (src.url) { props.url = src.url }
if (src.volume || src.volume === 0) { props.volume = src.volume.toString() }
if (Array.isArray(src.issued) && src.issued[0]['date-parts'].length === 3) {
props.year = src.issued[0]['date-parts'][0].toString()
} else if (src.hasOwnProperty('year')) {
} else if (src.year || src.year === 0) {
props.year = src.year
}

Expand Down

0 comments on commit 68e8e7e

Please sign in to comment.