2.1.9 • Published 6 days ago

@diotoborg/et-facere-iusto v2.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

Extract domain name from URL

Donate

This package provides a performant way to extract domain names from URLs without using regular expressions or array manipulations.

Learn more about What is a URL

Supports

  • ESM
  • Node.js
  • Browser

Usage

Installation

$ npm i --save @diotoborg/et-facere-iusto

Development

# Install bun https://bun.sh/
curl -fsSL https://bun.sh/install | bash


# tests
bun test:watch

API

ESM import

import extractDomain from '@diotoborg/et-facere-iusto';

Examples

const urls = [
    'https://www.npmjs.com/package/@diotoborg/et-facere-iusto',
    'http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
    'http://user:password@example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
    'https://npmjs.com/package/@diotoborg/et-facere-iusto',
    'ftp://example.org/resource.txt',
    'http://example.co.uk/',
    'this.is.my@email.com',
];

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 requires the optional dependency of the psl library.

Examples

npm i --save-optional psl
const url =
    'http://www.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument';

async function extract(url) {
    console.log(await extractDomain(url, { tld: true }));
    // example.co.uk
}

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

Please note that using the tld flag may significantly slow down the process. Benchmark (old) results:

# 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

$ bun test

Coding style

$ bun pretty

Benchmark

$ bun benchmark

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.

objectestreeprotobufstringparsingfile systemObservableses2017byteOffsetdataViewmochaInt8ArraydependenciescolouremrtrimEndflatMapsortedtrimRightupsnswaffindLastIndexshamdefinesymbolwidthES2019gitignoreframerqueuefunction.lengthratebannerequalityserializeenumerablewordwrapwgetredux-toolkitconsoleenvironmentiteratorimportexporttoArrayprotocol-buffersgenericscensorposetranspilercjks3ratelimitbinddeep-copyintrinsiceventDispatcherObject.keysexecuteterminalsettingsreact posepnpm9boundfindelbtypedarrayvpcviewassertentriesoptionnegativemakeaccessorlasttoSortedworkflowparenttddoutputclass-validatornumberinternal slotRxJSpropertiesArray.prototype.findLastIndexfunctionsjapaneseES2020dataECMAScript 5serializerlibphonenumbergetslicewaitbrowserstyledebuggerweakmapreaditerateisConcatSpreadableeslintconfigWeakMaperrorbreakECMAScript 2023deepatominternalschememkdirsjasminesetes2016wordbreakrangeerrorstreamlinewrapbyteLengthkeysecmascriptreact-hooksfast-cloneextrastringifyES8includespackage.jsonrequestloggeriamrm -rfYAMLtransformxhrhttpshasOwnPropertytoStringTagBigUint64ArraysymlinkelectrontakeECMAScript 3parsemanipulationfilterswfendpointreducerspinnerunicodefscopyinspectvalidatehash.envchineseagentObject.assignrm -frapisetterInt16ArraykarmaArray.prototype.flattenECMAScript 6ES6pluginbinariesyupgetintrinsicfast-deep-clonesearchrecursivecoreweaksetinstallutillinktrimieArrayBuffertoobjecttypanionansiECMAScript 2022directoryajvequalsomehastslibwalkhasOwntaskjestfastes2018argsconsumecirculararktypevaluesthreereadableReflect.getPrototypeOfcore-jsReactiveExtensionspropStreamthroatargumentnpmremoverobustObject.fromEntriesredirect[[Prototype]]WebSocket_.extendcharactertypescriptomitfetchassertsPushphonetypeofeventEmitterpropertypersistentes-abstract@@toStringTagformsReactiveXeslintpluginbrowserlista11ypostcss-pluginfast-copytraversetimeSymbol.toStringTagmkdirexpressiontouchreact animationwhatwgUnderscore.gitignoreArray.prototype.filterutilitiesmovenamesideconfigpreprocessorformattingspeedES7ajaxqs0buffersasynceslintECMAScript 2017lazypackageinputcolumnbeanstalktelephoneECMAScript 7fullrouting3dtermexecvarsmimetypesrmidleshimspringes2015util.inspectworkerindicatorworkspace:*resolveconcurrencyECMAScript 2015CSSsameValueZerocode pointsdataviewstylesMicrosoftescapetc39metadatagdprECMAScript 2018bundlingparsercolumnstsstoragegatewayzodfeedchromiumlocaljsdiffUint16Arrayes7quotefunctionhelpersgraphqlvariablesgroupByasciiautoscalingzxSymbolfnmatchcoercibledropiterationpipeWebSocketsTypedArraysyntaxArray.prototype.findLastenvironmentsloadingtypesafejsonsqsnpmignorehttpbincalloptimizerincontainseslint-pluginschemaregularcallbindArray.prototype.containsemojireducepathESnextbrowserslistmulti-packagedebugBigInt64ArrayHyBizeroserializationmoduletextprefixmake dircommandairbnbsafeArrayBuffer.prototype.sliceruntime
2.1.9

6 days ago

2.0.9

7 days ago

1.0.9

8 days ago

1.0.8

9 days ago

1.0.7

10 days ago

1.0.6

11 days ago

1.0.5

12 days ago

1.0.4

13 days ago

1.0.3

14 days ago

1.0.2

15 days ago

1.0.1

16 days ago