UNPKG

@sapphire/plugin-api

Version:

Plugin for @sapphire/framework to expose a REST API

85 lines (82 loc) 2.38 kB
'use strict'; var utilities = require('@sapphire/utilities'); var RouterBranch_cjs = require('./RouterBranch.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var _RouterRoot = class _RouterRoot extends RouterBranch_cjs.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 (utilities.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 (utilities.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; exports.RouterRoot = RouterRoot; //# sourceMappingURL=RouterRoot.cjs.map //# sourceMappingURL=RouterRoot.cjs.map