source: frontend/node_modules/psl/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 7.3 KB
Line 
1# psl (Public Suffix List)
2
3[![Node.js CI](https://github.com/lupomontero/psl/actions/workflows/node.js.yml/badge.svg)](https://github.com/lupomontero/psl/actions/workflows/node.js.yml)
4
5`psl` is a `JavaScript` domain name parser based on the
6[Public Suffix List](https://publicsuffix.org/).
7
8This implementation is tested against the
9[test data hosted by Mozilla](http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1)
10and kindly provided by [Comodo](https://www.comodo.com/).
11
12Cross browser testing provided by
13[<img alt="BrowserStack" width="160" src="./browserstack-logo.svg" />](https://www.browserstack.com/)
14
15## What is the Public Suffix List?
16
17The Public Suffix List is a cross-vendor initiative to provide an accurate list
18of domain name suffixes.
19
20The Public Suffix List is an initiative of the Mozilla Project, but is
21maintained as a community resource. It is available for use in any software,
22but was originally created to meet the needs of browser manufacturers.
23
24A "public suffix" is one under which Internet users can directly register names.
25Some examples of public suffixes are ".com", ".co.uk" and "pvt.k12.wy.us". The
26Public Suffix List is a list of all known public suffixes.
27
28Source: http://publicsuffix.org
29
30## Installation
31
32This module is available both for Node.js and the browser. See below for more
33details.
34
35### Node.js
36
37This module is tested on Node.js v8, v10, v12, v14, v16, v18, v20 and v22. See
38[`.github/workflows/node.js.yml`](.github/workflows/node.js.yml).
39
40```sh
41npm install psl
42```
43
44#### ESM
45
46From version `v1.13.0` you can now import `psl` as ESM.
47
48```js
49import psl from 'psl';
50```
51
52#### CommonJS
53
54If your project still uses CommonJS, you can continue importing the module like
55in previous versions.
56
57```js
58const psl = require('psl');
59```
60
61### Browser
62
63#### Using a bundler
64
65If you are using a bundler to build your app, you should be able to `import`
66and/or `require` the module just like in Node.js.
67
68#### ESM (using a CDN)
69
70In modern browsers you can also import the ESM directly from a `CDN`. For
71example:
72
73```js
74import psl from 'https://unpkg.com/psl@latest/dist/psl.mjs';
75```
76
77#### UMD / CommonJS
78
79Finally, you can still download [`dist/psl.umd.cjs`](https://raw.githubusercontent.com/lupomontero/psl/main/dist/psl.umd.cjs)
80and include it in a script tag.
81
82```html
83<script src="psl.umd.cjs"></script>
84```
85
86This script is bundled and wrapped in a [umd](https://github.com/umdjs/umd)
87wrapper so you should be able to use it standalone or together with a module
88loader.
89
90The script is also available on most popular CDNs. For example:
91
92* https://unpkg.com/psl@latest/dist/psl.umd.cjs
93
94## API
95
96### `psl.parse(domain)`
97
98Parse domain based on Public Suffix List. Returns an `Object` with the following
99properties:
100
101* `tld`: Top level domain (this is the _public suffix_).
102* `sld`: Second level domain (the first private part of the domain name).
103* `domain`: The domain name is the `sld` + `tld`.
104* `subdomain`: Optional parts left of the domain.
105
106#### Examples
107
108Parse domain without subdomain:
109
110```js
111import psl from 'psl';
112
113const parsed = psl.parse('google.com');
114console.log(parsed.tld); // 'com'
115console.log(parsed.sld); // 'google'
116console.log(parsed.domain); // 'google.com'
117console.log(parsed.subdomain); // null
118```
119
120Parse domain with subdomain:
121
122```js
123import psl from 'psl';
124
125const parsed = psl.parse('www.google.com');
126console.log(parsed.tld); // 'com'
127console.log(parsed.sld); // 'google'
128console.log(parsed.domain); // 'google.com'
129console.log(parsed.subdomain); // 'www'
130```
131
132Parse domain with nested subdomains:
133
134```js
135import psl from 'psl';
136
137const parsed = psl.parse('a.b.c.d.foo.com');
138console.log(parsed.tld); // 'com'
139console.log(parsed.sld); // 'foo'
140console.log(parsed.domain); // 'foo.com'
141console.log(parsed.subdomain); // 'a.b.c.d'
142```
143
144### `psl.get(domain)`
145
146Get domain name, `sld` + `tld`. Returns `null` if not valid.
147
148#### Examples
149
150```js
151import psl from 'psl';
152
153// null input.
154psl.get(null); // null
155
156// Mixed case.
157psl.get('COM'); // null
158psl.get('example.COM'); // 'example.com'
159psl.get('WwW.example.COM'); // 'example.com'
160
161// Unlisted TLD.
162psl.get('example'); // null
163psl.get('example.example'); // 'example.example'
164psl.get('b.example.example'); // 'example.example'
165psl.get('a.b.example.example'); // 'example.example'
166
167// TLD with only 1 rule.
168psl.get('biz'); // null
169psl.get('domain.biz'); // 'domain.biz'
170psl.get('b.domain.biz'); // 'domain.biz'
171psl.get('a.b.domain.biz'); // 'domain.biz'
172
173// TLD with some 2-level rules.
174psl.get('uk.com'); // null);
175psl.get('example.uk.com'); // 'example.uk.com');
176psl.get('b.example.uk.com'); // 'example.uk.com');
177
178// More complex TLD.
179psl.get('c.kobe.jp'); // null
180psl.get('b.c.kobe.jp'); // 'b.c.kobe.jp'
181psl.get('a.b.c.kobe.jp'); // 'b.c.kobe.jp'
182psl.get('city.kobe.jp'); // 'city.kobe.jp'
183psl.get('www.city.kobe.jp'); // 'city.kobe.jp'
184
185// IDN labels.
186psl.get('食狮.com.cn'); // '食狮.com.cn'
187psl.get('食狮.公司.cn'); // '食狮.公司.cn'
188psl.get('www.食狮.公司.cn'); // '食狮.公司.cn'
189
190// Same as above, but punycoded.
191psl.get('xn--85x722f.com.cn'); // 'xn--85x722f.com.cn'
192psl.get('xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'
193psl.get('www.xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'
194```
195
196### `psl.isValid(domain)`
197
198Check whether a domain has a valid Public Suffix. Returns a `Boolean` indicating
199whether the domain has a valid Public Suffix.
200
201#### Example
202
203```js
204import psl from 'psl';
205
206psl.isValid('google.com'); // true
207psl.isValid('www.google.com'); // true
208psl.isValid('x.yz'); // false
209```
210
211## Testing and Building
212
213There are tests both for Node.js and the browser (using [Playwright](https://playwright.dev)
214and [BrowserStack](https://www.browserstack.com/)).
215
216```sh
217# Run tests in node.
218npm test
219# Run tests in browserstack.
220npm run test:browserstack
221
222# Update rules from publicsuffix.org
223npm run update-rules
224
225# Build ESM, CJS and UMD and create dist files
226npm run build
227```
228
229Feel free to fork if you see possible improvements!
230
231## Acknowledgements
232
233* Mozilla Foundation's [Public Suffix List](https://publicsuffix.org/)
234* Thanks to Rob Stradling of [Comodo](https://www.comodo.com/) for providing
235 test data.
236* Inspired by [weppos/publicsuffix-ruby](https://github.com/weppos/publicsuffix-ruby)
237
238## License
239
240The MIT License (MIT)
241
242Copyright (c) 2014-2024 Lupo Montero <lupomontero@gmail.com>
243
244Permission is hereby granted, free of charge, to any person obtaining a copy
245of this software and associated documentation files (the "Software"), to deal
246in the Software without restriction, including without limitation the rights
247to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
248copies of the Software, and to permit persons to whom the Software is
249furnished to do so, subject to the following conditions:
250
251The above copyright notice and this permission notice shall be included in
252all copies or substantial portions of the Software.
253
254THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
255IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
256FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
257AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
258LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
259OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
260THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.