UNPKG

@jsvfs/adapter-azure-blob

Version:
47 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = exports.isContainerName = void 0; /** Function for iterating over a string and ensuring it is a valid container name. * See [Microsofts documentation](https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names) */ function isContainerName(str) { const validChars = '-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; const minLength = 3; const maxLength = 63; const invalidStartChar = '-'; const invalidSequence = '--'; if (typeof str !== 'string' || str.length < minLength || str.length > maxLength || str.includes(invalidSequence) || str.startsWith(invalidStartChar)) return false; for (const char of [...str]) { if (!validChars.includes(char)) return false; } return true; } exports.isContainerName = isContainerName; /** Parses a given path into a container and blob name. */ function parse(path, root) { if (root === '/') { const parts = path.split('/'); if (parts[0] === '') { return { container: parts[1], blobName: parts.slice(2).join('/') }; } return { container: parts[0], blobName: parts.slice(1).join('/') }; } return { container: root, blobName: path[0] === '/' ? path.substring(1) : path }; } exports.parse = parse; //# sourceMappingURL=helpers.js.map