\href{https://nodei.co/npm/psl/}{\texttt{ }}

\href{https://greenkeeper.io/}{\texttt{ }} \href{https://travis-ci.org/lupomontero/psl}{\texttt{ }} \href{https://david-dm.org/lupomontero/psl\#info=devDependencies}{\texttt{ }}

{\ttfamily psl} is a {\ttfamily Java\+Script} domain name parser based on the \href{https://publicsuffix.org/}{\texttt{ Public Suffix List}}.

This implementation is tested against the \href{http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1}{\texttt{ test data hosted by Mozilla}} and kindly provided by \href{https://www.comodo.com/}{\texttt{ Comodo}}.

Cross browser testing provided by \href{https://www.browserstack.com/}{\texttt{ }}\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23509}{}\doxysection{What is the Public Suffix List?}\label{md_sfcode_node_modules_psl_README_autotoc_md23509}
The Public Suffix List is a cross-\/vendor initiative to provide an accurate list of domain name suffixes.

The Public Suffix List is an initiative of the Mozilla Project, but is maintained as a community resource. It is available for use in any software, but was originally created to meet the needs of browser manufacturers.

A \char`\"{}public suffix\char`\"{} is one under which Internet users can directly register names. Some examples of public suffixes are \char`\"{}.\+com\char`\"{}, \char`\"{}.\+co.\+uk\char`\"{} and \char`\"{}pvt.\+k12.\+wy.\+us\char`\"{}. The Public Suffix List is a list of all known public suffixes.

Source\+: \href{http://publicsuffix.org}{\texttt{ http\+://publicsuffix.\+org}}\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23510}{}\doxysection{Installation}\label{md_sfcode_node_modules_psl_README_autotoc_md23510}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23511}{}\doxysubsection{Node.\+js}\label{md_sfcode_node_modules_psl_README_autotoc_md23511}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install -\/-\/save psl }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23512}{}\doxysubsection{Browser}\label{md_sfcode_node_modules_psl_README_autotoc_md23512}
Download \href{https://raw.githubusercontent.com/lupomontero/psl/master/dist/psl.min.js}{\texttt{ psl.\+min.\+js}} and include it in a script tag.


\begin{DoxyCode}{0}
\DoxyCodeLine{<script src="{}psl.min.js"{}></script> }

\end{DoxyCode}


This script is browserified and wrapped in a \href{https://github.com/umdjs/umd}{\texttt{ umd}} wrapper so you should be able to use it standalone or together with a module loader.\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23513}{}\doxysection{API}\label{md_sfcode_node_modules_psl_README_autotoc_md23513}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23514}{}\doxysubsection{$<$tt$>$psl.\+parse(domain)$<$/tt$>$}\label{md_sfcode_node_modules_psl_README_autotoc_md23514}
Parse domain based on Public Suffix List. Returns an {\ttfamily Object} with the following properties\+:


\begin{DoxyItemize}
\item {\ttfamily tld}\+: Top level domain (this is the {\itshape public suffix}).
\item {\ttfamily sld}\+: Second level domain (the first private part of the domain name).
\item {\ttfamily domain}\+: The domain name is the {\ttfamily sld} + {\ttfamily tld}.
\item {\ttfamily subdomain}\+: Optional parts left of the domain.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23515}{}\doxysubsubsection{Example\+:}\label{md_sfcode_node_modules_psl_README_autotoc_md23515}

\begin{DoxyCode}{0}
\DoxyCodeLine{var psl = require('psl');}
\DoxyCodeLine{}
\DoxyCodeLine{// Parse domain without subdomain}
\DoxyCodeLine{var parsed = psl.parse('google.com');}
\DoxyCodeLine{console.log(parsed.tld); // 'com'}
\DoxyCodeLine{console.log(parsed.sld); // 'google'}
\DoxyCodeLine{console.log(parsed.domain); // 'google.com'}
\DoxyCodeLine{console.log(parsed.subdomain); // null}
\DoxyCodeLine{}
\DoxyCodeLine{// Parse domain with subdomain}
\DoxyCodeLine{var parsed = psl.parse('www.google.com');}
\DoxyCodeLine{console.log(parsed.tld); // 'com'}
\DoxyCodeLine{console.log(parsed.sld); // 'google'}
\DoxyCodeLine{console.log(parsed.domain); // 'google.com'}
\DoxyCodeLine{console.log(parsed.subdomain); // 'www'}
\DoxyCodeLine{}
\DoxyCodeLine{// Parse domain with nested subdomains}
\DoxyCodeLine{var parsed = psl.parse('a.b.c.d.foo.com');}
\DoxyCodeLine{console.log(parsed.tld); // 'com'}
\DoxyCodeLine{console.log(parsed.sld); // 'foo'}
\DoxyCodeLine{console.log(parsed.domain); // 'foo.com'}
\DoxyCodeLine{console.log(parsed.subdomain); // 'a.b.c.d' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23516}{}\doxysubsection{$<$tt$>$psl.\+get(domain)$<$/tt$>$}\label{md_sfcode_node_modules_psl_README_autotoc_md23516}
Get domain name, {\ttfamily sld} + {\ttfamily tld}. Returns {\ttfamily null} if not valid.\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23517}{}\doxysubsubsection{Example\+:}\label{md_sfcode_node_modules_psl_README_autotoc_md23517}

\begin{DoxyCode}{0}
\DoxyCodeLine{var psl = require('psl');}
\DoxyCodeLine{}
\DoxyCodeLine{// null input.}
\DoxyCodeLine{psl.get(null); // null}
\DoxyCodeLine{}
\DoxyCodeLine{// Mixed case.}
\DoxyCodeLine{psl.get('COM'); // null}
\DoxyCodeLine{psl.get('example.COM'); // 'example.com'}
\DoxyCodeLine{psl.get('WwW.example.COM'); // 'example.com'}
\DoxyCodeLine{}
\DoxyCodeLine{// Unlisted TLD.}
\DoxyCodeLine{psl.get('example'); // null}
\DoxyCodeLine{psl.get('example.example'); // 'example.example'}
\DoxyCodeLine{psl.get('b.example.example'); // 'example.example'}
\DoxyCodeLine{psl.get('a.b.example.example'); // 'example.example'}
\DoxyCodeLine{}
\DoxyCodeLine{// TLD with only 1 rule.}
\DoxyCodeLine{psl.get('biz'); // null}
\DoxyCodeLine{psl.get('domain.biz'); // 'domain.biz'}
\DoxyCodeLine{psl.get('b.domain.biz'); // 'domain.biz'}
\DoxyCodeLine{psl.get('a.b.domain.biz'); // 'domain.biz'}
\DoxyCodeLine{}
\DoxyCodeLine{// TLD with some 2-\/level rules.}
\DoxyCodeLine{psl.get('uk.com'); // null);}
\DoxyCodeLine{psl.get('example.uk.com'); // 'example.uk.com');}
\DoxyCodeLine{psl.get('b.example.uk.com'); // 'example.uk.com');}
\DoxyCodeLine{}
\DoxyCodeLine{// More complex TLD.}
\DoxyCodeLine{psl.get('c.kobe.jp'); // null}
\DoxyCodeLine{psl.get('b.c.kobe.jp'); // 'b.c.kobe.jp'}
\DoxyCodeLine{psl.get('a.b.c.kobe.jp'); // 'b.c.kobe.jp'}
\DoxyCodeLine{psl.get('city.kobe.jp'); // 'city.kobe.jp'}
\DoxyCodeLine{psl.get('www.city.kobe.jp'); // 'city.kobe.jp'}
\DoxyCodeLine{}
\DoxyCodeLine{// IDN labels.}
\DoxyCodeLine{psl.get('食狮.com.cn'); // '食狮.com.cn'}
\DoxyCodeLine{psl.get('食狮.公司.cn'); // '食狮.公司.cn'}
\DoxyCodeLine{psl.get('www.食狮.公司.cn'); // '食狮.公司.cn'}
\DoxyCodeLine{}
\DoxyCodeLine{// Same as above, but punycoded.}
\DoxyCodeLine{psl.get('xn-\/-\/85x722f.com.cn'); // 'xn-\/-\/85x722f.com.cn'}
\DoxyCodeLine{psl.get('xn-\/-\/85x722f.xn-\/-\/55qx5d.cn'); // 'xn-\/-\/85x722f.xn-\/-\/55qx5d.cn'}
\DoxyCodeLine{psl.get('www.xn-\/-\/85x722f.xn-\/-\/55qx5d.cn'); // 'xn-\/-\/85x722f.xn-\/-\/55qx5d.cn' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23518}{}\doxysubsection{$<$tt$>$psl.\+is\+Valid(domain)$<$/tt$>$}\label{md_sfcode_node_modules_psl_README_autotoc_md23518}
Check whether a domain has a valid Public Suffix. Returns a {\ttfamily Boolean} indicating whether the domain has a valid Public Suffix.\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23519}{}\doxysubsubsection{Example}\label{md_sfcode_node_modules_psl_README_autotoc_md23519}

\begin{DoxyCode}{0}
\DoxyCodeLine{var psl = require('psl');}
\DoxyCodeLine{}
\DoxyCodeLine{psl.isValid('google.com'); // true}
\DoxyCodeLine{psl.isValid('www.google.com'); // true}
\DoxyCodeLine{psl.isValid('x.yz'); // false }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23520}{}\doxysection{Testing and Building}\label{md_sfcode_node_modules_psl_README_autotoc_md23520}
Test are written using \href{https://mochajs.org/}{\texttt{ {\ttfamily mocha}}} and can be run in two different environments\+: {\ttfamily node} and {\ttfamily phantomjs}.


\begin{DoxyCode}{0}
\DoxyCodeLine{\# This will run `eslint`, `mocha` and `karma`.}
\DoxyCodeLine{npm test}
\DoxyCodeLine{}
\DoxyCodeLine{\# Individual test environments}
\DoxyCodeLine{\# Run tests in node only.}
\DoxyCodeLine{./node\_modules/.bin/mocha test}
\DoxyCodeLine{\# Run tests in phantomjs only.}
\DoxyCodeLine{./node\_modules/.bin/karma start ./karma.conf.js -\/-\/single-\/run}
\DoxyCodeLine{}
\DoxyCodeLine{\# Build data (parse raw list) and create dist files}
\DoxyCodeLine{npm run build }

\end{DoxyCode}


Feel free to fork if you see possible improvements!\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23521}{}\doxysection{Acknowledgements}\label{md_sfcode_node_modules_psl_README_autotoc_md23521}

\begin{DoxyItemize}
\item Mozilla Foundation\textquotesingle{}s \href{https://publicsuffix.org/}{\texttt{ Public Suffix List}}
\item Thanks to Rob Stradling of \href{https://www.comodo.com/}{\texttt{ Comodo}} for providing test data.
\item Inspired by \href{https://github.com/weppos/publicsuffix-ruby}{\texttt{ weppos/publicsuffix-\/ruby}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_psl_README_autotoc_md23522}{}\doxysection{License}\label{md_sfcode_node_modules_psl_README_autotoc_md23522}
The MIT License (MIT)

Copyright (c) 2017 Lupo Montero \href{mailto:lupomontero@gmail.com}{\texttt{ lupomontero@gmail.\+com}}

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \char`\"{}\+Software\char`\"{}), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions\+:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED \char`\"{}\+AS IS\char`\"{}, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 