h1k.sh/l1TGF0   [ home ]   [ history ]   [ download ]

revision-3  2026-05-04 14:23 UTC  sha256:be6edfb979b6ac214d8e31e5314bdde85e3c6fb09073ba4f41d944fced308344

#lang:ts
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const SLUG_LEN = 6;

export function randomSlug(): string {
  const bytes = new Uint8Array(SLUG_LEN);
  crypto.getRandomValues(bytes);
  let out = '';
  for (let i = 0; i < SLUG_LEN; i++) {
    out += ALPHABET[bytes[i]! % 62];
  }
  return out;
}

export function isValidSlug(s: string): boolean {
  if (s.length < 1 || s.length > 32) return false;
  return /^[a-zA-Z0-9][a-zA-Z0-9-]*$|^[a-zA-Z0-9]$/.test(s);
}

export function normalizeSlug(s: string): string {
  return s.trim().toLowerCase();
}

const RESERVED = new Set([
  'new', 'published', 'api', 'admin', 'e', 'feed', 'raw',
  'stats', 'canary', 'health', 'robots', 'sitemap', 'install',
  'random', 'search', 'help', 'about', 'legal', 'privacy',
  'terms', 'contact', 'login', 'logout', 'register', 'account',
  'settings', 'dashboard', 'profile', 'upload', 'download',
]);

export function isValidCustomSlug(s: string): boolean {
  if (s.length < 1 || s.length > 32) return false;
  if (s.startsWith('-') || s.endsWith('-')) return false;
  if (s.includes('--')) return false;
  if (!(/^[a-z0-9-]+$/.test(s))) return false;
  if (RESERVED.has(s)) return false;
  return true;
}
#lang:python
# hello world 
print("lol")
#lang:none
hi