Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const parseWikidata = function (data) {
const list = Array.isArray(data) ? data : data.trim().split(/(?:[\s,]\s*)/g)
return [].concat(wdk.getEntities(list, ['en']))
}
const fetchWikidataLabel = function (q, lang) {
const ids = Array.isArray(q) ? q : typeof q === 'string' ? q.split('|') : ''
const url = wdk.getEntities(ids, [lang], 'labels')
const entities = JSON.parse(fetchFile(url)).entities || {}
return Object.keys(entities).map(entityKey => (entities[entityKey].labels[lang] || {}).value)
}
const fetchWikidataLabelAsync = async function (q, lang) {
const ids = Array.isArray(q) ? q : typeof q === 'string' ? q.split('|') : ''
const url = wdk.getEntities(ids, [lang], 'labels')
const entities = JSON.parse(await fetchFileAsync(url)).entities || {}
return Object.keys(entities).map(entityKey => (entities[entityKey].labels[lang] || {}).value)
}
)
let wikidataurl
let wikidataid
if (orgInstances.length > 0) {
wikidataurl = orgInstances[0].url
wikidataid = orgInstances[0].id
} else {
wikidataurl = response.search[0].url
wikidataid = response.search[0].id
}
const stack_exchange = await fetchSEtag(wikidataid)
const gitlab = await fetchGitLabOrg(wikidataid)
const entityAPIurl = wdk.getEntities({
ids: [wikidataid],
props: ['sitelinks'],
format: 'json',
})
const entitydata = await fetch(entityAPIurl)
let sitelinks = await entitydata.json()
sitelinks = sitelinks.entities[wikidataid].sitelinks
if (Object.keys(sitelinks).length) {
const wikipediaurls = Object.assign(
...Object.entries(sitelinks).map(([site, title]) => ({
[site.slice(0, -4)]: wdk.getSitelinkUrl(title),
}))
)
return {
stack_exchange,
gitlab,
async function fetchGitLabOrg(wikidata_id) {
const wikiAPIurl = wdk.getEntities(wikidata_id)
const page = await fetch(wikiAPIurl)
const { entities } = await page.json()
const entity = entities[wikidata_id]
if (!(WIKI_ACCOUNT_ON in entity.claims)) {
return
}
const gitlabClaim = entity.claims[WIKI_ACCOUNT_ON].sort(
(a, b) => WIKI_CLAIM_PRIORITY[a.rank] - WIKI_CLAIM_PRIORITY[b.rank]
).find(prop => prop.mainsnak.datavalue.value.id === WIKI_GITLAB)
if (!(gitlabClaim && WIKI_ACCOUNT_USERNAME in gitlabClaim.qualifiers)) {
return
}
_genRequestUrlById(ids) {
return wdk.getEntities({
ids: ids,
format: this.format,
});
}
}