@scaleway/sdk-client
Version:
Scaleway SDK Client
31 lines (30 loc) • 864 B
JavaScript
const isAccessKeyRegex = /^SCW[A-Z0-9]{17}$/i;
const isRegionRegex = /^[a-z]{2}-[a-z]{3}$/i;
const isUUIDRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;
const isZoneRegex = /^[a-z]{2}-[a-z]{3}-[1-9]$/i;
const isUUID = (str) => isUUIDRegex.test(str);
const isAccessKey = (str) => isAccessKeyRegex.test(str);
const isSecretKey = (str) => isUUID(str);
const isOrganizationId = (str) => isUUID(str);
const isProjectId = (str) => isUUID(str);
const isRegion = (str) => isRegionRegex.test(str);
const isZone = (str) => isZoneRegex.test(str);
const isURL = (str) => {
let url;
try {
url = new URL(str);
} catch {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
};
export {
isAccessKey,
isOrganizationId,
isProjectId,
isRegion,
isSecretKey,
isURL,
isUUID,
isZone
};