For the complete documentation index, see llms.txt. This page is also available as Markdown.

General utils

A set of small, framework-agnostic helpers exported from vueless.

isSSR / isCSR

Two constant booleans (not functions) evaluated once when the module loads. Use them to guard environment-specific code.

import { isSSR, isCSR } from "vueless";

if (isCSR) {
  localStorage.setItem("visited", "1"); // browser-only
}
  • isSSR — true when running on the server (no window).

  • isCSR — true when running in the browser. Exact inverse of isSSR.

setTitle

Set the document title, optionally combined with a suffix (e.g. your app name).

import { setTitle } from "vueless";

setTitle({ title: "Dashboard", suffix: "MyApp" }); // → "Dashboard / MyApp"

Accepts a single options object — all keys optional:

  • title — main page title.

  • separator — string placed between title and suffix (default " / ").

  • suffix — trailing text such as the site/app name.

When title is empty, the document title is set to just the suffix. No-op on the server.

getStored

SSR-safe wrapper over localStorage.getItem.

Returns the stored string, or undefined if the key is missing or running on the server.

getRandomId

Generate a random, non-cryptographic identifier made of letters (A–Z, a–z).

  • length — desired id length (default 15).

getCookie / setCookie / deleteCookie

Read, write, and remove browser cookies.

  • getCookie(name) — returns the decoded cookie value, or undefined if not found.

  • setCookie(name, value, attributes?) — writes a cookie. attributes may include expires (a Date is converted to UTC), path (defaults to "/"), max-age, secure, etc. Boolean-true attributes are emitted as bare flags.

  • deleteCookie(name) — immediately expires the cookie.

createDebounce

Create a debounced version of a function that only fires after a period of inactivity.

  • func — the function to debounce.

  • ms — delay in milliseconds.

Returns a new function that preserves the original argument types and this binding. Each call resets the timer, so func runs only once after ms of silence (trailing edge).

hasSlotContent

Check whether a Vue slot actually renders non-empty content. Useful for conditionally rendering wrappers around optional slots.

  • slot — a Vue slot function (or undefined/null).

  • props — optional props passed to the slot when evaluating it.

Returns false for missing slots or slots that render only comments, empty text, or empty fragments.

Last updated