No description
Find a file
2026-02-09 22:38:41 +01:00
.github/workflows Initial commit 2026-02-09 12:28:32 +01:00
src fix: active class 2026-02-09 22:38:41 +01:00
test feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
.eslintrc.json Initial commit 2026-02-09 12:28:32 +01:00
.gitignore Initial commit 2026-02-09 12:28:32 +01:00
.prettierrc Initial commit 2026-02-09 12:28:32 +01:00
CHANGELOG.md Initial commit 2026-02-09 12:28:32 +01:00
LICENSE Initial commit 2026-02-09 12:28:32 +01:00
package-lock.json feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
package.json feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
README.md feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
tsconfig.json Initial commit 2026-02-09 12:28:32 +01:00
tsup.config.ts feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
vitest.config.ts Initial commit 2026-02-09 12:28:32 +01:00

@quartz-community/utils

Shared utility functions for Quartz community plugins.

Installation

npm install @quartz-community/utils

Or using GitHub:

npm install github:quartz-community/utils

Usage

import {
  simplifySlug,
  getFullSlug,
  joinSegments,
  removeAllChildren,
  classNames,
} from "@quartz-community/utils";

// Path utilities
const slug = simplifySlug("folder/index"); // "folder/"
const currentSlug = getFullSlug(window); // e.g., "blog/my-post"
const path = joinSegments("a", "b", "c"); // "a/b/c"

// DOM utilities
removeAllChildren(document.getElementById("container")!);

// Language utilities
const classes = classNames("btn", isActive && "active", null); // "btn active"

Modules

Path (@quartz-community/utils/path)

Path manipulation utilities for Quartz slugs:

  • simplifySlug(slug) - Remove /index suffix from slugs
  • getFullSlug(window) - Get current page slug from document body dataset
  • getFullSlugFromUrl() - Get current page slug from URL pathname
  • joinSegments(...segments) - Join path segments with proper slash handling
  • resolvePath(path) - Ensure path starts with /
  • endsWith(str, suffix) - Check if path ends with suffix
  • trimSuffix(str, suffix) - Remove suffix from path
  • stripSlashes(str, onlyPrefix?) - Remove leading/trailing slashes
  • getFileExtension(path) - Get file extension
  • isFolderPath(path) - Check if path represents a folder
  • getAllSegmentPrefixes(path) - Get all path prefixes

DOM (@quartz-community/utils/dom)

DOM manipulation utilities:

  • removeAllChildren(element) - Remove all child nodes from an element
  • registerEscapeHandler(container, callback) - Register Escape key and click-outside handlers
  • normalizeRelativeURLs(document, baseUrl) - Convert relative URLs to absolute

Lang (@quartz-community/utils/lang)

Language/general utilities:

  • classNames(...classes) - Combine CSS class names, filtering falsy values

Types

The package exports TypeScript types for type-safe slug handling:

import type { FullSlug, SimpleSlug, RelativeURL } from "@quartz-community/utils";

License

MIT