chanmyaemaung / justparseurl

Built with a minimalistic approach, JustParseUrl remains incredibly lightweight, ensuring optimal performance without unnecessary overhead.

Home Page:https://www.npmjs.com/package/justparseurl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JustParseUrl - A Lightweight URL Parser

npm version License npm downloads Bundle Size TypeScript Code Style: Prettier Contributions Welcome

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.

Demo

Code Pen

Table of Contents

Installation

You can install JustParseUrl via npm:

npm install justparseurl

Usage

Node.js

const JustParseUrl = require("justparseurl");

const urlInstance = new JustParseUrl("https://example.com/path?query=value");
console.log(urlInstance);

Frontend Libraries (ES6 Module)

import JustParseUrl from 'justparseurl';

const urlInstance = new JustParseUrl('https://example.com/path?query=value');
console.log(urlInstance.);

CDN (Vanilla JS)

Include the script in your HTML file:

<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>

API

constructor(input: string)

Creates a new instance of the JustParseUrl class with the provided URL.

Properties

  • 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.

getDetails()

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.

Usage

const justParseUrl = new JustParseUrl('https://example.com/path?query=value');
console.log(justParseUrl.getDetails());

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the ISC License - see the LICENSE.md file for details.

About

Built with a minimalistic approach, JustParseUrl remains incredibly lightweight, ensuring optimal performance without unnecessary overhead.

https://www.npmjs.com/package/justparseurl

License:ISC License


Languages

Language:TypeScript 100.0%