forked from logo94/getViafWorksById
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (25 loc) · 888 Bytes
/
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
/**
* Ottieni dettaglio elemento Wikidata
* @param {string} viafId - ID Authority Cluster VIAF "102333412"
* @param {string} [endpoint="viaf.org"] - opzionale
* @returns {Array<string>|[]} - Ritorna un array di titoli
*/
const getViafWorksById = async (viafId, endpoint = "viaf.org") => {
try {
const url = `https://${endpoint}/viaf/${viafId}`;
const headers = new Headers({
"Accept": "application/json"
});
const response = await fetch(url, { headers });
const json = await response.json();
const work_array = json['ns1:VIAFCluster']['ns1:titles']['ns1:work']
let response_array = []
work_array.forEach(work => {
response_array.push(work['ns1:title'])
})
return response_array;
} catch {
return [];
}
};
export { getViafWorksById };