bananas-commerce-admin
Version:
What's this, an admin for apes?
76 lines • 2.12 kB
JavaScript
export * from "./contribute";
export * from "./country_code_formatter";
export * from "./form_validation";
export * from "./format_date";
export * from "./format_purchase_number";
export * from "./format_string";
export * from "./get_cookie";
export * from "./has_access";
export * from "./has_group";
export * from "./has_permission";
export * from "./is_email";
export * from "./is_positive_integer";
export * from "./is_url";
export * from "./pluralize";
export * from "./select_styles";
export * from "./timeline";
export * from "./to_title_case";
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