JustParseUrl is a lightweight and versatile utility designed for parsing URLs effortlessly in both JavaScript and TypeScript. Whether you're working on server-side applications with Node.js, building modern Frontend Libraries (ES6 Module), or crafting vanilla JavaScript for CDN delivery, JustParseUrl seamlessly fits into your web development ecosystem.
You can install JustParseUrl via npm:
npm install justparseurl
const JustParseUrl = require("justparseurl");
const urlInstance = new JustParseUrl("https://example.com/path?query=value");
console.log(urlInstance);
import JustParseUrl from 'justparseurl';
const urlInstance = new JustParseUrl('https://example.com/path?query=value');
console.log(urlInstance.);
<script src="https://cdn.jsdelivr.net/npm/justparseurl@1.1.0/dist/justparseurl.min.js"></script>
<script>
const urlInstance = new JustParseUrl('https://example.com/path?query=value');
console.log(urlInstance);
</script>
Creates a new instance of the JustParseUrl
class with the provided URL.
-
protocol: string
: The protocol scheme of the URL (e.g.,http:
). -
slashes: boolean
: A boolean indicating whether the protocol is followed by two forward slashes (//
). -
auth?: string
: Authentication information portion (e.g.,username:password
). -
username: string
: Username of basic authentication. -
password: string
: Password of basic authentication. -
host: string
: Host name with port number. The hostname might be invalid. -
hostname: string
: Host name without port number. This might be an invalid hostname. -
port: string
: Optional port number. -
pathname: string
: URL path. -
query: Record<string, string>
: Parsed object containing query string. -
hash: string
: The "fragment" portion of the URL including the pound-sign (#
). -
href: string
: The full URL. -
origin: string
: The origin of the URL.
Returns an object with details about the parsed URL, including properties like protocol
, hostname
, pathname
, query
, and more. The details are automatically populated upon creating an instance of the JustParseUrl
class; there's no need for an exclusive call to this method.
const justParseUrl = new JustParseUrl('https://example.com/path?query=value');
console.log(justParseUrl.getDetails());
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the ISC License - see the LICENSE.md file for details.