1.0.2 • Published 6 months ago
just-domain v1.0.2
just-domain
A lightweight utility to quickly extract domains from URLs in both browser and Node.js environments.
Installation
npm install just-domain
Usage
import { justDomain } from 'just-domain';
// Basic usage
console.log(justDomain('https://example.com/path')); // 'example.com'
// Strip www
console.log(justDomain('https://www.example.com', { stripWww: true })); // 'example.com'
// Include port
console.log(justDomain('http://localhost:3000', { includePort: true })); // 'localhost:3000'
// In browser, defaults to current URL if no argument provided
console.log(justDomain()); // current domain
API
justDomain(href?, options?)
Parameters
href
(optional): URL string to parse. In browser environments, defaults to current page URL.options
(optional): Configuration objectstripWww
: Remove 'www.' prefix if presentincludePort
: Include port number in output if present
License
MIT