parse-domain 2.3.0 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +2 -2
- package/build/tries/icann.complete.json +1 -1
- package/build/tries/icann.light.json +1 -1
- package/build/tries/meta.json +1 -0
- package/build/tries/private.complete.json +1 -1
- package/build/tries/private.json +1 -0
- package/lib/parseDomain.js +18 -36
- package/lib/trie/characters.js +16 -0
- package/lib/trie/lookUp.js +33 -0
- package/lib/trie/nodes.js +40 -0
- package/lib/trie/parse.js +64 -0
- package/lib/{tries → trie}/parsePubSuffixList.js +0 -0
- package/lib/{tries → trie}/serializeTrie.js +6 -6
- package/lists/icann.complete.js +2 -2
- package/lists/icann.light.js +2 -2
- package/lists/private.complete.js +2 -2
- package/package.json +6 -7
- package/scripts/build-tries.js +15 -7
- package/src/index.d.ts +18 -0
- package/test/parseDomain.test.js +214 -90
- package/test/snapshots.test.js +6 -29
- package/test/trie/lookUp.test.js +96 -0
- package/test/trie/nodes.test.js +24 -0
- package/test/trie/parse.test.js +140 -0
- package/test/trie/parsePubSuffixList.test.js +130 -0
- package/test/{tries → trie}/serializeTrie.test.js +20 -14
- package/lib/tries/lookUp.js +0 -40
- package/lib/tries/parseTrie.js +0 -62
- package/lib/tries/separators.js +0 -12
- package/test/mocha.opts +0 -1
- package/test/tries/lookUp.test.js +0 -116
- package/test/tries/parsePubSuffixList.test.js +0 -129
- package/test/tries/parseTrie.test.js +0 -162
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"ua>cc,inf,ltd,biz,co,pp<pl>beep,krasnik,leczna,lubartow,lublin,poniatowa,swidnik,co,art,gliwice,krakow,poznan,wroc,zakopane,gda,gdansk,gdynia,med,sopot<ca>barsy,awdev>*<co,blogspot,no-ip<estate>compute>*<<network>alces>*<co,arvo,azimuth<net>alwaysdata,cloudfront,t3l3p0rt,go-vip,myfritz,blackbaudcdn,boomla,bplaced,square7,gb,hu,jp,se,uk,in,cloudaccess,cdn77-ssl,cdn77>r<cloudeity,feste-ip,knx-server,static-access,cryptonomic>*<dattolocal,mydatto,debian,at-band-camp,blogdns,broke-it,buyshouses,dnsalias,dnsdojo,does-it,dontexist,dynalias,dynathome,endofinternet,from-az,from-co,from-la,from-ny,gets-it,ham-radio-op,homeftp,homeip,homelinux,homeunix,in-the-band,is-a-chef,is-a-geek,isa-geek,kicks-ass,office-on-the,podzone,scrapper-site,selfip,sells-it,servebbs,serveftp,thruhere,webhop,definima,casacam,dynu,dynv6,twmail,ru,channelsdvr,fastlylb>map<fastly>freetls,map,prod>a,global<ssl>a,b,global<<flynnhosting,cloudfunctions,moonscale,in-dsl,in-vpn,ipifony,iobb,kinghost,uni5,barsy,memset,azurewebsites,azure-mobile,cloudapp,dnsup,hicam,now-dns,ownip,vpndns,eating-organic,mydissent,myeffect,mymediapc,mypsx,mysecuritycamera,nhlfan,no-ip,pgafan,privatizehealthinsurance,bounceme,ddns,redirectme,serveblog,serveminecraft,sytes,cloudycluster,rackmaze,schokokeks,firewall-gateway,siteleaf,srcf>soc,user<dsmynas,familyds,yandexcloud>storage,website<za<com>amazonaws>compute>*<compute-1>*<us-east-1>dualstack>s3<<elb>*<s3,s3-ap-northeast-1,s3-ap-northeast-2,s3-ap-south-1,s3-ap-southeast-1,s3-ap-southeast-2,s3-ca-central-1,s3-eu-central-1,s3-eu-west-1,s3-eu-west-2,s3-eu-west-3,s3-external-1,s3-fips-us-gov-west-1,s3-sa-east-1,s3-us-gov-west-1,s3-us-east-2,s3-us-west-1,s3-us-west-2,ap-northeast-2>s3,dualstack>s3<s3-website<ap-south-1>s3,dualstack>s3<s3-website<ca-central-1>s3,dualstack>s3<s3-website<eu-central-1>s3,dualstack>s3<s3-website<eu-west-2>s3,dualstack>s3<s3-website<eu-west-3>s3,dualstack>s3<s3-website<us-east-2>s3,dualstack>s3<s3-website<ap-northeast-1>dualstack>s3<<ap-southeast-1>dualstack>s3<<ap-southeast-2>dualstack>s3<<eu-west-1>dualstack>s3<<sa-east-1>dualstack>s3<<s3-website-us-east-1,s3-website-us-west-1,s3-website-us-west-2,s3-website-ap-northeast-1,s3-website-ap-southeast-1,s3-website-ap-southeast-2,s3-website-eu-west-1,s3-website-sa-east-1<elasticbeanstalk>ap-northeast-1,ap-northeast-2,ap-northeast-3,ap-south-1,ap-southeast-1,ap-southeast-2,ca-central-1,eu-central-1,eu-west-1,eu-west-2,eu-west-3,sa-east-1,us-east-1,us-east-2,us-gov-west-1,us-west-1,us-west-2<on-aptible,myasustor,wpcomstaging,balena-devices,betainabox,bplaced,ar,br,cn,de,eu,gb,hu,jpn,kr,mex,no,qc,ru,sa,uk,us,uy,za,africa,gr,co,xenapponazure,jdevcloud,wpdevcloud,cloudcontrolled,cloudcontrolapp,trycloudflare,dattolocal,dattorelay,dattoweb,mydatto,drayddns,dreamhosters,mydrobo,dyndns-at-home,dyndns-at-work,dyndns-blog,dyndns-free,dyndns-home,dyndns-ip,dyndns-mail,dyndns-office,dyndns-pics,dyndns-remote,dyndns-server,dyndns-web,dyndns-wiki,dyndns-work,blogdns,cechire,dnsalias,dnsdojo,doesntexist,dontexist,doomdns,dyn-o-saur,dynalias,est-a-la-maison,est-a-la-masion,est-le-patron,est-mon-blogueur,from-ak,from-al,from-ar,from-ca,from-ct,from-dc,from-de,from-fl,from-ga,from-hi,from-ia,from-id,from-il,from-in,from-ks,from-ky,from-ma,from-md,from-mi,from-mn,from-mo,from-ms,from-mt,from-nc,from-nd,from-ne,from-nh,from-nj,from-nm,from-nv,from-oh,from-ok,from-or,from-pa,from-pr,from-ri,from-sc,from-sd,from-tn,from-tx,from-ut,from-va,from-vt,from-wa,from-wi,from-wv,from-wy,getmyip,gotdns,hobby-site,homelinux,homeunix,iamallama,is-a-anarchist,is-a-blogger,is-a-bookkeeper,is-a-bulls-fan,is-a-caterer,is-a-chef,is-a-conservative,is-a-cpa,is-a-cubicle-slave,is-a-democrat,is-a-designer,is-a-doctor,is-a-financialadvisor,is-a-geek,is-a-green,is-a-guru,is-a-hard-worker,is-a-hunter,is-a-landscaper,is-a-lawyer,is-a-liberal,is-a-libertarian,is-a-llama,is-a-musician,is-a-nascarfan,is-a-nurse,is-a-painter,is-a-personaltrainer,is-a-photographer,is-a-player,is-a-republican,is-a-rockstar,is-a-socialist,is-a-student,is-a-teacher,is-a-techie,is-a-therapist,is-an-accountant,is-an-actor,is-an-actress,is-an-anarchist,is-an-artist,is-an-engineer,is-an-entertainer,is-certified,is-gone,is-into-anime,is-into-cars,is-into-cartoons,is-into-games,is-leet,is-not-certified,is-slick,is-uberleet,is-with-theband,isa-geek,isa-hockeynut,issmarterthanyou,likes-pie,likescandy,neat-url,saves-the-whales,selfip,sells-for-less,sells-for-u,servebbs,simple-url,space-to-rent,teaches-yoga,writesthisblog,ddnsfree,ddnsgeek,giize,gleeze,kozow,loseyourip,ooguy,theworkpc,mytuleap,evennode>eu-1,eu-2,eu-3,eu-4,us-1,us-2,us-3,us-4<fbsbx>apps<fastly-terrarium,fastvps-server,mydobiss,firebaseapp,flynnhub,freebox-os,freeboxos,githubusercontent,0emm>*<appspot,blogspot,codespot,googleapis,googlecode,pagespeedmobilizer,publishproxy,withgoogle,withyoutube,herokuapp,herokussl,myravendb,pixolino,joyent>cns>*<<lpusercontent,lmpm>app<linode>members,nodebalancer<barsycenter,barsyonline,miniserver,meteorapp>eu<bitballoon,netlify,4u,nfshost,001www,ddnslive,myiphost,blogsyte,ciscofreak,damnserver,ditchyourip,dnsiskinky,dynns,geekgalaxy,health-carereform,homesecuritymac,homesecuritypc,myactivedirectory,mysecuritycamera,net-freaks,onthewifi,point2this,quicksytes,securitytactics,serveexchange,servehumour,servep2p,servesarcasm,stufftoread,unusualperson,workisboring,3utilities,ddnsking,myvnc,servebeer,servecounterstrike,serveftp,servegame,servehalflife,servehttp,serveirc,servemp3,servepics,servequake,operaunite,outsystemscloud,ownprovider,pgfog,pagefrontapp,gotpantheon,prgmr>xen<qualifioapp,qa2,dev-myqnapcloud,alpha-myqnapcloud,myqnapcloud,quipelements>*<rackmaze,rhcloud,render>app<onrender,logoip,scrysec,firewall-gateway,myshopblocks,shopitsite,1kapp,appchizi,applinzi,sinaapp,vipsinaapp,bounty-full>alpha,beta<stackhero-network,stdlib>api<temp-dns,dsmynas,familyds,thingdustdata,bloxcms,townnews-staging,hk,wafflecell,remotewd,xnbay>u2,u2-local<yolasite<cn>com>amazonaws>compute>*<eb>cn-north-1,cn-northwest-1<elb>*<cn-north-1>s3<<<instantcloud<org>amune>tele<pimienta,poivron,potager,sweetpepper,ae,us,certmgr,cdn77>c,rsc<cdn77-secure>origin>ssl<<cloudns,duckdns,tunk,dyndns>go,home<blogdns,blogsite,boldlygoingnowhere,dnsalias,dnsdojo,doesntexist,dontexist,doomdns,dvrdns,dynalias,endofinternet,endoftheinternet,from-me,game-host,gotdns,hobby-site,homedns,homeftp,homelinux,homeunix,is-a-bruinsfan,is-a-candidate,is-a-celticsfan,is-a-chef,is-a-geek,is-a-knight,is-a-linux-user,is-a-patsfan,is-a-soxfan,is-found,is-lost,is-saved,is-very-bad,is-very-evil,is-very-good,is-very-nice,is-very-sweet,isa-geek,kicks-ass,misconfused,podzone,readmyblog,selfip,sellsyourhome,servebbs,serveftp,servegame,stuff-4-sale,webhop,ddnss,accesscam,camdvr,freeddns,mywire,webredirect,eu>al,asso,at,au,be,bg,ca,cd,ch,cn,cy,cz,de,dk,edu,ee,es,fi,fr,gr,hr,hu,ie,il,in,int,is,it,jp,kr,lt,lu,lv,mc,me,mk,mt,my,net,ng,nl,no,nz,paris,pl,pt,q-a,ro,ru,se,si,sk,tr,uk,us<twmail,fedorainfracloud,fedorapeople,fedoraproject>cloud,os>app<stg>os>app<<<freedesktop,hepforge,in-dsl,in-vpn,js,uklugs,barsy,mayfirst,mozilla-iot,bmoattachments,dynserv,now-dns,cable-modem,collegefan,couchpotatofries,mlbfan,mysecuritycamera,nflfan,read-books,ufcfan,hopto,myftp,no-ip,zapto,pubtls,my-firewall,myfirewall,spdns,dsmynas,familyds,edugit,tuxfamily,diskstation,hk,wmflabs,za<io>apigee,b-data,backplaneapp,banzaicloud>app<boxfuse,browsersafetymark,bigv>uk0<cleverapps,dedyn,drud,definima,enonic>customer<github,gitlab,hasura-app,moonscale>*<loginline,barsy,azurecontainer,ngrok,nodeart>stage<nodum,nid,pantheonsite,dyn53,protonet,vaporcloud,on-rio>*<readthedocs,resindevice,resinstaging>devices<hzc,sandcats,shiftedit,mo-siemens,lair>apps<stolos>*<spacekit,utwente,applicationcloud,scapp,s5y>*<telebit,thingdust>dev>cust<disrec>cust<prod>cust<testing>cust<<2038,wedeploy,basicserver,virtualserver<jp>ne>aseinet>user<gehirn<usercontent,blogspot<vc>gv>d<nom<eus>party>user<<co>go-vip,carrd,crd,otap>*<com>blogspot<leadpages,lpages,mypi,n4t,nodum,repl<ws>advisor>*<cloud66,dyndns,mypets<la>bnr,c,nym<ch>square7,blogspot,linkyard-cloud,dnsking,gotdns,12hp,2ix,4lima,lima-city<de>bplaced,square7,com,cosidns>dyn<dynamisches-dns,dnsupdater,internet-dns,l-o-g-i-n,dnshome,fuettertdasnetz,isteingeek,istmein,lebtimnetz,leitungsen,traeumtgerade,ddnss>dyn,dyndns<dyndns1,dyn-ip24,home-webserver>dyn<myhome-server,goip,blogspot,dyn-berlin,in-berlin,in-brb,in-butter,in-dsl,in-vpn,mein-iserv,test-iserv,keymachine,git-repos,lcube-server,svn-repos,barsy,logoip,firewall-gateway,my-gateway,my-router,spdns,speedpartner>customer<taifun-dns,12hp,2ix,4lima,lima-city,dd-dns,dray-dns,draydns,dyn-vpn,dynvpn,mein-vigor,my-vigor,my-wan,syno-ds,synology-diskstation,synology-ds,uberspace>*<virtualuser,virtual-user<uk>co>bytemark>dh,vm<blogspot,barsy,barsyonline,nh-serv,no-ip,wellbeingzone,gwiddle<gov>service,homeoffice<org>glug,lug,lugs<barsy<eu>mycd,cloudns,barsy,wellbeingzone,spdns,transurl>*<diskstation<ai>uwu,nom<se>com,blogspot,conf<bz>za,nym<group>discourse<nl>virtueeldomein,co,hosting-cluster,blogspot,khplay,transurl>*<cistron,demon<dev>lcl>*<stg>*<workers,iserv,loginline,webhare>*<<me>c66,daplie>localhost<filegear,filegear-au,filegear-de,filegear-gb,filegear-ie,filegear-jp,filegear-sg,glitch,ravendb,barsy,nctu,soundcast,tcp4,brasilia,ddns,dnsfor,hopto,loginto,noip,webhop,nym,diskstation,dscloud,i234,myds,synology,wedeploy,yombo,nohost<zone>cloud66,hs,triton>*<lima<host>cloudaccess,freesite,pcloud,half<site>cloudera,cyon,lelux,loginline,barsy,platformsh>*<byen<app>wnext,run>a<web,hasura,loginline,telebit<cz>co,realm,e4,blogspot,metacentrum>cloud,custom<muni>cloud>flt,usr<<<asia>cloudns<biz>cloudns,dyndns,for-better,for-more,for-some,for-the,selfip,webhop,bpl,orx,mmafan,myftp,no-ip,dscloud<club>cloudns,barsy,pony<cc>cloudns,ftpaccess,game-server,myphotos,scrapping,twmail,fantasyleague<in>cloudns,blogspot,barsy<info>cloudns,dynamic-dns,dyndns,barrel-of-knowledge,barrell-of-knowledge,for-our,groks-the,groks-this,here-for-more,knowsitall,selfip,webhop,barsy,mayfirst,forumz,nsupdate,dvrcam,ilovecollege,no-ip,v-info<pro>cloudns,dnstrace>bci<barsy<pw>cloudns,x443,nom<us>cloudns,drud,is-by,land-4-sale,stuff-4-sale,freeddns,golffan,noip,pointto,de>lib<<gdn>cnpy<no>co,blogspot<be>webhosting,blogspot,transurl>*<<is>cupcake,blogspot<link>cyon,mypep,dweb>*<<dk>biz,co,firm,reg,store,blogspot<earth>dapps>*,bzz>*<<<th>online,shop<fi>dy,blogspot,häkkinen,iki<tv>dyndns,better-than,on-the-web,worse-than<cx>ath,info<name>her>forgot<his>forgot<<nu>merseine,mine,shacknet,nom,builder>site<enterprisecloud<rocks>myddns,lima-city,webspace<xyz>blogsite,fhapp,crafting,zapto,telebit>*<<one>onred>staging<for,homelink<tw>com>mymailer<url,blogspot,nym<ru>adygeya,bashkiria,bir,cbg,com,dagestan,grozny,kalmykia,kustanai,marine,mordovia,msk,mytis,nalchik,nov,pyatigorsk,spb,vladikavkaz,vladimir,blogspot,myjino>hosting>*<landing>*<spectrum>*<vps>*<<cldmail>hb<net,org,pp,ras<su>abkhazia,adygeya,aktyubinsk,arkhangelsk,armenia,ashgabad,azerbaijan,balashov,bashkiria,bryansk,bukhara,chimkent,dagestan,east-kazakhstan,exnet,georgia,grozny,ivanovo,jambyl,kalmykia,kaluga,karacol,karaganda,karelia,khakassia,krasnodar,kurgan,kustanai,lenug,mangyshlak,mordovia,msk,murmansk,nalchik,navoi,north-kazakhstan,nov,obninsk,penza,pokrovsk,sochi,spb,tashkent,termez,togliatti,troitsk,tselinograd,tula,tuva,vladikavkaz,vladimir,vologda,nym<direct>fastpanel<fr>fbx-os,fbxos,freebox-os,freeboxos,blogspot,on-web,chirurgiens-dentistes-en-france<at>futurecms>*,ex>*<in>*<<futurehosting,futuremailing,ortsinfo>ex>*<kunden>*<<co>blogspot<biz,info,priv,12hp,2ix,4lima,lima-city<cloud>statics>*<linkyard,magentosite>*<vapor,on-rancher>*<sensiosite>*<trafficplex,voorloper<ms>lab<digital>cloudapps>london<<im>ro,nom<ro>shop,blogspot,nym<ae>blogspot,nom<al>blogspot,nom<am>blogspot<ba>blogspot<bg>blogspot,barsy<bj>blogspot<cf>blogspot<cl>blogspot,nom<id>co>blogspot<zone<il>co>blogspot<<ke>co>blogspot<nom<nz>co>blogspot<nym<za>co>blogspot<<ar>com>blogspot<<au>com>blogspot<<br>com>blogspot<leg>ac,al,am,ap,ba,ce,df,es,go,ma,mg,ms,mt,pa,pb,pe,pi,pr,rj,rn,ro,rr,rs,sc,se,sp,to<<by>com>blogspot<nym<cy>com>blogspot<<ee>com>blogspot<<eg>com>blogspot<<es>com>blogspot<<mt>com>blogspot<<ng>com>blogspot<col,firm,gen,ltd<tr>com>blogspot<<uy>com>blogspot<nom<cv>blogspot<gr>blogspot,nym<hk>blogspot,nym,ltd,inc<hr>blogspot,free<hu>blogspot<ie>blogspot,nym<it>blogspot,16-b,32-b,64-b,syncloud<kr>blogspot<li>blogspot,caa,nom,nym<lt>blogspot,nym<lu>blogspot,nym<md>blogspot<mk>blogspot,nom<mr>blogspot<mx>blogspot,nym<my>blogspot<pe>blogspot,nym<pt>blogspot,nym<qa>blogspot,nom<re>blogspot<rs>blogspot,ua,nom,ox<sg>blogspot<si>blogspot,nom<sk>blogspot,nym<sn>blogspot<td>blogspot<ug>blogspot,nom<vn>blogspot<goog>cloud<ci>fin<run>hs,development,ravendb,repl<sh>hashbang,platform>*<wedeploy,now<community>ravendb<city>ng<gl>biz,nom<ink>ng<school>ng<so>sch<gg>kaas,cya<systems>knightpoint<krd>co,edu<business>co<education>co<events>co<financial>co<place>co<technology>co<space>linkitools,uber,xs4all<bs>we<services>loginline<menu>barsy<mobi>barsy,dscloud<online>barsy<pub>barsy<shop>barsy<support>barsy<casa>nabu>ui<<fashion>of,on<football>of<london>in,of<men>for<mom>and,for<sale>for<work>of,to<top>now-dns,ntdll<ovh>nerdpol<mn>nyc,nym<af>nom<ec>nym<gd>nom<ge>nom<gt>nom<gy>nym<hn>nom<kz>nym<lc>nym,oy<st>nom,noho<sx>nym<tj>nom<vg>nom<hosting>opencraft<pm>own<bn>co<page>prvcy<fit>ptplus<edu>rit>git-pages<<land>static>dev,sites<<farm>storj<to>vpnplus<cool>de<pictures>1337<rip>clan<management>router<academy>official<faith>ybo<party>ybo<review>ybo<science>ybo<trade>ybo<design>bss"
|
package/lib/parseDomain.js
CHANGED
|
@@ -6,53 +6,35 @@ var privateTrie = require("../lists/private.complete");
|
|
|
6
6
|
|
|
7
7
|
var normalize = require("./normalize.js");
|
|
8
8
|
|
|
9
|
-
var lookUp = require("./
|
|
9
|
+
var lookUp = require("./trie/lookUp"); // eslint-disable-next-line
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var urlParts = /^(:?\/\/|https?:\/\/)?([^/]*@)?(.+?)(:\d{2,5})?([/?].*)?$/; // 1 = protocol, 2 = auth, 3 =
|
|
12
|
+
var urlParts = /^(:?\/\/|https?:\/\/)?([^/]*@)?(.+?)(:\d{2,5})?([/?].*)?$/; // 1 = protocol, 2 = auth, 3 = hostname, 4 = port, 5 = path
|
|
13
13
|
|
|
14
14
|
var dot = /\./g;
|
|
15
15
|
var emptyArr = [];
|
|
16
16
|
|
|
17
|
-
function matchTld(
|
|
17
|
+
function matchTld(hostname, options) {
|
|
18
18
|
// for potentially unrecognized tlds, try matching against custom tlds
|
|
19
19
|
if (options.customTlds) {
|
|
20
20
|
// try matching against a built regexp of custom tlds
|
|
21
|
-
var tld =
|
|
21
|
+
var tld = hostname.match(options.customTlds);
|
|
22
22
|
|
|
23
23
|
if (tld !== null) {
|
|
24
24
|
return tld[0];
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var _iteratorError = undefined;
|
|
28
|
+
var domains = hostname.split(".");
|
|
29
|
+
var icannTlds = lookUp(icannTrie, domains);
|
|
30
|
+
var privateTlds = options.privateTlds ? lookUp(privateTrie, domains) : emptyArr;
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var _tld = lookUp(trie, domain);
|
|
32
|
+
if (privateTlds.length > icannTlds.length) {
|
|
33
|
+
return "." + privateTlds.join(".");
|
|
34
|
+
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} catch (err) {
|
|
44
|
-
_didIteratorError = true;
|
|
45
|
-
_iteratorError = err;
|
|
46
|
-
} finally {
|
|
47
|
-
try {
|
|
48
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
49
|
-
_iterator["return"]();
|
|
50
|
-
}
|
|
51
|
-
} finally {
|
|
52
|
-
if (_didIteratorError) {
|
|
53
|
-
throw _iteratorError;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
36
|
+
if (icannTlds.length > 0) {
|
|
37
|
+
return "." + icannTlds.join(".");
|
|
56
38
|
}
|
|
57
39
|
|
|
58
40
|
return null;
|
|
@@ -80,7 +62,7 @@ function parseDomain(url, options) {
|
|
|
80
62
|
var normalizedUrl = normalize.url(url);
|
|
81
63
|
var tld = null;
|
|
82
64
|
var urlSplit;
|
|
83
|
-
var
|
|
65
|
+
var hostname;
|
|
84
66
|
|
|
85
67
|
if (!normalizedUrl) {
|
|
86
68
|
return null;
|
|
@@ -93,27 +75,27 @@ function parseDomain(url, options) {
|
|
|
93
75
|
return null;
|
|
94
76
|
}
|
|
95
77
|
|
|
96
|
-
|
|
78
|
+
hostname = urlSplit[3]; // domain will now be something like sub.domain.example.com
|
|
97
79
|
|
|
98
|
-
tld = matchTld(
|
|
80
|
+
tld = matchTld(hostname, normalizedOptions);
|
|
99
81
|
|
|
100
82
|
if (tld === null) {
|
|
101
83
|
return null;
|
|
102
84
|
} // remove tld and split by dot
|
|
103
85
|
|
|
104
86
|
|
|
105
|
-
urlSplit =
|
|
87
|
+
urlSplit = hostname.slice(0, -tld.length).split(dot);
|
|
106
88
|
|
|
107
89
|
if (tld.charAt(0) === ".") {
|
|
108
90
|
// removes the remaining dot, if present (added to handle localhost)
|
|
109
91
|
tld = tld.slice(1);
|
|
110
92
|
}
|
|
111
93
|
|
|
112
|
-
|
|
94
|
+
hostname = urlSplit.pop();
|
|
113
95
|
var subdomain = urlSplit.join(".");
|
|
114
96
|
return {
|
|
115
97
|
tld: tld,
|
|
116
|
-
domain:
|
|
98
|
+
domain: hostname,
|
|
117
99
|
subdomain: subdomain
|
|
118
100
|
};
|
|
119
101
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
UP: "<",
|
|
5
|
+
// one level up
|
|
6
|
+
SAME: ",",
|
|
7
|
+
// same level
|
|
8
|
+
DOWN: ">",
|
|
9
|
+
// one level down
|
|
10
|
+
RESET: "|",
|
|
11
|
+
// reset level index and start new
|
|
12
|
+
WILDCARD: "*",
|
|
13
|
+
// as defined by publicsuffix.org
|
|
14
|
+
EXCEPTION: "!" // as defined by publicsuffix.org
|
|
15
|
+
|
|
16
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var characters = require("./characters.js");
|
|
4
|
+
|
|
5
|
+
function lookUp(trie, domains) {
|
|
6
|
+
var domainsToCheck = domains.slice();
|
|
7
|
+
var topLevel = [];
|
|
8
|
+
var node = trie;
|
|
9
|
+
|
|
10
|
+
while (domainsToCheck.length) {
|
|
11
|
+
var domain = domainsToCheck.pop();
|
|
12
|
+
|
|
13
|
+
if (node.children.has(characters.WILDCARD)) {
|
|
14
|
+
if (node.children.has(characters.EXCEPTION + domain)) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
node = node.children.get(characters.WILDCARD);
|
|
19
|
+
} else {
|
|
20
|
+
if (node.children.has(domain) === false) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
node = node.children.get(domain);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
topLevel.unshift(domain);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return topLevel;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = lookUp;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function createNode() {
|
|
4
|
+
var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
5
|
+
return {
|
|
6
|
+
domain: domain,
|
|
7
|
+
children: new Map(),
|
|
8
|
+
parent: null
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function createOrGetChild(parent, domain) {
|
|
13
|
+
var child = parent.children.get(domain);
|
|
14
|
+
|
|
15
|
+
if (child === undefined) {
|
|
16
|
+
child = createNode(domain);
|
|
17
|
+
adoptChild(parent, child);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return child;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function adoptChild(parent, child) {
|
|
24
|
+
if (typeof child.domain !== "string") {
|
|
25
|
+
throw new Error("Cannot adopt child: child.domain must be a string");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (parent.children.has(child.domain)) {
|
|
29
|
+
throw new Error("Cannot adopt child: parent has already a child with the domain '".concat(child.domain, "'"));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
parent.children.set(child.domain, child);
|
|
33
|
+
child.parent = parent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
createNode: createNode,
|
|
38
|
+
createOrGetChild: createOrGetChild,
|
|
39
|
+
adoptChild: adoptChild
|
|
40
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var characters = require("./characters");
|
|
4
|
+
|
|
5
|
+
var _require = require("./nodes"),
|
|
6
|
+
createNode = _require.createNode,
|
|
7
|
+
createOrGetChild = _require.createOrGetChild; // Parsing is complex... :)
|
|
8
|
+
// eslint-disable-next-line complexity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function parse(serialized) {
|
|
12
|
+
var rootNode = createNode();
|
|
13
|
+
var domain = "";
|
|
14
|
+
var parentNode = rootNode;
|
|
15
|
+
var node;
|
|
16
|
+
|
|
17
|
+
function addDomain() {
|
|
18
|
+
node = createOrGetChild(parentNode, domain);
|
|
19
|
+
domain = "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (var i = 0; i < serialized.length; i++) {
|
|
23
|
+
var _char = serialized.charAt(i);
|
|
24
|
+
|
|
25
|
+
switch (_char) {
|
|
26
|
+
case characters.SAME:
|
|
27
|
+
{
|
|
28
|
+
addDomain();
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
case characters.DOWN:
|
|
33
|
+
{
|
|
34
|
+
addDomain();
|
|
35
|
+
parentNode = node;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
case characters.RESET:
|
|
40
|
+
{
|
|
41
|
+
addDomain();
|
|
42
|
+
parentNode = rootNode;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
case characters.UP:
|
|
47
|
+
{
|
|
48
|
+
addDomain();
|
|
49
|
+
parentNode = parentNode.parent;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
domain += _char;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (domain !== "") {
|
|
58
|
+
addDomain();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return rootNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = parse;
|
|
File without changes
|
|
@@ -4,7 +4,7 @@ var _LINE_FILTERS;
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var characters = require("./characters");
|
|
8
8
|
|
|
9
9
|
var TYPE_COMPLETE = "complete";
|
|
10
10
|
var TYPE_LIGHT = "light";
|
|
@@ -54,14 +54,14 @@ function lineToString(line, i, arr) {
|
|
|
54
54
|
|
|
55
55
|
if (indexOfDifference === 0) {
|
|
56
56
|
// line and prevLine are completely different
|
|
57
|
-
separatorFromPrev =
|
|
57
|
+
separatorFromPrev = characters.RESET;
|
|
58
58
|
} else if (indexOfDifference === prevLine.length - 1) {
|
|
59
59
|
// only the last part of line and prevLine are different
|
|
60
|
-
separatorFromPrev =
|
|
60
|
+
separatorFromPrev = characters.SAME;
|
|
61
61
|
} else if (indexOfDifference > prevLine.length - 1) {
|
|
62
62
|
// we don't need to go up the hierarchy first because prevLine is part of line
|
|
63
63
|
// so let's just start with an initial down separator
|
|
64
|
-
separatorFromPrev =
|
|
64
|
+
separatorFromPrev = characters.DOWN;
|
|
65
65
|
} else {
|
|
66
66
|
// line and prevLine are different, but share a common root at indexOfDifference - 1
|
|
67
67
|
// we now need to go up the hierarchy to the common root
|
|
@@ -76,11 +76,11 @@ function lineToString(line, i, arr) {
|
|
|
76
76
|
throw new Error("Cannot serialize trie: The public suffix list contains unexpected rules.");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
separatorFromPrev = new Array(levelsUp).fill(
|
|
79
|
+
separatorFromPrev = new Array(levelsUp).fill(characters.UP).join("");
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
return separatorFromPrev + line.slice(indexOfDifference).join(
|
|
83
|
+
return separatorFromPrev + line.slice(indexOfDifference).join(characters.DOWN);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function serializeTrie(parsedList, type) {
|
package/lists/icann.complete.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const parse = require("../lib/trie/parse");
|
|
4
4
|
|
|
5
|
-
module.exports =
|
|
5
|
+
module.exports = parse(require("../build/tries/icann.complete.json").trie);
|
package/lists/icann.light.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const parse = require("../lib/trie/parse");
|
|
4
4
|
|
|
5
|
-
module.exports =
|
|
5
|
+
module.exports = parse(require("../build/tries/icann.light.json").trie);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const parse = require("../lib/trie/parse");
|
|
4
4
|
|
|
5
|
-
module.exports =
|
|
5
|
+
module.exports = parse(require("../build/tries/private.complete.json").trie);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse-domain",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "Splits an url into sub-domain, domain and effective top-level-domain",
|
|
5
5
|
"main": "./lib/parseDomain.js",
|
|
6
|
-
"types": "./
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "run-s build:lib build:tries",
|
|
9
9
|
"build:lib": "run-s build:lib:clean build:lib:babel",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"release": "standard-version",
|
|
16
16
|
"pretest": "run-s build:lib:clean pretest:link",
|
|
17
17
|
"pretest:link": "node scripts/link-src.js",
|
|
18
|
-
"test": "
|
|
18
|
+
"test": "jest",
|
|
19
19
|
"posttest": "eslint src test",
|
|
20
20
|
"update": "updtr"
|
|
21
21
|
},
|
|
@@ -37,10 +37,9 @@
|
|
|
37
37
|
"author": "peerigon <developers@peerigon.com>",
|
|
38
38
|
"license": "Unlicense",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"chai": "^4.2.0",
|
|
41
40
|
"got": "^8.3.2",
|
|
41
|
+
"jest": "^24.9.0",
|
|
42
42
|
"mkdirp": "^0.5.1",
|
|
43
|
-
"mocha": "^6.1.4",
|
|
44
43
|
"npm-run-all": "^4.1.5"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
@@ -51,7 +50,6 @@
|
|
|
51
50
|
"eslint-config-peerigon": "^17.1.0",
|
|
52
51
|
"eslint-plugin-import": "^2.17.2",
|
|
53
52
|
"eslint-plugin-jsdoc": "^4.8.4",
|
|
54
|
-
"nyc": "^14.1.1",
|
|
55
53
|
"rimraf": "^2.6.3",
|
|
56
54
|
"standard-version": "^6.0.1",
|
|
57
55
|
"updtr": "^3.1.0"
|
|
@@ -61,6 +59,7 @@
|
|
|
61
59
|
"scripts",
|
|
62
60
|
"lists",
|
|
63
61
|
"test",
|
|
64
|
-
"build"
|
|
62
|
+
"build",
|
|
63
|
+
"src/index.d.ts"
|
|
65
64
|
]
|
|
66
65
|
}
|
package/scripts/build-tries.js
CHANGED
|
@@ -12,7 +12,7 @@ const got = require("got");
|
|
|
12
12
|
const mkdirp = require("mkdirp");
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
require.resolve("../lib/
|
|
15
|
+
require.resolve("../lib/trie/parsePubSuffixList");
|
|
16
16
|
} catch (error) {
|
|
17
17
|
// This conditions occurs when the CI system or a developer checks out the repo for the first time.
|
|
18
18
|
// It happens because the postinstall hook kicks in *before* the lib is built.
|
|
@@ -20,12 +20,13 @@ try {
|
|
|
20
20
|
console.error("Lib does not exist yet, skipping build-tries step.");
|
|
21
21
|
process.exit(0); // eslint-disable-line no-process-exit
|
|
22
22
|
}
|
|
23
|
-
const parsePubSuffixList = require("../lib/
|
|
24
|
-
const serializeTrie = require("../lib/
|
|
23
|
+
const parsePubSuffixList = require("../lib/trie/parsePubSuffixList");
|
|
24
|
+
const serializeTrie = require("../lib/trie/serializeTrie");
|
|
25
25
|
|
|
26
26
|
const PUBLIC_SUFFIX_URL = "https://publicsuffix.org/list/public_suffix_list.dat";
|
|
27
27
|
const rootPath = path.resolve(__dirname, "..");
|
|
28
28
|
const triesPath = path.resolve(rootPath, "build", "tries");
|
|
29
|
+
const metaJsonFilename = path.resolve(triesPath, "meta.json");
|
|
29
30
|
const tries = [
|
|
30
31
|
{
|
|
31
32
|
listName: "icann",
|
|
@@ -59,7 +60,6 @@ got(PUBLIC_SUFFIX_URL, {timeout: 60 * 1000})
|
|
|
59
60
|
return {
|
|
60
61
|
path: path.resolve(triesPath, trie.filename),
|
|
61
62
|
content: JSON.stringify({
|
|
62
|
-
updatedAt: new Date().toISOString(),
|
|
63
63
|
trie: serializeTrie(parsedList, trie.type),
|
|
64
64
|
}),
|
|
65
65
|
};
|
|
@@ -74,20 +74,28 @@ got(PUBLIC_SUFFIX_URL, {timeout: 60 * 1000})
|
|
|
74
74
|
.then(() => {
|
|
75
75
|
process.stderr.write("Running sanity check... ");
|
|
76
76
|
|
|
77
|
-
childProcess.execFileSync(process.execPath, [require.resolve("
|
|
77
|
+
childProcess.execFileSync(process.execPath, [require.resolve(".bin/jest")], {
|
|
78
78
|
cwd: rootPath,
|
|
79
79
|
encoding: "utf8",
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
process.stderr.write("ok" + os.EOL);
|
|
83
|
+
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
metaJsonFilename,
|
|
86
|
+
JSON.stringify({
|
|
87
|
+
updatedAt: new Date().toISOString(),
|
|
88
|
+
}),
|
|
89
|
+
"utf8"
|
|
90
|
+
);
|
|
83
91
|
})
|
|
84
92
|
.catch(err => {
|
|
85
93
|
console.error("");
|
|
86
94
|
console.error(`Could not update list of known top-level domains for parse-domain because of "${err.message}"`);
|
|
87
95
|
|
|
88
|
-
const
|
|
96
|
+
const metaJson = JSON.parse(fs.readFileSync(metaJsonFilename, "utf8"));
|
|
89
97
|
|
|
90
|
-
console.error("Using possibly outdated prebuilt list from " + new Date(
|
|
98
|
+
console.error("Using possibly outdated prebuilt list from " + new Date(metaJson.updatedAt).toDateString());
|
|
91
99
|
|
|
92
100
|
// We can recover using the (possibly outdated) prebuilt list, hence exit code 0
|
|
93
101
|
process.exit(0); // eslint-disable-line no-process-exit
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export as namespace parseDomain;
|
|
2
|
+
|
|
3
|
+
declare namespace parseDomain {
|
|
4
|
+
interface ParseOptions {
|
|
5
|
+
customTlds?: RegExp | Array<string>;
|
|
6
|
+
privateTlds?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ParsedDomain {
|
|
10
|
+
domain: string;
|
|
11
|
+
subdomain: string;
|
|
12
|
+
tld: string;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare function parseDomain(url: string, options?: parseDomain.ParseOptions): parseDomain.ParsedDomain | null;
|
|
17
|
+
|
|
18
|
+
export = parseDomain;
|