2 lines
138 KiB
JavaScript
2 lines
138 KiB
JavaScript
|
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tldjs=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var allRules=require("./lib/suffix-trie.js").fromJson(require("./rules.json")),extractHostname=require("./lib/clean-host.js"),getDomain=require("./lib/domain.js"),getPublicSuffix=require("./lib/public-suffix.js"),getSubdomain=require("./lib/subdomain.js"),isValid=require("./lib/is-valid.js"),isIp=require("./lib/is-ip.js"),tldExists=require("./lib/tld-exists.js"),TLD_EXISTS=1,PUBLIC_SUFFIX=2,DOMAIN=3,SUB_DOMAIN=4,ALL=5;module.exports=function factory(options){var rules=options.rules||allRules||{},validHosts=options.validHosts||[],_extractHostname=options.extractHostname||extractHostname;function parse(url,_step){var step=_step||ALL,result={hostname:_extractHostname(url),isValid:null,isIp:null,tldExists:!1,publicSuffix:null,domain:null,subdomain:null};return null===result.hostname?(result.isIp=!1,result.isValid=!1,result):(result.isIp=isIp(result.hostname),result.isIp?(result.isValid=!0,result):(result.isValid=isValid(result.hostname),!1===result.isValid?result:(step!==ALL&&step!==TLD_EXISTS||(result.tldExists=tldExists(rules,result.hostname)),step===TLD_EXISTS?result:(result.publicSuffix=getPublicSuffix(rules,result.hostname),step===PUBLIC_SUFFIX?result:(result.domain=getDomain(validHosts,result.publicSuffix,result.hostname),step===DOMAIN?result:(result.subdomain=getSubdomain(result.hostname,result.domain),result))))))}return{extractHostname:_extractHostname,isValid:isValid,parse:parse,tldExists:function(url){return parse(url,TLD_EXISTS).tldExists},getPublicSuffix:function(url){return parse(url,PUBLIC_SUFFIX).publicSuffix},getDomain:function(url){return parse(url,DOMAIN).domain},getSubdomain:function(url){return parse(url,SUB_DOMAIN).subdomain},fromUserSettings:factory}}({})},{"./lib/clean-host.js":2,"./lib/domain.js":3,"./lib/is-ip.js":5,"./lib/is-valid.js":6,"./lib/public-suffix.js":7,"./lib/subdomain.js":8,"./lib/suffix-trie.js":9,"./lib/tld-exists.js":10,"./rules.json":17}],2:[function(require,module,exports){var URL=require("url"),isValid=require("./is-valid.js"),hasPrefixRE=/^(([a-z][a-z0-9+.-]*)?:)?\/\//;function trimTrailingDots(value){return"."===value[value.length-1]?value.substr(0,value.length-1):value}module.exports=function(value){if(isValid(value))return trimTrailingDots(value);var url=value;"string"!=typeof url&&(url=""+url);var needsTrimming=function(value){return value.length>0&&(value.charCodeAt(0)<=32||value.charCodeAt(value.length-1)<=32)}(url);needsTrimming&&(url=url.trim());var needsLowerCase=function(value){for(var i=0;i<value.length;i+=1){var code=value.charCodeAt(i);if(code>=65&&code<=90)return!0}return!1}(url);if(needsLowerCase&&(url=url.toLowerCase()),(needsLowerCase||needsTrimming)&&isValid(url))return trimTrailingDots(url);hasPrefixRE.test(url)||(url="//"+url);var parts=URL.parse(url,null,!0);return parts.hostname?trimTrailingDots(parts.hostname):null}},{"./is-valid.js":6,url:15}],3:[function(require,module,exports){"use strict";function shareSameDomainSuffix(hostname,vhost){return pattern=vhost,(str=hostname).lastIndexOf(pattern)===str.length-pattern.length&&(hostname.length===vhost.length||"."===hostname[hostname.length-vhost.length-1]);var str,pattern}module.exports=function(validHosts,suffix,hostname){for(var i=0;i<validHosts.length;i+=1){var vhost=validHosts[i];if(shareSameDomainSuffix(hostname,vhost))return vhost}return null===s
|