Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.formatPackageUrl = (registry, name) => {
if (name[0] === '@') {
// dont encodeURIComponent @ char, it will be 405
// https://registry.npmjs.com/%40rstacruz%2Ftap-spec/%3E%3D4.1.1
name = '@' + utility.encodeURIComponent(name.substring(1));
}
const parsed = url.parse(registry);
if (parsed.pathname.endsWith('/')) {
parsed.pathname += name;
} else {
parsed.pathname += `/${name}`;
}
return url.format(parsed);
};
url: function(subject, status, options) {
options = options || {};
let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
if (options.color) {
url += `/${utility.encodeURIComponent(options.color)}`;
}
if (options.icon) {
url += `?icon=${utility.encodeURIComponent(options.icon)}`;
}
return url;
},
},
url = url.replace(/:([a-zA-Z_]\w*)/g, function($0, key) {
if (utility.has(args, key)) {
const values = args[key];
replacedParams.push(key);
return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
}
return $0;
});
url = url.replace(/:([a-zA-Z_]\w*)/g, function($0, key) {
if (utility.has(args, key)) {
const values = args[key];
replacedParams.push(key);
return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
}
return $0;
});
for (const key in args) {
if (replacedParams.includes(key)) {
continue;
}
const values = args[key];
const encodedKey = utility.encodeURIComponent(key);
if (Array.isArray(values)) {
for (const val of values) {
queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
}
} else {
queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
}
}
}
if (queries.length > 0) {
const queryStr = queries.join('&');
if (!url.includes('?')) {
url = `${url}?${queryStr}`;
} else {
url = `${url}&${queryStr}`;
replacedParams.push(key);
return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
}
return $0;
});
for (const key in args) {
if (replacedParams.includes(key)) {
continue;
}
const values = args[key];
const encodedKey = utility.encodeURIComponent(key);
if (Array.isArray(values)) {
for (const val of values) {
queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
}
} else {
queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
}
}
}
if (queries.length > 0) {
const queryStr = queries.join('&');
if (!url.includes('?')) {
url = `${url}?${queryStr}`;
} else {
url = `${url}&${queryStr}`;
}
}
return $0;
});
for (const key in args) {
if (replacedParams.includes(key)) {
continue;
}
const values = args[key];
const encodedKey = utility.encodeURIComponent(key);
if (Array.isArray(values)) {
for (const val of values) {
queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
}
} else {
queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
}
}
}
if (queries.length > 0) {
const queryStr = queries.join('&');
if (!url.includes('?')) {
url = `${url}?${queryStr}`;
} else {
url = `${url}&${queryStr}`;
}
}
return url;
}
proto._escape = function _escape(name) {
return utility.encodeURIComponent(name).replace(/%2F/g, '/');
};
url: function(subject, status, options) {
options = options || {};
let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
if (options.color) {
url += `/${utility.encodeURIComponent(options.color)}`;
}
if (options.icon) {
url += `?icon=${utility.encodeURIComponent(options.icon)}`;
}
return url;
},
},