UNPKG

fs-zoo

Version:

File system abstractions and implementations

25 lines (24 loc) 978 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertType = exports.assertName = exports.parseId = exports.parseParts = void 0; const parseParts = (path) => (!path ? [] : path.split('/').filter(Boolean)); exports.parseParts = parseParts; const parseId = (path) => { const collection = (0, exports.parseParts)(path); const resource = collection.pop() || ''; return [collection, resource]; }; exports.parseId = parseId; const nameRegex = /^(\.{1,2})$|^(.*([\/\\]).*)$/; const assertName = (name, method, klass) => { const isInvalid = !name || nameRegex.test(name); if (isInvalid) throw new TypeError(`Failed to execute '${method}' on '${klass}': Name is not allowed.`); }; exports.assertName = assertName; const assertType = (type, method, klass) => { const length = type.length; for (let i = 0; i < length; i++) (0, exports.assertName)(type[i], method, klass); }; exports.assertType = assertType;