Registry / devops / urlite

urlite

JSON →
library3.1.0jsnpmunverified

urlite is a minimal, dependency-free URL parser and formatter for Node.js and browsers, optimized for size and speed. Version 3.1.0 compresses to under 1 kB minified and achieves over 2 million parse operations per second—outperforming most alternatives. It uses a single regex to extract URL components in one pass. An 'extra' entry point adds querystring, hash, and auth parsing/formatting. Ship TypeScript definitions. Ideal when bundle size and parsing performance are critical.

npm install urlite
INSTALL
IMPORT
SIG · URLITE
U
urlite
devopsjavascriptv3.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (parse)
import urlite from 'urlite'
import { parse } from 'urlite'
Main export is a function; use default import for the parse function. Named export 'parse' does not exist.
default (extra)
import urlite from 'urlite/extra'
import { extra } from 'urlite'
Extended version with querystring, hash and auth parsing. Import from 'urlite/extra' subpath.
require (CommonJS)
const urlite = require('urlite')
const { default } = require('urlite')
CJS require yields the parse function directly. No destructuring of 'default' needed.

Parse a URL with auth, port, path, query, and hash; then format back to original string.

import urlite from 'urlite'; const parsed = urlite.parse('http://user:pass@example.com:8080/path?query=string#fragment'); console.log(parsed); /* { auth: 'user:pass', hash: '#fragment', hostname: 'example.com', href: 'http://user:pass@example.com:8080/path?query=string#fragment', path: '/path?query=string', pathname: '/path', port: '8080', protocol: 'http:', search: '?query=string' } */ const formatted = urlite.format(parsed); console.log(formatted); // 'http://user:pass@example.com:8080/path?query=string#fragment'
Debug
Known issues
gotchaThe 'hash' property includes the leading '#' character. e.g. '#fragment'. Many other parsers omit the '#'.
fix
Strip '#' manually: parsed.hash.slice(1) or use urlite/extra for parsed hash object.
affects: >=1.0.0
gotchaThe 'search' property includes the leading '?' character. e.g. '?query=string'.
fix
Strip '?' manually: parsed.search.slice(1) or use urlite/extra for parsed search object.
affects: >=1.0.0
gotchaurlite/extra mutates the parsed object (search and hash become objects with setters). Passing the same object to format may produce unexpected results if you modify those objects.
fix
Clone the parsed object before mutation or re-parse if you need to modify search/hash.
affects: >=1.0.0
gotchaNo built-in normalization (e.g. lowercasing hostname, removing default ports). The output is as given.
fix
If you need normalization, handle it manually after parsing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: urlite.parse is not a function
Used named import 'parse' instead of default import.
fix
Change `import { parse } from 'urlite'` to `import urlite from 'urlite'`, then use `urlite.parse()`.
Module not found: Can't resolve 'urlite/extra'
Missing file or webpack resolve issues with subpath imports.
fix
Ensure you are using version 3.1.0+ which includes the extra subpath. Also check that your bundler supports package.json 'exports' field. Use `require('urlite/extra')` or a full path fallback.
Cannot read property 'slice' of undefined
Trying to call .slice() on properties that are undefined (e.g., when no hash or search present).
fix
Check for existence: `parsed.hash && parsed.hash.slice(1)` or use optional chaining: `parsed.hash?.slice(1)`.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
packageurlite
urlite — npm install urlite · libregistry