Skip to content

Repository files navigation

@build-from-bits/browser-utils

Browser/environment utilities: URL helpers, SSR detection, and media URL builders.

Install

npm install @build-from-bits/browser-utils

API

  • IN_SERVERtrue when window is undefined (SSR/Node).
  • getProtocol()window.location.protocol or null on the server.
  • getHostname() — host + port (example.com:8080) or null on the server.
  • getHostlink()https://example.com:8080.
  • getCurrentUrl() — full current URL or null on the server.
  • getUrlParameter(name) — query param value, or '' when missing.
  • isNoWindow()true when window does not exist.
  • getMediaUrl(baseUrl, key, options) — transformed media URL (h, w, f, q).
  • getOriginalMediaUrl(baseUrl, key, extra) — untransformed media URL with optional extra params.

Usage

import { getHostlink, getUrlParameter, getMediaUrl } from '@build-from-bits/browser-utils';

const host = getHostlink();
const token = getUrlParameter('token');
const img = getMediaUrl('https://cdn.example.com/api/file/get', 'key-1', { w: 400, q: 80 });

Publish

npm run build
npm run pack:check
npm run publish:npm
npm run publish:github

License

Licensed under the Apache License 2.0.

Copyright 2026 Build From Bits Pvt Ltd.

About

Browser/environment utilities: URL helpers, SSR detection, and media URL builders.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages