UNPKG

bananas-commerce-admin

Version:

What's this, an admin for apes?

59 lines 1.57 kB
export function ensureTrailingSlash(path) { if (path != null && !path.endsWith("/")) { return `${path}/`; } return path; } export function ensureLeadingHash(hash) { if (hash != null && !hash.startsWith("#")) { return `#${hash}`; } return hash; } export function absolutePath(path, basename = "/") { if (!path) { return path; } let pathname = path; // Make relative path absolute to basename if (!pathname.startsWith("/")) { pathname = ensureTrailingSlash(basename) + pathname; } // Expand path if (pathname.indexOf(".") >= 0) { const stack = []; for (const part of pathname.split("/")) { if (part === ".") { continue; } else if (part === ".." && stack.length > 0) { stack.pop(); } else { stack.push(part); } } pathname = stack.join("/"); } return ensureTrailingSlash(pathname); } export function nthIndexOf(str, pattern, n, start) { const index = str.indexOf(pattern, start ?? 0); if (index >= 0 && n > 1) { return nthIndexOf(str, pattern, n - 1, index + 1); } return index; } /** * Like Python’s `.capitalize()`. */ export function capitalize(string) { return string.slice(0, 1).toUpperCase() + string.slice(1).toLowerCase(); } /** * Like Python’s `.title()`. */ export function title(string) { return string.split(" ").map(capitalize).join(" "); } //# sourceMappingURL=index.js.map