@ooneex/url wraps the native URL with a friendlier, typed API. It parses a URL into its parts (protocol, subdomain, domain, port, path, queries, fragment), coerces query values to their natural types, and exposes helpers for common parameters like lang, page, limit, and order. A chainable Url class lets you mutate and rebuild URLs, while ReadonlyUrl offers the same read accessors without mutation.
Installation
Add the package with Bun.Usage
Construct aUrl from a string (or a native URL) and read its parts. Query values are automatically parsed: "true"/"false" become booleans and numeric strings become numbers.
Url class is chainable: every setter returns the instance and rebuilds the underlying URL, so you can read the result with toString().
ReadonlyUrl, which exposes all the getters but none of the setters.
When to use it
- You need to read URL query parameters already coerced to their natural types (numbers, booleans) instead of raw strings.
- You handle list endpoints and want typed accessors with defaults for
page,limit,order,orderBy,lang, and search (q). - You want to build or modify URLs fluently with a chainable API that handles path normalization, default ports, and query rebuilding for you.
- You want a read-only view of a URL (
ReadonlyUrl) to pass around without risk of mutation. - You don’t need it for trivial cases where the native
URLandURLSearchParamsalready cover what you do.