Skip to content
Snippets Groups Projects
Commit 48ac359e authored by Rhys Arkins's avatar Rhys Arkins
Browse files

chore: refactor res purl

parent 64dfb59c
No related branches found
No related tags found
No related merge requests found
......@@ -10,50 +10,50 @@ function parse(input) {
if (!input.startsWith(scheme)) {
return null;
}
const res = {};
const purl = {};
let remaining = input.substring(scheme.length);
let parts = remaining.split('#');
if (parts.length > 1) {
[remaining, res.subpath] = parts;
[remaining, purl.subpath] = parts;
}
parts = remaining.split('?');
if (parts.length > 1) {
[remaining, res.qualifiers] = parts;
[remaining, purl.qualifiers] = parts;
}
parts = remaining.split('@');
if (parts.length > 1) {
[remaining, res.version] = parts;
[remaining, purl.version] = parts;
}
parts = remaining.split('/');
[res.datasource, ...remaining] = parts;
[purl.datasource, ...remaining] = parts;
if (remaining.length === 1) {
[res.name] = remaining;
res.lookupName = res.name;
[purl.name] = remaining;
purl.lookupName = purl.name;
} else {
res.name = remaining.pop();
res.namespace = remaining.join('/').replace('%40', '@');
res.lookupName = res.namespace + '/' + res.name;
purl.name = remaining.pop();
purl.namespace = remaining.join('/').replace('%40', '@');
purl.lookupName = purl.namespace + '/' + purl.name;
}
if (res.qualifiers) {
const allQualifiers = res.qualifiers.split('&');
res.qualifiers = {};
if (purl.qualifiers) {
const allQualifiers = purl.qualifiers.split('&');
purl.qualifiers = {};
allQualifiers.forEach(qualifier => {
const [key, val] = qualifier.split('=');
res.qualifiers[key] = val;
purl.qualifiers[key] = val;
});
if (res.qualifiers.repository_url) {
res.registryUrls = res.qualifiers.repository_url.split(',');
delete res.qualifiers.repository_url;
if (purl.qualifiers.repository_url) {
purl.registryUrls = purl.qualifiers.repository_url.split(',');
delete purl.qualifiers.repository_url;
}
} else {
res.qualifiers = {};
purl.qualifiers = {};
}
if (res.subpath) {
res.lookupType = res.subpath;
delete res.subpath;
if (purl.subpath) {
purl.lookupType = purl.subpath;
delete purl.subpath;
}
delete res.namespace;
delete res.name;
delete res.version; // we don't use it
return res;
delete purl.namespace;
delete purl.name;
delete purl.version; // we don't use it
return purl;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment