Update README.md

This commit is contained in:
Doug Bird 2018-06-12 23:16:56 -07:00 committed by GitHub
parent 300cc523e0
commit 16e7cdb202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 69 additions and 27 deletions

View File

@ -1,9 +1,9 @@
# TLD Enumerations # TLD Enumerations
Lists of every [IANA TLD](http://data.iana.org/TLD/tlds-alpha-by-domain.txt) in various formats. The lists may be continuously updated using the [included utility](#updating-the-tld-lists) that pulls the latest data from IANA. Lists of every [IANA TLD](http://data.iana.org/TLD/tlds-alpha-by-domain.txt) in various formats. The lists may be continuously updated using the [included utility](#updating-the-tld-lists) that pulls the latest data from IANA.
* [CSV format](./tlds.csv) * [CSV Format](./tlds.csv)
* [All Formats](#tld-list-formats) * [All Format Files](#tld-list-formats)
* [Updating the TLDs](#updating-the-tld-lists) * [Updating the Format Files](#updating-the-tld-format-files)
* [Node Usage](#node-usage) * [Node Usage](#node-usage)
* [PHP Usage](#php-usage) * [PHP Usage](#php-usage)
@ -29,20 +29,20 @@ Additionally, for convenience, some native programming language formats have als
```js ```js
const tldEnum = require('tld-enum'); const tldEnum = require('tld-enum');
tldEnum.tldList; //an array with every IANA TLD tldEnum.list; //an array with every IANA TLD
``` ```
The following example... The following example...
```js ```js
const tldEnum = require('tld-enum'); const tldEnum = require('tld-enum');
console.log("There are " + tldEnum.tldList.length + " IANA TLDs"); console.log("There are " + tldEnum.list.length + " IANA TLDs");
let tldCheck; let tldCheck;
tldCheck = "com"; tldCheck = "com";
console.log("Is '" + tldCheck + "' a real TLD?"); console.log("Is '" + tldCheck + "' a real TLD?");
if (tldEnum.tldList.indexOf(tldCheck.toLowerCase()) != -1) { if (tldEnum.list.indexOf(tldCheck.toLowerCase()) != -1) {
console.log(" yes"); console.log(" yes");
} else { } else {
console.log(" no"); console.log(" no");
@ -50,7 +50,7 @@ Additionally, for convenience, some native programming language formats have als
tldCheck = "somethingWeird"; tldCheck = "somethingWeird";
console.log("Is '" + tldCheck + "' a real TLD?"); console.log("Is '" + tldCheck + "' a real TLD?");
if (tldEnum.tldList.indexOf(tldCheck.toLowerCase()) != -1) { if (tldEnum.list.indexOf(tldCheck.toLowerCase()) != -1) {
console.log(" yes"); console.log(" yes");
} else { } else {
console.log(" no"); console.log(" no");
@ -59,7 +59,7 @@ Additionally, for convenience, some native programming language formats have als
Should produce the following output... Should produce the following output...
```txt ```txt
There are 1573 IANA TLDs There are 1577 IANA TLDs
Is 'com' a real TLD? Is 'com' a real TLD?
yes yes
Is 'somethingWeird' a real TLD? Is 'somethingWeird' a real TLD?
@ -72,26 +72,23 @@ Additionally, for convenience, some native programming language formats have als
$ composer require katmore/tld-enum $ composer require katmore/tld-enum
``` ```
* access the list by using the `\TldEnum\TldEnum::TLD_ENUM` class constant array * access the list by using the `\TldList::TLD_LIST` class constant array
```php ```php
<?php <?php
require_once __DIR__ . '/vendor/autoload.php'; print_r(\TldList::TLD_LIST); //an array with every IANA TLD
\TldEnum\TldEnum::TLD_ENUM; //an array with every IANA TLD
``` ```
The following example... The following example...
```php ```php
<?php <?php
use TldEnum\TldEnum; use TldEnum\TldList;
require __DIR__ . '/vendor/autoload.php'; echo "There are " . count(TldList::TLD_LIST) . " IANA TLDs\n";
echo "There are " . count(TldEnum::TLD_ENUM) . " IANA TLDs\n";
$tldCheck = "com"; $tldCheck = "com";
echo "Is '$tldCheck' a real TLD?\n"; echo "Is '$tldCheck' a real TLD?\n";
if (in_array(strtolower($tldCheck), TldEnum::TLD_ENUM)) { if (in_array(strtolower($tldCheck), TldList::TLD_LIST)) {
echo " yes\n"; echo " yes\n";
} else { } else {
echo " no\n"; echo " no\n";
@ -99,7 +96,7 @@ Additionally, for convenience, some native programming language formats have als
$tldCheck = "somethingWeird"; $tldCheck = "somethingWeird";
echo "Is '$tldCheck' a real TLD?\n"; echo "Is '$tldCheck' a real TLD?\n";
if (in_array(strtolower($tldCheck), TldEnum::TLD_ENUM)) { if (in_array(strtolower($tldCheck), TldList::TLD_LIST)) {
echo " yes\n"; echo " yes\n";
} else { } else {
echo " no\n"; echo " no\n";
@ -108,7 +105,7 @@ Additionally, for convenience, some native programming language formats have als
Should produce the following output... Should produce the following output...
```txt ```txt
There are 1573 IANA TLDs There are 1577 IANA TLDs
Is 'com' a real TLD? Is 'com' a real TLD?
yes yes
Is 'somethingWeird' a real TLD? Is 'somethingWeird' a real TLD?
@ -116,27 +113,72 @@ Additionally, for convenience, some native programming language formats have als
``` ```
## Examples ## Examples
* [php-demo.php](/examples/php-demo.php) * [php-demo.php](/examples/php-demo.php) Demo using the simple array of every TLD in PHP.
* [js-demo.js](/examples/js-demo.js) * [js-demo.js](/examples/js-demo.js) Demo using the simple array of every TLD in JavaScript.
* [php-TldDesc-demo.php](/examples/php-TldDesc-demo.php) Demo using the TLD description hashmap in PHP.
* [php-TldType-demo.php](/examples/php-TldType-demo.php) Demo using the TLD type hashmap in PHP.
* [php-TldInfo-demo.php](/examples/php-TldInfo-demo.php) Demo using the array of TLD info hashmaps in PHP.
* [js-desc-demo.js](/examples/js-desc-demo.js) Demo using the TLD description hashmap in JavaScript.
* [js-type-demo.js](/examples/js-type-demo.js) Demo using the TLD type hashmap in JavaScript.
* [js-info-demo.js](/examples/js-info-demo.js) Demo using the array of TLD info hashmaps in JavaScript.
## TLD List Formats ## TLD List Formats
* **CSV**: [tlds.csv](/tlds.csv) * **CSV**: [tlds.csv](/tlds.csv)
A CSV file providing a row for each TLD with the following three columns: *domain* (TLD), *description*, and *type*. A CSV file providing a row for each TLD with the following three columns: *domain* (TLD), *description*, and *type*.
* **PHP**: [TldEnum.php](/formats/php/TldEnum/TldEnum.php) * **PHP**
* [TldList.php](/formats/php/TldEnum/TldList.php)
A PHP source file providing a class with a constant having an array value comprised of every IANA TLD. A PHP source file providing a class constant array comprised of every IANA TLD.
* **JSON**: [tld-list.json](/formats/json/tld-list.json) * [TldDesc.php](/formats/php/TldEnum/TldDesc.php)
A JSON formatted array comprised of every IANA TLD. A PHP source file providing a class constant assoc array with a key for every IANA TLD and the corresponding TLD's "description" as the value.
* **JavaScript**: [tld-enum.js](/formats/js/tld-enum.js) * [TldType.php](/formats/php/TldEnum/TldType.php)
An export module with a constant having an array value comprised of every IANA TLD. A PHP source file providing a class constant assoc array with a key for every IANA TLD and the corresponding TLD's "type" as the value.
## Updating the TLD lists * [TldInfo.php](/formats/php/TldEnum/TldInfo.php)
A PHP source file providing a class constant array of "info" assoc array elements of every IANA TLD.
* **JSON**
* [tld-list.json](/formats/json/tld-list.json)
A JSON formatted array comprised of every IANA TLD.
* [tld-desc.json](/formats/json/tld-desc.json)
A JSON formatted object with a property for every IANA TLD and the corresponding TLD's "description" as the value.
* [tld-type.json](/formats/json/tld-type.json)
A JSON formatted object with a property for every IANA TLD and the corresponding TLD's "type" as the value.
* [tld-info.json](/formats/json/tld-info.json)
A JSON formatted array of "info" object elements of every IANA TLD.
* **JavaScript**
* [list.js](/formats/js/tld-enum/list.json)
An export module with an array comprised of every IANA TLD.
* [desc.js](/formats/js/tld-enum/desc.json)
An export module with an object containing a property for every IANA TLD and the corresponding TLD's "description" as the value.
* [type.js](/formats/js/tld-enum/type.json)
An export module with an object containing a property for every IANA TLD and the corresponding TLD's "type" as the value.
* [info.js](/formats/js/tld-enum/info.json)
An export module with an array comprised of "info" object elements of every IANA TLD.
## Updating the TLD format files
All [TLD List Formats](#tld-list-formats) can be updated with the latest data from IANA by using the [**TLD Update Utility**](/bin/update-formats.sh). All [TLD List Formats](#tld-list-formats) can be updated with the latest data from IANA by using the [**TLD Update Utility**](/bin/update-formats.sh).
```sh ```sh