-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathuser-utils.mjs
More file actions
24 lines (20 loc) · 915 Bytes
/
user-utils.mjs
File metadata and controls
24 lines (20 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import $rdf from 'rdflib'
const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#')
const VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#')
export async function getName (webId, fetchGraph) {
const graph = await fetchGraph(webId)
const nameNode = graph.any($rdf.sym(webId), VCARD('fn'))
return nameNode.value
}
export async function getWebId (accountDirectory, accountUrl, suffixMeta, fetchData) {
const metaFilePath = `${accountDirectory}/${suffixMeta}`
const metaFileUri = `${accountUrl}${suffixMeta}`
const metaData = await fetchData(metaFilePath)
const metaGraph = $rdf.graph()
$rdf.parse(metaData, metaGraph, metaFileUri, 'text/turtle')
const webIdNode = metaGraph.any(undefined, SOLID('account'), $rdf.sym(accountUrl))
return webIdNode.value
}
export function isValidUsername (username) {
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(username)
}