7.9.125 • Published 11 months ago

@diotoborg/et-facere-iusto v7.9.125

Weekly downloads
-
License
MIT
Repository
github
Last release
11 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 @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
7.9.124

11 months ago

7.9.125

11 months ago

5.6.95

1 year ago

4.5.77

1 year ago

4.5.78

1 year ago

4.5.79

1 year ago

3.4.58

1 year ago

3.2.35

1 year ago

3.4.59

1 year ago

3.2.34

1 year ago

3.2.37

1 year ago

3.2.36

1 year ago

3.2.39

1 year ago

3.2.38

1 year ago

3.4.56

1 year ago

3.4.57

1 year ago

2.1.16

1 year ago

2.1.17

1 year ago

7.6.107

12 months ago

2.1.14

1 year ago

7.6.106

12 months ago

2.1.15

1 year ago

2.1.12

1 year ago

2.1.13

1 year ago

2.1.10

1 year ago

2.1.11

1 year ago

7.6.101

1 year ago

7.6.105

12 months ago

7.6.104

12 months ago

7.6.103

12 months ago

7.6.102

1 year ago

4.5.90

1 year ago

3.3.52

1 year ago

3.3.53

1 year ago

3.3.54

1 year ago

3.3.55

1 year ago

2.1.18

1 year ago

3.3.56

1 year ago

2.1.19

1 year ago

2.1.27

1 year ago

2.1.28

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.1.23

1 year ago

2.1.24

1 year ago

2.1.21

1 year ago

7.9.123

11 months ago

2.1.22

1 year ago

2.1.20

1 year ago

6.6.100

1 year ago

6.6.101

1 year ago

7.7.123

11 months ago

4.5.80

1 year ago

7.7.120

12 months ago

4.5.83

1 year ago

4.5.84

1 year ago

7.7.122

11 months ago

4.5.81

1 year ago

2.1.29

1 year ago

7.7.121

12 months ago

4.5.82

1 year ago

4.5.87

1 year ago

4.5.88

1 year ago

4.5.85

1 year ago

4.5.86

1 year ago

2.1.34

1 year ago

4.5.89

1 year ago

2.1.32

1 year ago

2.1.33

1 year ago

2.1.30

1 year ago

2.1.31

1 year ago

7.7.117

12 months ago

7.7.116

12 months ago

7.7.119

12 months ago

7.7.118

12 months ago

7.7.113

12 months ago

7.7.112

12 months ago

7.7.115

12 months ago

7.7.114

12 months ago

7.7.111

12 months ago

7.7.110

12 months ago

4.4.69

1 year ago

4.4.68

1 year ago

4.4.67

1 year ago

4.4.66

1 year ago

7.7.109

12 months ago

7.7.108

12 months ago

7.7.107

12 months ago

6.6.99

1 year ago

6.6.95

1 year ago

6.6.96

1 year ago

6.6.97

1 year ago

6.6.98

1 year ago

3.2.46

1 year ago

3.2.45

1 year ago

3.2.48

1 year ago

3.2.47

1 year ago

3.2.49

1 year ago

3.4.61

1 year ago

3.4.62

1 year ago

3.4.63

1 year ago

3.2.40

1 year ago

3.4.64

1 year ago

3.4.65

1 year ago

3.2.42

1 year ago

3.4.66

1 year ago

3.2.41

1 year ago

3.2.44

1 year ago

3.2.43

1 year ago

3.4.60

1 year ago

2.2.34

1 year ago

7.8.123

11 months ago

4.6.91

1 year ago

4.6.92

1 year ago

3.2.51

1 year ago

4.6.90

1 year ago

3.2.50

1 year ago

4.6.95

1 year ago

4.4.72

1 year ago

4.4.71

1 year ago

3.2.52

1 year ago

4.6.93

1 year ago

4.4.70

1 year ago

4.6.94

1 year ago

4.4.76

1 year ago

4.4.75

1 year ago

4.4.74

1 year ago

4.4.73

1 year ago

4.4.77

1 year ago

2.1.9

1 year ago

2.0.9

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