Fast URL Parsing JavaScript Library - url.js

File Size: 67.4 KB
Views Total: 351
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Fast URL Parsing JavaScript Library - url.js

url.js is a lightweight, fast, and JavaScript-powered URL parser that allows you to extract any data (like domains, subdomains, ports, hostnames, protocol, queries, hashes, etc) from URLs and mailto links.

How to use it:

1. Import the url.js JavaScript library. Note that the library works with both jQuery and Vanilla JavaScript.

// Vanilla JavaScript
<script src="/path/to/dist/url.min.js"></script>
// Contains a list of valid tld's
<script src="/path/to/dist/url-tld.min.js"></script>

// jQuery
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/dist/jquery-url.min.js"></script>
// Contains a list of valid tld's
<script src="/path/to/dist/jquery-url-tld.min.js"></script>

2. Extract data from URLs and mailto links.

// Vanilla JavaScript
$.url('hostname', url);

// jQuery
$.url('hostname', url);
const url = 'https://www.jqueryscript.net/plus/search.php?kwtype=0&keyword=slider'


// net
url('tld',url);

// jqueryscript.net
url('domain',url);

// www.jqueryscript.net
url('hostname', url);

// www
url('sub', url);

// undefined
url('.0', url);

// www
url('.1', url);

// jqueryscript
url('.2', url); 

// net
url('.-1', url);

// username:password
url('auth',url);

// username
url('user',url);

// password
url('pass',url);

// 443
url('port', url);

// https
url('protocol', url);

// /plus/search.php
url('path', url); 

// search.php
url('file', url);

// search
url('filename', url);

// undefined
url('fileext', url);

// plus
url('1', url);

// search.php
url('2', url); 

// undefined
url('3', url); 

// search.php
url('-1', url);

// kwtype=0&keyword=slider
url('query', url); 

// {"kwtype":"0","keyword":"slider"}
url('?', url); 

// slider
url('?keyword', url);

// undefined
url('field[0]', url); 

// undefined
url('field', url); 

// undefined
url('hash', url);

// undefined
url('#', url);

// undefined
url('#para1', url); 

// mailto
url('protocol', 'mailto:[email protected]'); 

// [email protected]
url('email', 'mailto:[email protected]');

This awesome jQuery plugin is developed by websanova. For more Advanced Usages, please check the demo page or visit the official website.