Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

874 B
Raw Blame
export const createId = (prefix: string) => `${prefix}_${crypto.randomUUID().replace(/-/g, "")}`;

export const isoNow = () => new Date().toISOString();

// Limits, offsets and cursors are bound to SQL integer parameters, which
// reject fractions, so a value such as `?limit=1.5` is truncated first.
export const clampNumber = (value: number, min: number, max: number) =>
  Number.isNaN(value) ? min : Math.min(Math.max(Math.trunc(value), min), max);

export const parseJsonArray = (json: string): string[] => {
  try {
    const value = JSON.parse(json);
    return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
  } catch {
    return [];
  }
};

export const slugify = (value: string) =>
  value
    .trim()
    .toLowerCase()
    .replace(/['"]/g, "")
    .replace(/[^\p{L}\p{N}]+/gu, "-")
    .replace(/^-+|-+$/g, "")
    .slice(0, 80);