source: trip-planner-front/node_modules/psl/README.md@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.6 KB
Line 
1# psl (Public Suffix List)
2
3[![NPM](https://nodei.co/npm/psl.png?downloads=true&downloadRank=true)](https://nodei.co/npm/psl/)
4
5[![Greenkeeper badge](https://badges.greenkeeper.io/lupomontero/psl.svg)](https://greenkeeper.io/)
6[![Build Status](https://travis-ci.org/lupomontero/psl.svg?branch=master)](https://travis-ci.org/lupomontero/psl)
7[![devDependency Status](https://david-dm.org/lupomontero/psl/dev-status.png)](https://david-dm.org/lupomontero/psl#info=devDependencies)
8
9`psl` is a `JavaScript` domain name parser based on the
10[Public Suffix List](https://publicsuffix.org/).
11
12This implementation is tested against the
13[test data hosted by Mozilla](http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1)
14and kindly provided by [Comodo](https://www.comodo.com/).
15
16Cross browser testing provided by
17[<img alt="BrowserStack" width="160" src="./browserstack-logo.svg" />](https://www.browserstack.com/)
18
19## What is the Public Suffix List?
20
21The Public Suffix List is a cross-vendor initiative to provide an accurate list
22of domain name suffixes.
23
24The Public Suffix List is an initiative of the Mozilla Project, but is
25maintained as a community resource. It is available for use in any software,
26but was originally created to meet the needs of browser manufacturers.
27
28A "public suffix" is one under which Internet users can directly register names.
29Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The
30Public Suffix List is a list of all known public suffixes.
31
32Source: http://publicsuffix.org
33
34
35## Installation
36
37### Node.js
38
39```sh
40npm install --save psl
41```
42
43### Browser
44
45Download [psl.min.js](https://raw.githubusercontent.com/lupomontero/psl/master/dist/psl.min.js)
46and include it in a script tag.
47
48```html
49<script src="psl.min.js"></script>
50```
51
52This script is browserified and wrapped in a [umd](https://github.com/umdjs/umd)
53wrapper so you should be able to use it standalone or together with a module
54loader.
55
56## API
57
58### `psl.parse(domain)`
59
60Parse domain based on Public Suffix List. Returns an `Object` with the following
61properties:
62
63* `tld`: Top level domain (this is the _public suffix_).
64* `sld`: Second level domain (the first private part of the domain name).
65* `domain`: The domain name is the `sld` + `tld`.
66* `subdomain`: Optional parts left of the domain.
67
68#### Example:
69
70```js
71var psl = require('psl');
72
73// Parse domain without subdomain
74var parsed = psl.parse('google.com');
75console.log(parsed.tld); // 'com'
76console.log(parsed.sld); // 'google'
77console.log(parsed.domain); // 'google.com'
78console.log(parsed.subdomain); // null
79
80// Parse domain with subdomain
81var parsed = psl.parse('www.google.com');
82console.log(parsed.tld); // 'com'
83console.log(parsed.sld); // 'google'
84console.log(parsed.domain); // 'google.com'
85console.log(parsed.subdomain); // 'www'
86
87// Parse domain with nested subdomains
88var parsed = psl.parse('a.b.c.d.foo.com');
89console.log(parsed.tld); // 'com'
90console.log(parsed.sld); // 'foo'
91console.log(parsed.domain); // 'foo.com'
92console.log(parsed.subdomain); // 'a.b.c.d'
93```
94
95### `psl.get(domain)`
96
97Get domain name, `sld` + `tld`. Returns `null` if not valid.
98
99#### Example:
100
101```js
102var psl = require('psl');
103
104// null input.
105psl.get(null); // null
106
107// Mixed case.
108psl.get('COM'); // null
109psl.get('example.COM'); // 'example.com'
110psl.get('WwW.example.COM'); // 'example.com'
111
112// Unlisted TLD.
113psl.get('example'); // null
114psl.get('example.example'); // 'example.example'
115psl.get('b.example.example'); // 'example.example'
116psl.get('a.b.example.example'); // 'example.example'
117
118// TLD with only 1 rule.
119psl.get('biz'); // null
120psl.get('domain.biz'); // 'domain.biz'
121psl.get('b.domain.biz'); // 'domain.biz'
122psl.get('a.b.domain.biz'); // 'domain.biz'
123
124// TLD with some 2-level rules.
125psl.get('uk.com'); // null);
126psl.get('example.uk.com'); // 'example.uk.com');
127psl.get('b.example.uk.com'); // 'example.uk.com');
128
129// More complex TLD.
130psl.get('c.kobe.jp'); // null
131psl.get('b.c.kobe.jp'); // 'b.c.kobe.jp'
132psl.get('a.b.c.kobe.jp'); // 'b.c.kobe.jp'
133psl.get('city.kobe.jp'); // 'city.kobe.jp'
134psl.get('www.city.kobe.jp'); // 'city.kobe.jp'
135
136// IDN labels.
137psl.get('食狮.com.cn'); // '食狮.com.cn'
138psl.get('食狮.公司.cn'); // '食狮.公司.cn'
139psl.get('www.食狮.公司.cn'); // '食狮.公司.cn'
140
141// Same as above, but punycoded.
142psl.get('xn--85x722f.com.cn'); // 'xn--85x722f.com.cn'
143psl.get('xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'
144psl.get('www.xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'
145```
146
147### `psl.isValid(domain)`
148
149Check whether a domain has a valid Public Suffix. Returns a `Boolean` indicating
150whether the domain has a valid Public Suffix.
151
152#### Example
153
154```js
155var psl = require('psl');
156
157psl.isValid('google.com'); // true
158psl.isValid('www.google.com'); // true
159psl.isValid('x.yz'); // false
160```
161
162
163## Testing and Building
164
165Test are written using [`mocha`](https://mochajs.org/) and can be
166run in two different environments: `node` and `phantomjs`.
167
168```sh
169# This will run `eslint`, `mocha` and `karma`.
170npm test
171
172# Individual test environments
173# Run tests in node only.
174./node_modules/.bin/mocha test
175# Run tests in phantomjs only.
176./node_modules/.bin/karma start ./karma.conf.js --single-run
177
178# Build data (parse raw list) and create dist files
179npm run build
180```
181
182Feel free to fork if you see possible improvements!
183
184
185## Acknowledgements
186
187* Mozilla Foundation's [Public Suffix List](https://publicsuffix.org/)
188* Thanks to Rob Stradling of [Comodo](https://www.comodo.com/) for providing
189 test data.
190* Inspired by [weppos/publicsuffix-ruby](https://github.com/weppos/publicsuffix-ruby)
191
192
193## License
194
195The MIT License (MIT)
196
197Copyright (c) 2017 Lupo Montero <lupomontero@gmail.com>
198
199Permission is hereby granted, free of charge, to any person obtaining a copy
200of this software and associated documentation files (the "Software"), to deal
201in the Software without restriction, including without limitation the rights
202to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
203copies of the Software, and to permit persons to whom the Software is
204furnished to do so, subject to the following conditions:
205
206The above copyright notice and this permission notice shall be included in
207all copies or substantial portions of the Software.
208
209THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
210IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
212AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
213LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
214OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
215THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.