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—truewhen running on the server (nowindow).isCSR—truewhen running in the browser. Exact inverse ofisSSR.
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 (default15).
getCookie / setCookie / deleteCookie
Read, write, and remove browser cookies.
getCookie(name)— returns the decoded cookie value, orundefinedif not found.setCookie(name, value, attributes?)— writes a cookie.attributesmay includeexpires(aDateis converted to UTC),path(defaults to"/"),max-age,secure, etc. Boolean-trueattributes are emitted as bare flags.deleteCookie(name)— immediately expires the cookie.
The cookie helpers access document directly and are client-side only — calling them during SSR will throw. Guard with isCSR if needed.
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 (orundefined/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