Skip to content

Commit

Permalink
Merge pull request #34 from mjethani/readme-domaintoascii
Browse files Browse the repository at this point in the history
Update README.md to use domainToASCII()
  • Loading branch information
gorhill committed Sep 4, 2021
2 parents 5405a51 + ab77dc2 commit 3a22c72
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ publicSuffixList = {
## Usage

```html
<script src="punycode.js"></script>
<script type="module">
import publicSuffixList from 'publicsuffixlist.js';
// See https://github.com/mathiasbynens/punycode.js for an alternative.
const domainToASCII = domain => new URL('ws://' + domain).hostname;
/**/
// Feed it the list (you choose how you obtain it).
// `list` must be unicode text.
// Need to pass a converter to punycode (punycode.js is
// awesome: https://github.com/bestiejs/punycode.js).
publicSuffixList.parse(list, punycode.toASCII);
publicSuffixList.parse(list, domainToASCII);
/**/
Expand Down Expand Up @@ -72,14 +71,13 @@ npm install gorhill/publicsuffixlist.js
```
```js
import suffixList from 'publicsuffixlist';
// For utf-8 conversion - npm install punycode
import punycode from 'punycode';
import { domainToASCII } from 'url';
import fs from 'fs';

// Suffix list downloaded from https://publicsuffix.org/list/public_suffix_list.dat
const suffixData = fs.readFileSync('./public_suffix_list.dat', 'utf8');

suffixList.parse(suffixData, punycode.toASCII);
suffixList.parse(suffixData, domainToASCII);

let domain = suffixList.getDomain('haha.whatisthis.global.prod.fastly.net');
// domain = 'whatisthis.global.prod.fastly.net'
Expand Down

0 comments on commit 3a22c72

Please sign in to comment.