stnd.buildSTANDARD MANUAL2026-07-15

@stnd/utils

@stnd/utils

Pure utility functions for the Standard Ecosystem.


The odds-and-ends drawer: slugify a title, count reading time, merge two config objects deeply, validate a filename. No framework, no side effects, zero dependencies — safe to import anywhere (Node, browser, Cloudflare Worker) without dragging anything else in.

import { slugify, formatDate } from "@stnd/utils";
slugify("Hello World!"); // "hello-world"
formatDate(new Date(), "dot"); // "24.03.14" — YY.MM.DD, two-digit year

Overview

@stnd/utils provides a collection of small, focused utility functions with zero dependencies. These functions are designed to be “pure” — they have no side effects and do not depend on any specific framework or environment (isomorphic).

Key Modules

String & Content (/utils.js)

  • slugify(text): Robust generation of URL-friendly slugs.
  • excerptWords(content, maxWords): Generates excerpts from Markdown.
  • firstParagraph(content): Extracts the first paragraph of text.
  • getReadingTime(text): Estimates reading time in minutes.
  • numberOfWords(text): Accurate word count for various languages.

Filenames & IDs (/filename.js)

  • isNanoId(str): Validates Nano ID format.
  • generateShortId(length): Generates a cryptographically secure short ID.
  • sanitizeFilename(name, fallback): Ensures a string is safe for use as a filename.
  • makeUniqueFilename(base, usedSet): Appends suffixes to avoid filename collisions.

CSS Sanitization (/css.js)

  • sanitizeCssColor(value): Validates and cleans CSS color strings.
  • sanitizeCssFontFamily(value): Validates font family declarations.
  • sanitizeCssNumber(value): Validates numeric values with units (px, rem, etc.).

Date & Time (/utils.js)

  • formatDate(date, format): Flexible date formatting (ISO, HTML, locale).
  • getYear(date): Extracts the year from various date formats.
  • timeAgo(timestamp): Human-readable relative time (e.g., “5m ago”).

Data & Logic (/utils.js)

  • deepMerge(target, …sources): Deeply merges multiple objects.
  • validateEmail(email): Basic email format validation.
  • filterData(arr, path, value): Filters an array of objects based on a nested property path.

Usage

import { slugify, formatDate } from "@stnd/utils";

const title = "Hello World!";
const slug = slugify(title); // "hello-world"

const today = formatDate(new Date(), "dot"); // "24.03.14" (YY.MM.DD)

Features

  • Tree-Shakable: Import only what you need to keep your bundles small.
  • Isomorphic: Works in Node.js, Browsers, and Edge Workers.
  • Zero Dependencies: Maximum portability and security.

Notes / Observations

  • The "dot" format is YY.MM.DD (two-digit year) — a prior version of this
    doc claimed "2024.03.14" (four-digit year), which doesn’t match formatDate‘s actual implementation in utils.js.

Todo

  • [ ] Nothing tracked yet.