10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-09 07:33:52 +01:00
QUESTDB_website/static/js/DOICache.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

class DOICache{
constructor(){
this._doimap=new Map()
this._Cite=require("citation-js")
}
clear(){
this._doimap.clear()
}
2020-09-09 14:39:46 +02:00
delete(article){
return this._doimap.delete(doi)
}
forEach(callbackfn, thisArg=None){
return this._doimap.forEach(callbackfn,thisArg)
}
get(doi){
return this._doimap.get(doi)
}
has(doi){
return this._doimap.has(doi)
}
async add(doi){
if(!this.has(doi)){
const publi=await this._Cite.async(doi)
this._doimap.set(doi,publi)
}
}
2020-09-09 14:39:46 +02:00
async tryAdd(doi){
const publi = await this._Cite.async(doi)
if (publi.data.length === 0) {
return false
}
this._doimap.set(doi,publi)
return true
}
async addRange(dois){
const set=new Set(dois)
for(const doi of set){
await this.add(doi)
}
}
2020-09-09 14:39:46 +02:00
async tryAddRange(dois){
const set = new Set(dois)
return Promise.all(Array.from(set).map(doi=>this.tryAdd(doi)))
}
get size(){
return this._doimap.size()
}
2019-12-19 14:45:31 +01:00
keys() { return this._doimap.keys()}
values() { return this._doimap.values()}
entries() { return this._doimap.entries()}
[Symbol.iterator]() { return this.values()}
}