UNPKG

sensai

Version:

Because even AI needs a master

42 lines (41 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, /** * Get metadata from file path. * @notes please note we will assume we can only have one slot folder in a file path (usually right before filename). */ "default", { enumerable: true, get: function() { return _default; } }); const _constants = require("../../constants"); const _default = (filePath)=>{ // Split the entire path into segments const segments = filePath.split("/"); // The last segment is the filename const filename = segments.pop(); // Determine method from filename (route.METHOD.ts) const chunks = filename.split("."); const method = chunks.length > 2 ? chunks[1].toUpperCase() : _constants.HTTP_ANY; // filter collections/slots let version = _constants.VERSION_DEFAULT; const pathname = segments.filter((segment)=>{ if (segment.startsWith("(") && segment.endsWith(")")) { return false; } if (segment.startsWith("@")) { version = segment.substring(1); return false; } return true; }).join("/"); return { pathname, filename, method, version }; };