सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
public_suffix पैकेज एक डार्ट लाइब्रेरी है जो सार्वजनिक सफ़िक्स सूची का उपयोग करके डोमेन नामों को विश्लेषित करती है, जिससे URL में टॉप-लेवल डोमेन (TLD) और रूट डोमेन की सटीक पहचान होती है। यह यह निर्धारित करने में मदद करता है कि डोमेन के कौन से हिस्से सार्वजनिक रूप से पंजीकृत किए जा सकते हैं और कौन से तीसरे पक्ष द्वारा प्रबंधित किए जाते हैं, जो कुकी प्रबंधन और डोमेन प्रमाणीकरण जैसी सुरक्षा और गोपनीयता विशेषताओं के लिए महत्वपूर्ण है। यह पैकेज सभी प्रमुख प्लेटफॉर्म जैसे वेब, मोबाइल और डेस्कटॉप को समर्थन देता है, जिससे यह आर्थिक डोमेन विश्लेषण की आवश्यकता वाले क्रॉस-प्लेटफॉर्म एप्लिकेशन के लिए आदर्श है।
उपयोग
डोमेन सत्यापन
Cookie सीमा निर्धारण
गोपनीयता सुरक्षा
URL पार्सिंग
सुरक्षा जाँच
मुख्य विशेषताएँ
आधिकारिक सार्वजनिक अंत सूची का उपयोग करता है
क्रॉस-प्लेटफ़ॉर्म समर्थन
सही TLD और मूल डोमेन का पता लगाना
हल्का और कारगर
नियमित रूप से अपडेट किया जाता है
इनके लिए उपयुक्त
वेब एप्लिकेशन
मोबाइल ऐप्स
डेस्कटॉप टूल्स
सुरक्षा-केंद्रित सेवाएं
ब्राउज़र एक्सटेंशन
विचार योग्य बातें
सूची अपडेट के लिए इंटरनेट एक्सेस की आवश्यकता होती है
प्रदर्शन के लिए कैशिंग की आवश्यकता हो सकती है
डोमेन-स्तर विश्लेषण तक सीमित
सामान्य URL विश्लेषण के लिए नहीं
बाहरी सूची के शुद्धता पर निर्भर
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Create instances of PublicSuffix to parse URLs, passing in the SuffixRules instance from step 2.
Access the different URL components through the PublicSuffix objects.
Short example using the static list
import'package:public_suffix/public_suffix.dart';
main() {
// Load a list of suffix rules.var suffixListString = 'load the list into this string';
DefaultSuffixRules.initFromString(suffixListString);
// Parse a URL.var parsedUrl = PublicSuffix(urlString: 'https://www.komposten.github.io');
// Obtain information using the many getters, for example:print(parsedUrl.suffix); // github.ioprint(parsedUrl.root); // kompostenprint(parsedUrl.domain); // komposten.github.ioprint(parsedUrl.icannDomain); // github.io// public_suffix also supports punycoded URLs:
parsedUrl = PublicSuffix(urlString: 'https://www.xn--6qq79v.cn');
print(parsedUrl.domain); // xn--6qq79v.cnprint(parsedUrl.punyDecoded.domain); // 你好.cn
}
Obtaining a suffix list
public_suffix requires a list of suffix rules to work. There is no list bundled by default as these lists are updated frequently.
To use public_suffix you need to first load a list of rules, and then either initialise DefaultSuffixRules (for static access) or create
your own instance of SuffixRules.
Initialising DefaultSuffixRules
The easiest way to use public_suffix is to get a list of rules and pass that list to DefaultSuffixRules. The PublicSuffix class will use this
list by default.
There are two ways of initialising it:
Load the list using your own code and pass it to DefaultSuffixRules.initFromString():
//Example using Flutterimport'package:flutter/services.dart';
import'package:public_suffix/public_suffix.dart';
main() {
var suffixList = rootBundle.loadString('assets/public_suffix_list.dat');
DefaultSuffixRules.initFromString(suffixList);
}
Import either the dart:io or the dart:html-based helper and load the list from a URI:
//Example using dart:io; for dart:html use browser_helper.dart instead.import'package:public_suffix/io_helper.dart';
main() async {
var uri = Uri.parse('https://publicsuffix.org/list/public_suffix_list.dat');
awaitSuffixRulesHelper.initDefaultListFromUri(listUri);
}
Creating SuffixRules instances
An alternative way to use public_suffix is to manually create an instance of SuffixRules and then pass that in when creating PublicSuffix objects.
Just like before, there are two ways of doing this:
Load the list using your own code and pass it to one of SuffixRules constructors:
//Example using Flutterimport'package:flutter/services.dart';
import'package:public_suffix/public_suffix.dart';
main() {
var suffixList = rootBundle.loadString('assets/public_suffix_list.dat');
var suffixRules = SuffixRules.fromString(suffixList);
}
Import either the dart:io or the dart:html-based helper and load the list from a URI:
//Example using dart:io; for dart:html use browser_helper.dart instead.import'package:public_suffix/io_helper.dart';
main() async {
var uri = Uri.parse('https://publicsuffix.org/list/public_suffix_list.dat');
var suffixRules = awaitSuffixRulesHelper.createListFromUri(listUri);
}
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 when the master copy is updated.
Utility functions
Several utility functions can be found in the DomainUtils class (imported from public_suffix.dart). These currently include:
isSubdomainOf: Checks if a given URL is a subdomain of another domain.
isSubdomain: Checks if a given URL has a subdomain part.
isKnownSuffix: Checks if a given suffix (e.g. co.uk) is listed in the suffix rule list.
hasValidDomain: Checks if a given URL contains a registrable domain part.
Most of these create PublicSuffix objects internally. If you are already working with PublicSuffix objects, there are similar methods you can call directly on those to avoid creating new ones.
Contributing
Git message conventions
public_suffix uses gitmoji to indicate commit types (bug fix, new feature, re-factor, etc.)
Commit messages should generally follow this format:
:emoji: Write a short summary on line one
Put additional information two lines down.
Use imperative forms of verbs. For example "Add", "Fix" and "Move" instead of "Added", "Fixed" and "Moved".
License
public_suffix is licensed under the MIT license. See LICENSE for the full license text.