@wo-library/web
v1.0.0
Published
Web/DOM utilities
Readme
@wo-library/web
Browser and DOM utilities for script loading, fetch wrappers, storage abstraction, and more.
Installation
npm install @wo-library/web
# or
yarn add @wo-library/webFeatures
Script & Stylesheet Loading
Dynamically inject <script> or <link> tags with CSP nonce support.
import { loadScript, loadStylesheet } from "@wo-library/web";
await loadScript("https://cdn.example.com/sdk.js");
await loadStylesheet("https://cdn.example.com/styles.css");Fetch Wrapper (WoFetch)
Configurable HTTP client with auth header injection, URL construction, pluggable error/response handlers, and XHR file upload with progress.
import { fetch } from "@wo-library/web";
const api = new fetch.WoFetch({ endpoint: "https://api.example.com" });
const user = await api.getUrl<User>("/users/1");
await api.postUrl("/users", { data: { name: "Alice" } });Storage Abstraction (AnyStorage)
Unified API across localStorage, sessionStorage, and in-memory fallback. Supports optional JSON serialisation and key prefixing.
import { storage } from "@wo-library/web";
await storage.anyStorageInstance.setItem("token", "abc123", { persist: true });
const token = await storage.anyStorageInstance.getItem("token", { persist: true });CSS Utilities
Read and set CSS custom properties on DOM elements.
import { cssVariable, overrideStyleProperty } from "@wo-library/web";
const color = cssVariable("--primary-color");
overrideStyleProperty("--primary-color", "#ff0000");SVG Utilities
Serialise SVG nodes or markup strings to data:image/svg+xml URIs.
import { svg } from "@wo-library/web";
const dataUri = svg.svgNodeToData(document.querySelector("svg")!);Error Classes
Typed error hierarchy for network and response failures:
| Class | Description |
| --- | --- |
| WoError | Base error |
| WoLoadScriptError | Script failed to load |
| WoNetworkError | No response received |
| WoResponseError<T> | Non-OK response with data and status |
Payments
Razorpay checkout integration via razorpayCheckout.
Routing
redirectToLogout — redirects to a logout path with optional from and message query parameters.
Dependencies
lodash-es— tree-shakeable utilitiestype-fest— type helpers
Related Packages
@wo-library/js— pure JS/TS utilities@wo-library/react— React components and hooks
License
MIT
