@sapphire/plugin-api
Version:
Plugin for @sapphire/framework to expose a REST API
82 lines (80 loc) • 2.25 kB
JavaScript
import { __name } from '../../../chunk-S573YWRP.mjs';
import { isNullishOrEmpty } from '@sapphire/utilities';
import { RouterBranch } from './RouterBranch.mjs';
var _RouterRoot = class _RouterRoot extends RouterBranch {
constructor() {
super("::ROOT::", false, null);
}
/**
* Adds a route to the branch
*
* @param route The route to add
* @returns The node the route was added to
*/
add(route) {
return this._add(route.path, 0, route);
}
/**
* Removes a route from the branch
*
* @param route The route to remove
* @returns Whether or not the route was removed
*/
remove(route) {
return this._remove(route.path, 0, route);
}
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
get path() {
return "";
}
toString() {
return "";
}
static makeRoutePathForPiece(directories, name) {
const parts = [];
for (const directory of directories) {
const trimmed = directory.trim();
if (isNullishOrEmpty(trimmed)) continue;
if (trimmed.startsWith("(") && trimmed.endsWith(")")) continue;
parts.push(trimmed);
}
if (name !== "index") {
parts.push(name.trim());
}
return parts.join("/");
}
static normalize(path) {
const parts = [];
if (isNullishOrEmpty(path)) return parts;
let part = "";
for (const char of path) {
if (char === "/") {
if (part.length) {
parts.push(part);
part = "";
}
} else {
part += char;
}
}
if (part.length) {
parts.push(part);
}
return parts;
}
static extractMethod(path) {
if (path.length === 0) return null;
if (typeof path === "string") {
const methodSeparatorPositionIndex = path.lastIndexOf(".");
if (methodSeparatorPositionIndex === -1 || methodSeparatorPositionIndex === path.length - 1) return null;
return path.slice(methodSeparatorPositionIndex + 1).toUpperCase();
}
const lastIndex = path.length - 1;
return _RouterRoot.extractMethod(path[lastIndex]);
}
};
__name(_RouterRoot, "RouterRoot");
var RouterRoot = _RouterRoot;
export { RouterRoot };
//# sourceMappingURL=RouterRoot.mjs.map
//# sourceMappingURL=RouterRoot.mjs.map