deno.land / x / shacl_to_type@v0.0.9 / frontend / Context.ts

نووسراو ببینە
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
export class Context {
#jsonLdContext: { [key: string]: string } #jsonLdContextInverted: { [key: string]: string } = {}
constructor (jsonLdContext: { [key: string]: string }) { this.#jsonLdContext = jsonLdContext for (const [key, value] of Object.entries(jsonLdContext)) { if (key === '@vocab') continue this.#jsonLdContextInverted[value] = key } }
compactIri(iri: string, vocab = false) { let changed = true
if (this.#jsonLdContext['@vocab'] && vocab) { iri = iri.replace(this.#jsonLdContext['@vocab'], '') }
while (changed) { changed = false
for (const [prefixIri, alias] of Object.entries(this.#jsonLdContextInverted)) { if (iri.startsWith(prefixIri) && !prefixIri.includes('://')) { iri = iri.replace(prefixIri, alias) changed = true } }
for (const [prefixIri, alias] of Object.entries(this.#jsonLdContextInverted)) { if (iri.startsWith(prefixIri) && prefixIri.includes('://')) { iri = iri.replace(prefixIri, alias + ':') changed = true } } }
return iri.trim() }
getContextRaw () { return this.#jsonLdContext }}
shacl_to_type

Version Info

Tagged at
a year ago