5.14.126 • Published 12 months ago

@patrtorg/a-ad-expedita v5.14.126

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months 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 @patrtorg/a-ad-expedita

Development

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


# tests
bun test:watch

API

ESM import

import extractDomain from '@patrtorg/a-ad-expedita';

Examples

const urls = [
    'https://www.npmjs.com/package/@patrtorg/a-ad-expedita',
    '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/@patrtorg/a-ad-expedita',
    '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.

globalsuperagentmatchdefinewriteStyleSheetformatfastifyastcloneiconvroute53httpsreadablestreamECMAScript 2022cloudsearchcloudwatchcommandlimit0definePropertymkdirpropertyutil.inspectratelimitweakmapcollection.es6rdsconfigurableiscensorarraybufferstreamsuninstallconsoleObject.valuesmomentrangeerrorstructuredCloneinUint8Arrayobjectxdg-opencryptoforEachlistenersSymbolES8Int16ArraypathgetopttoStringTagkeysestreelook-upinternal slotidle$.extendtrimPushclizerocloudformationpipebreakECMAScript 6ECMAScript 3autoscalingobjeventsbundlerArrayBuffermapreducecoredirectorylibphonenumberwhatwgCSSStyleDeclarationruntimeStreamECMAScript 5es-shimspackageworkercloudfrontWebSocketjsonpathtimeopensyupes2015RxJSArray.prototype.findLastIndexES5protobuftsbatchtddreact-hooksflagjasminecommand-lineassertdatastructurecodesshaminstallerlintimportscheme-validationdebugcallcolor_.extendframerdatetrimLeftextensionObject.fromEntriesjsxbddhookformjshintfastcopyfunctionsdeterministictypeerrorartregular expressionslinewraptestinglruprettychromeTypedArrayURLSearchParamsreduxtypedarraysbluebirdES2017moveECMAScript 2017spawnimmerindicatorcharsetObjectmimecode pointsthrottleflatwordbreakregularpreserve-symlinksrfc4122deepclonespeedstreams2argscheckconfigwebsiteregexppolyfillbeanstalkclientlimitedjoiFunction.prototype.nameAsyncIteratorlazycmdRegExp.prototype.flagsiamutilprunebrowserlistdirswfdescriptorcallbindwritablefull-widthtrimRightMicrosoftstoragegatewaysesfunctionalES7ES6enderformsInt32Arraylookincludespromisestypeofprefixvalidatetyped arraystylesstdlibbrowserasyncvpcbytechineseObject.definePropertytouchstartertelephonehttptakespinnerses5gesturesieutilitiesWeakMapcurllogparserremovecreateyamlrobustoptionrequireObject.assignredirectIteratorserializerxdgcircularpromisexhrArray.prototype.flateditorfileglobalsUint32Arraysomeviewfigletawsemojilinkmodulesgetintrinsicstyled-componentsenvironmentstrimEndairbnbfolderslotdotenvamazonfullwidthhardlinkseslintspringentriesBigInt64ArrayESnextquerytypepositiveSettypedarrayparentdefaultunicodesymlinks[[Prototype]]a11yform-validationfast-deep-copygetbundlingInt8Arrayi18nnegative zerostringprotocol-buffersparseES2021commanderwalkingregexString.prototype.matchAllArray.prototype.flattenwrapcachepackage managerYAMLargparsereact-testing-library@@toStringTagpackagessearchBigUint64ArraygettervariablesArray.prototype.flatMapfindupsnsgdprcall-boundsimpledbconsumeboundmapmkdirpfindLastIndextestjestmime-dbsideapollopopmotioneveryrequesttextdeepcopystylingeslintpluginserializevalidationFloat32ArraywalkjsonupweaksetflagspluginaccessorequalityfunctiontypescjkArray.prototype.includeseslintconfigtc39jsdomeventDispatcherECMAScript 2018convertthreecolorsjswaapistyleefficienttypedespreeregular expressionpostcss-pluginTypeScriptescapeloadbalancingstringifytrimStartcollectionRegExp#flagsECMAScript 2020guidio-tsfetchnamesESfastclonediffcss-in-jsphoneexecvalidjQueryparentstapvaluepatchdroptypesafeexpressshrinkwrapredux-toolkitdeep-copygraphqlproxyreact-hook-formES2015argvlastloadingrapidreactnodecoercibleavarmdircallbackroutingbyteLengthkoreaneslint-pluginwidthurlec2numbertoobjectlockfileminimales2017loggerstartduplexasciithroatequalprototypeframeworkStreamsJSONfindLastflattenlaunchoptimizerpnpm9vestHyBivaluesinspecteventEmitterhasOwnmulti-packageecmascripthasSymbol.toStringTages2018picomatchoptimisturlsenumerableimportexportagentinferenceesextraschemareact animationES2019persistentes7randombrowserslistparsingkarmaArray.prototype.filterratettyrm -rfnodejsclass-validatorfast-clonenopePromisebuffersreadablecharacterstapeemrinternalappqueueidwafArray.prototype.findLastpackage.jsongroupES2018qsexevarscloudtrailintrinsicfind-upreal-timekeyes6higher-orderjapanesedomTypeBoxl10nfast-copyprivate datacore-jsRFC-6455omitsharedarraybufferwebes8formattingredacthooksenvString.prototype.trimsqssetterdayjslocationerrores-shim APIbindprivate.envinstallcolourargumenttoArrayURLUnderscoreiterationrouteJSON-SchemaArray.prototype.containsES2016columnsmkdirsaccessibilityidentifiersmobilereducerwhichutilityisConcatSpreadablegetOwnPropertyDescriptorworkspace:*symbolformarraysperformanceworkflowexecutableCSSarktypelengthES2022npmwarningfastsharedtoolkitpropertiessymlinkassertionfunction.length-0terminalmodulereusesameValueZeroelasticachewgetreaddom-testing-librarybyteOffsetargumentsUint8ClampedArraytasksetcontainsObservableslanguagees2016globwaitcolumnfilterprotofpsFloat64ArrayshimArrayBuffer#sliceopenponyfillschemeprogressstyleguidedebuggerreduces3mrumake dirECMAScript 2019openerspinnermergetestertypescriptproprmnativebannerelectrontoolsconcatES2023settingsECMAScript 2015recursivechannelawesomesaucergbECMAScript 2023quoteassignmetadataoutputicuhasOwnPropertydragtypanionjavascriptkinesiselbcomputed-typesassertsemitfullautoprefixerECMAScript 2021monorepoReactiveExtensionsdeepmimetypesfs__proto__shellajvdatabufferRxwordwrappostcssArrayrm -frchildObservableshebangconcatMapsliceWeakSetfixed-widthstringifiersyntaxerrortostringtagcopyfromoncemochaperformantdataviewstatelessReflect.getPrototypeOfReactiveXconcurrencystabledependency managerinputstreamajaxObject.keysObject.getPrototypeOfgenericssymbolsWebSocketsinvariantflatMapebsgetPrototypeOfquerystringObject.ismatcheseast-asian-widthvisualawaitArrayBuffer.prototype.slicemakeoffsetdependenciesUint16ArraydataViewhas-ownimmutabletoSortedspeces-abstract
@patrtorg/numquam-doloribus-sit@patrtorg/doloribus-aperiam@patrtorg/dolorum-blanditiis@patrtorg/dolorum-quisquam-molestias@patrtorg/eaque-tempore-temporibus@patrtorg/ducimus-hic@patrtorg/eaque-dolorem-iusto@patrtorg/enim-culpa@patrtorg/enim-quas@patrtorg/est-corrupti@patrtorg/error-expedita-rerum@patrtorg/esse-ut@patrtorg/esse-occaecati-quos@patrtorg/ex-iure@patrtorg/expedita-deleniti-ratione@patrtorg/expedita-eaque-at@patrtorg/fugiat-beatae-quas@patrtorg/fugiat-perspiciatis@patrtorg/fugit-cumque@patrtorg/illo-saepe@patrtorg/hic-facere-ratione@patrtorg/itaque-beatae@patrtorg/iste-sunt@patrtorg/iure-at@patrtorg/labore-nemo-impedit@patrtorg/molestiae-nulla-architecto@patrtorg/modi-aut-dolorem@patrtorg/modi-officia-iusto@patrtorg/nihil-at@patrtorg/nihil-vero-ipsa@patrtorg/pariatur-sapiente@patrtorg/quia-laborum-porro@patrtorg/qui-dolore@patrtorg/quidem-dolore@patrtorg/qui-omnis-voluptates@patrtorg/similique-nam@patrtorg/sed-laudantium-nemo@patrtorg/sapiente-sed-eius@patrtorg/sed-veritatis-placeat@patrtorg/soluta-quo@patrtorg/nisi-perferendis@patrtorg/perspiciatis-possimus@patrtorg/quo-cupiditate-sit@patrtorg/saepe-tenetur-iusto@patrtorg/repellendus-ex@patrtorg/repudiandae-dolore@patrtorg/repellat-quam@patrtorg/tempora-quas@patrtorg/tempore-cumque@patrtorg/vero-quibusdam-ipsa@patrtorg/maiores-adipisci-maxime@patrtorg/nostrum-beatae-a@patrtorg/nobis-assumenda-optio@patrtorg/nobis-nobis@patrtorg/quas-sed-id@patrtorg/reiciendis-doloribus-officia@patrtorg/soluta-numquam@patrtorg/soluta-et@patrtorg/neque-consectetur@patrtorg/neque-voluptatem@patrtorg/odit-facere@patrtorg/officiis-qui@patrtorg/odio-ratione@patrtorg/officiis-dolorum@patrtorg/quos-hic@patrtorg/similique-vero-sapiente@patrtorg/sit-ipsam-dolore@patrtorg/suscipit-sit-culpa@patrtorg/tempora-impedit-dolore@patrtorg/porro-voluptates@patrtorg/quod-asperiores@patrtorg/tenetur-aut@patrtorg/tempore-labore-mollitia@patrtorg/totam-accusamus@patrtorg/veritatis-vel-amet@patrtorg/veritatis-ad-voluptates@patrtorg/occaecati-reiciendis-reiciendis@patrtorg/pariatur-repellendus-aspernatur@patrtorg/quo-in@patrtorg/sunt-distinctio-illo@patrtorg/sunt-asperiores@patrtorg/ullam-eum@patrtorg/ullam-doloremque@patrtorg/unde-cupiditate@patrtorg/animi-laboriosam-adipisci@patrtorg/aperiam-quaerat@patrtorg/aspernatur-assumenda@patrtorg/architecto-laudantium@patrtorg/aspernatur-repellendus-assumenda@patrtorg/assumenda-officia@patrtorg/assumenda-qui@patrtorg/assumenda-ipsam@patrtorg/aspernatur-laborum@patrtorg/at-sunt-itaque@patrtorg/commodi-illo@patrtorg/beatae-quas@patrtorg/blanditiis-ea-quaerat@patrtorg/blanditiis-quibusdam-sit@patrtorg/consectetur-odio-placeat@patrtorg/consequatur-distinctio
5.14.126

12 months ago

5.14.125

12 months ago

5.14.124

1 year ago

4.14.115

1 year ago

4.14.114

1 year ago

5.14.123

1 year ago

5.14.122

1 year ago

5.14.121

1 year ago

5.14.120

1 year ago

5.14.115

1 year ago

5.14.119

1 year ago

5.14.118

1 year ago

5.14.117

1 year ago

5.14.116

1 year ago

4.13.112

1 year ago

4.13.111

1 year ago

4.14.112

1 year ago

4.14.113

1 year ago

4.12.110

1 year ago

4.12.111

1 year ago

4.11.107

1 year ago

4.12.107

1 year ago

4.12.108

1 year ago

4.12.109

1 year ago

4.11.106

1 year ago

4.11.105

1 year ago

4.11.104

1 year ago

4.11.103

1 year ago

4.11.101

1 year ago

4.11.102

1 year ago

4.11.100

1 year ago

4.11.99

1 year ago

4.10.89

1 year ago

1.4.20

1 year ago

1.4.21

1 year ago

2.5.40

1 year ago

2.5.41

1 year ago

2.5.42

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

3.8.69

1 year ago

3.8.67

1 year ago

3.8.68

1 year ago

3.8.65

1 year ago

3.8.66

1 year ago

3.8.63

1 year ago

3.8.64

1 year ago

3.8.61

1 year ago

3.8.62

1 year ago

3.8.74

1 year ago

3.6.51

1 year ago

3.8.75

1 year ago

3.6.50

1 year ago

3.8.72

1 year ago

1.4.15

1 year ago

3.8.73

1 year ago

3.8.70

1 year ago

1.4.17

1 year ago

3.8.71

1 year ago

1.4.16

1 year ago

1.4.19

1 year ago

1.4.18

1 year ago

4.11.98

1 year ago

4.11.97

1 year ago

4.11.96

1 year ago

4.11.95

1 year ago

1.5.30

1 year ago

1.5.32

1 year ago

1.5.31

1 year ago

1.5.34

1 year ago

1.5.33

1 year ago

4.11.90

1 year ago

3.5.50

1 year ago

1.5.36

1 year ago

1.5.35

1 year ago

1.5.38

1 year ago

1.5.37

1 year ago

4.11.94

1 year ago

4.11.93

1 year ago

4.11.92

1 year ago

1.3.15

1 year ago

4.11.91

1 year ago

3.7.59

1 year ago

3.7.57

1 year ago

3.7.58

1 year ago

3.9.79

1 year ago

3.7.55

1 year ago

3.7.56

1 year ago

3.9.77

1 year ago

3.7.53

1 year ago

3.9.78

1 year ago

3.7.54

1 year ago

3.9.75

1 year ago

3.7.51

1 year ago

3.9.76

1 year ago

3.7.52

1 year ago

3.5.47

1 year ago

3.5.46

1 year ago

3.5.45

1 year ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

4.9.84

1 year ago

4.9.86

1 year ago

4.9.85

1 year ago

4.9.88

1 year ago

3.5.49

1 year ago

4.9.87

1 year ago

3.5.48

1 year ago

4.9.89

1 year ago

1.5.21

1 year ago

2.5.38

1 year ago

1.5.23

1 year ago

2.5.39

1 year ago

1.5.22

1 year ago

4.10.90

1 year ago

1.5.25

1 year ago

1.5.24

1 year ago

3.9.84

1 year ago

3.7.60

1 year ago

1.5.27

1 year ago

3.7.61

1 year ago

1.5.26

1 year ago

3.9.82

1 year ago

1.5.29

1 year ago

3.9.83

1 year ago

1.5.28

1 year ago

3.9.80

1 year ago

3.9.81

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.10

1 year ago

1.1.10

1 year ago

1.2.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago