-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const through = require('through2')
const isRetraction = data => {
if (data['update-to'][0].type.toLowerCase().trim() == 'retraction') {
console.log('properly reported retracion')
return true
} else if (/^retract(ed|ion)/.test(data.title[0].toLowerCase().trim())) {
console.log('improperly reported retraction')
return true
}
return false
}
const convert = data => {
if (!data['update-to']) throw new Error('CrossRef entry is not an update')
return {
retracted: isRetraction(data),
timestamp: data['update-to'][0].updated.timestamp,
updates: [
{
timestamp: data.indexed.timestamp,
identifier: { doi: data.DOI },
type: data['update-to'][0].type
}
],
identifier: { doi: data['update-to'][0].DOI },
journal: data['container-title'][0],
publisher: data.publisher,
title: data.title[0]
}
}
const crossref2retraction = (data, enc, done) => {
let converted
try {
converted = convert(data)
} catch (e) {
return done(e)
}
return done(null, converted)
}
module.exports = {
convert: convert,
stream: through.ctor({ objectMode: true }, crossref2retraction)
}