{"library":"parseuri","title":"parseUri: Mighty but Tiny URI Parser","description":"parseUri is a highly compact and comprehensive JavaScript library for parsing URIs, URNs, and URLs into their constituent parts. The current stable version is 3.0.2, with major breaking changes introduced in v2.0.0 and v3.0.0; the latter also transitioned the package to pure ESM. Historically, releases were infrequent, but v3 indicates renewed activity. Its key differentiators include its small footprint (1KB min/gzip), zero dependencies, and robust handling of partial or invalid URIs where the built-in `URL` constructor might throw errors. It also provides a richer set of URI properties, such as `authority`, `userinfo`, `subdomain`, `domain`, `tld`, and `resource`, which are not exposed by the native `URL` object, making it suitable for complex URI analysis beyond standard web URLs. It supports a 'friendly' parsing mode and configurable multi-level TLDs.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install parseuri"],"cli":null},"imports":["import parseUri from 'parseuri';","import { setTlds } from 'parseuri';","import type { URI } from 'parseuri';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import parseUri, { setTlds } from 'parseuri';\n\n// Configure custom TLDs, e.g., to handle 'co.uk' as a single TLD\nsetTlds({ 'co': ['uk', 'jp'], 'com': ['au'] });\n\nconst uriString = 'https://user:pass@sub1.sub2.example.co.uk:8080/p/a/t/h/a.html?q=1&param=two#hash';\nconst parsed = parseUri(uriString);\n\nconsole.log('Full URI (href):', parsed.href);\nconsole.log('Protocol:', parsed.protocol);\nconsole.log('Hostname:', parsed.hostname);\nconsole.log('Domain:', parsed.domain);\nconsole.log('TLD:', parsed.tld); // Will show 'co.uk' due to setTlds\nconsole.log('Pathname:', parsed.pathname);\nconsole.log('Query parameter \"q\":', parsed.queryParams.get('q'));\nconsole.log('All query parameters:', Object.fromEntries(parsed.queryParams.entries()));\n\n// Example of parsing a relative path (friendly mode)\nconst friendlyParsed = parseUri('example.com/file.html', true); // 'true' enables friendly mode\nconsole.log('\\nFriendly Mode Domain:', friendlyParsed.domain);\nconsole.log('Friendly Mode Filename:', friendlyParsed.filename);\n\n// Example with a non-web protocol\nconst customProtocolUri = 'git://localhost:1234/repo/project.git';\nconst customParsed = parseUri(customProtocolUri);\nconsole.log('\\nCustom Protocol:', customParsed.protocol);\nconsole.log('Custom Protocol Hostname:', customParsed.hostname);\nconsole.log('Custom Protocol Pathname:', customParsed.pathname);","lang":"typescript","description":"Demonstrates importing `parseUri` and `setTlds`, parsing a complex URI, accessing various parts including query parameters, and showing usage of friendly mode and non-web protocols.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}