@samchon/openapi
Version:
OpenAPI definitions and converters for 'typia' and 'nestia'.
25 lines (20 loc) • 1.7 kB
JavaScript
import { NamingConvention } from "./NamingConvention.mjs";
var EndpointUtil;
(function(EndpointUtil) {
EndpointUtil.capitalize = str => str.length !== 0 ? str[0].toUpperCase() + str.slice(1).toLowerCase() : str;
EndpointUtil.pascal = path => EndpointUtil.splitWithNormalization(path).filter((str => str[0] !== "{")).map(NamingConvention.pascal).join("");
EndpointUtil.splitWithNormalization = path => path.split("/").map((str => EndpointUtil.normalize(str.trim()))).filter((str => !!str.length));
EndpointUtil.reJoinWithDecimalParameters = path => {
path = path.split("/").map((str => str[0] === "{" && str[str.length - 1] === "}" ? `:${str.substring(1, str.length - 1)}` : str)).join("/");
return `${path.startsWith("/") ? "" : "/"}${path}`;
};
EndpointUtil.normalize = str => {
str = str.split(".").join("_").split("-").join("_").trim();
if (RESERVED.has(str)) return `_${str}`; else if (str.length !== 0 && "0" <= str[0] && str[0] <= "9") str = `_${str}`;
return str;
};
EndpointUtil.escapeDuplicate = keep => change => keep.includes(change) ? EndpointUtil.escapeDuplicate(keep)(`_${change}`) : change;
})(EndpointUtil || (EndpointUtil = {}));
const RESERVED = new Set([ "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "module", "new", "null", "package", "public", "private", "protected", "return", "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", "with" ]);
export { EndpointUtil };
//# sourceMappingURL=EndpointUtil.mjs.map