Skip to content

Commit

Permalink
📝 Update docs and add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Komposten committed Aug 24, 2019
1 parent 5390768 commit 76354be
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.0

-
- Load suffix rule lists from strings or URIs.
- Parse URLs against suffix lists to obtain:
- public suffix (e.g. `co.uk`)
- root domain (e.g. `google`)
- registrable domain (e.g. `google.co.uk`)
- Obtain results with and without private (i.e. non-ICANN/IANA) suffix rules.
- Obtain punycode encoded and decoded results (if a punycoded URL is parsed).
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# public_suffix
[![Build Status](https://travis-ci.com/Komposten/public_suffix.svg?branch=master)](https://travis-ci.com/Komposten/public_suffix)

**A domain parser based on the [Public Suffix List](https://publicsuffix.org/)**

public_suffix identifies the public suffixes, root domains and registrable parts of URLs.
public_suffix is a dart library for identifying the public suffixes (or TLDs), root domains and registrable parts of URLs.

## Usage
1) Import `public_suffix_io.dart` or `public_suffix_browser.dart`.
2) Initialise `SuffixRules` from a file/uri containing suffix rules.
3) Create a new instance of `PublicSuffix` to parse a URL.
4) Access the different components through the `PublicSuffix` object.

**Note:** Don't overload publicsuffix.org's servers by repeatedly retrieving the suffix list from them. Cache a copy somewhere instead, and update that copy only when the master copy is updated.

```dart
import 'public_suffix_io.dart';
main() {
SuffixRulesHelper.initFromUri(Uri.parse("https://publicsuffix.org/list/public_suffix_list.dat"));
PublicSuffix suffix = PublicSuffix(Uri.parse("https://www.publicsuffix.org"));
print(suffix.publicTld); // "org"
print(suffix.rootDomain); // "publicsuffix"
print(suffix.registrableDomain); // "publicsuffix.org"
import 'package:public_suffix/public_suffix_io.dart';
main(List<String> arguments) async {
await SuffixRulesHelper.initFromUri(
Uri.parse("https://publicsuffix.org/list/public_suffix_list.dat"));
PublicSuffix suffix =
PublicSuffix(Uri.parse("https://www.komposten.github.io"));
//Results when matching against ICANN/IANA and private suffixes.
print(suffix.suffix); // "github.io"
print(suffix.root); // "komposten"
print(suffix.domain); // "komposten.github.io"
//Results when matching against only ICANN/IANA suffixes.
print(suffix.icannSuffix); // "io"
print(suffix.icannRoot); // "github"
print(suffix.icannDomain); // "github.io"
//punycode decoded results.
suffix = PublicSuffix(Uri.parse("https://www.xn--6qq79v.cn"));
print(suffix.domain); // "xn--6qq79v.cn"
print(suffix.punyDecoded.domain); // "你好.cn"
}
```

## License
public_suffix is licensed under the MIT license. See [LICENSE](LICENSE) for the full license text.
public_suffix is licensed under the MIT license. See [LICENSE](https://github.com/Komposten/public_suffix/blob/master/LICENSE) for the full license text.
30 changes: 30 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:public_suffix/public_suffix_io.dart';

main(List<String> arguments) async {
// Load a list of suffix rules from publicsuffix.org.
await SuffixRulesHelper.initFromUri(
Uri.parse("https://publicsuffix.org/list/public_suffix_list.dat"));

// Parse a URL.
PublicSuffix suffix =
PublicSuffix(Uri.parse("https://www.komposten.github.io"));

// Results when matching against ICANN/IANA and private suffixes.
print(suffix.suffix); // "github.io"
print(suffix.root); // "komposten"
print(suffix.domain); // "komposten.github.io"

// Results when matching against only ICANN/IANA suffixes.
print(suffix.icannSuffix); // "io"
print(suffix.icannRoot); // "github"
print(suffix.icannDomain); // "github.io"

// punycode decoded results.
suffix = PublicSuffix(Uri.parse("https://www.xn--6qq79v.cn"));
print(suffix.domain); // "xn--6qq79v.cn"
print(suffix.punyDecoded.domain); // "你好.cn"

// Dispose the list to unload it from memory if you wish.
// This is probably not needed since the list is relatively small.
SuffixRules.dispose();
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: public_suffix
description: A library for getting the public suffix of a URL.
# version: 1.0.0
description: A domain parser based on the Public Suffix List
version: 1.0.0
homepage: https://www.github.com/komposten/
repository: https://www.github.com/komposten/public_suffix
issue_tracker: https://www.github.com/komposten/public_suffix/issues
Expand Down

0 comments on commit 76354be

Please sign in to comment.