@argos-ci/util
Version:
Set of utilities used across all Argos SDKs.
42 lines (38 loc) • 1.05 kB
JavaScript
// src/metadata.ts
function getMetadataPath(snapshotPath) {
return snapshotPath + ".argos.json";
}
// src/name.ts
function getScreenshotName(name, options = {}) {
return sanitizePath(
`${name}${options.viewportWidth ? ` vw-${options.viewportWidth}` : ""}`
);
}
function sanitizePath(name) {
return name.split("/").map((filename) => sanitizeFilename(filename)).join("/");
}
function filenameReservedRegex() {
return /[<>:"/\\|?*\u0000-\u001F]|[. ]$/g;
}
function windowsReservedNameRegex() {
return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
}
function sanitizeFilename(name) {
const replacement = "-";
const sanitized = name.replace(filenameReservedRegex(), replacement);
if (windowsReservedNameRegex().test(sanitized)) {
return `${sanitized}${replacement}`;
}
return sanitized;
}
// src/threshold.ts
function validateThreshold(threshold) {
if (threshold < 0 || threshold > 1) {
throw new Error("The threshold must be between 0 and 1.");
}
}
export {
getMetadataPath,
getScreenshotName,
validateThreshold
};