All Projects → bjarneo → extract-domain

bjarneo / extract-domain

Licence: MIT license
Extract domain name from an URL

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to extract-domain

Parse Domain
Splits a hostname into subdomains, domain and (effective) top-level domains.
Stars: ✭ 261 (+1086.36%)
Mutual labels:  parse, domain
domain-word
Tells you which "words" can be written as a publicly available domain
Stars: ✭ 40 (+81.82%)
Mutual labels:  domain, domain-name
mpq
Decoder/parser of Blizzard's MPQ archive file format
Stars: ✭ 28 (+27.27%)
Mutual labels:  parse
domain-monitor
Self-hosted server to monitor WHOIS records for specified domains.
Stars: ✭ 36 (+63.64%)
Mutual labels:  domain
sitemapper
parses sitemaps for Node.JS
Stars: ✭ 70 (+218.18%)
Mutual labels:  parse
logparser
Easy parsing of Apache HTTPD and NGINX access logs with Java, Hadoop, Hive, Pig, Flink, Beam, Storm, Drill, ...
Stars: ✭ 139 (+531.82%)
Mutual labels:  parse
flex-bison-indentation
An example of how to correctly parse python-like indentation-scoped files using flex (and bison).
Stars: ✭ 32 (+45.45%)
Mutual labels:  parse
PyScholar
A 'supervised' parser for Google Scholar
Stars: ✭ 74 (+236.36%)
Mutual labels:  parse
pixie
Tiny template functions.
Stars: ✭ 14 (-36.36%)
Mutual labels:  parse
exjson
JSON parser and genarator in Elixir.
Stars: ✭ 71 (+222.73%)
Mutual labels:  parse
SwiftDomainParser
A Full Swift Lightweight Framework that uses the Public Suffix list to Parse URLs
Stars: ✭ 48 (+118.18%)
Mutual labels:  parse
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (+172.73%)
Mutual labels:  parse
pixl-xml
A simple module for parsing and composing XML.
Stars: ✭ 78 (+254.55%)
Mutual labels:  parse
parse-author
Parse a person, author, contributor or maintainer string into an object with name, email and url properties following NPM conventions. Useful for the `authors` property in package.json or for parsing an AUTHORS file into an array of person objects.
Stars: ✭ 23 (+4.55%)
Mutual labels:  parse
Android-Clean-Architecture
This is a sample movie list Android application built to demonstrate use of Clean Architecture tools. Dedicated to all Android Developers - (Kotlin, MVVM, Clean Architecture, Rx-Java, Dagger, OkHttp, Unit Testing, SOLID principles, Code Coverage)
Stars: ✭ 268 (+1118.18%)
Mutual labels:  domain
domin
Domain Name Search untuk mencari ketersedian nama domain.
Stars: ✭ 17 (-22.73%)
Mutual labels:  domain
strongs-dictionary-xml
Strong's Greek Dictionary in XML with real Greek
Stars: ✭ 65 (+195.45%)
Mutual labels:  domain
pfp-vim
A vim hex-editor plugin that uses 010 templates to parse binary data using pfp
Stars: ✭ 57 (+159.09%)
Mutual labels:  parse
snapdragon-lexer
Converts a string into an array of tokens, with useful methods for looking ahead and behind, capturing, matching, et cetera.
Stars: ✭ 19 (-13.64%)
Mutual labels:  parse
postcss-styl
PostCSS parser plugin for converting Stylus syntax to PostCSS AST.
Stars: ✭ 15 (-31.82%)
Mutual labels:  parse

Extract domain name from URL

Donate Travis

Performant domain name extraction. No regex or array magic.

What is an URL

However. This package will also remove the sub domain, and unless the TLD option is used, anything other than the domain and second level domain (so www.example.co.uk would return co.uk)

Supports

Browser and Node.

Usage

$ npm i --save extract-domain
  • urls = string|array
  • returns string|array
extractDomain(urls);

ES6

import extractDomain from "extract-domain";
const extractDomain = require("extract-domain");
const urls = [
    "https://www.npmjs.com/package/extract-domain",
    "http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument",
    "http://user:[email protected]:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument",
    "https://npmjs.com/package/extract-domain",
    "ftp://example.org/resource.txt",
    "http://example.co.uk/",
    "[email protected]"
];

extractDomain(urls[0]); // npmjs.com

extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com', 'example.org', 'co.uk', 'email.com' ]

TLD support

TLD support require optional dependency to psl library.

const url =
    "http://www.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument";

extractDomain(url, { tld: true });
// example.co.uk

However, using the tld flag will slow down the process by many seconds. Benchmark:

# extract domain 10,000 times
  end ~14 ms (0 s + 13572914 ns)
# extract domain with tld 10,000 times
  end ~4.29 s (4 s + 288108681 ns)

Tests

$ npm test

Coding style

$ npm run pretty

Benchmark

$ npm run benchmark

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].