Download wp-calypso/client/lib/domains/get-tld.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/domains/get-tld.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/domains/get-tld.js
-
curl -L -o get-tld.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/domains/get-tld.js
1.03 kB
| import wpcomMultiLevelTlds from './tlds/wpcom-multi-level-tlds.json'; | |
| import { parseDomainAgainstTldList } from './utils'; | |
| /** | |
| * Parse the tld from a given domain name, semi-naively. The function | |
| * first parses against a list of tlds that have been sold on WP.com | |
| * and falls back to a simplistic "everything after the last dot" approach | |
| * if the list of explicitly allowed tlds failed. This is ultimately not comprehensive as that | |
| * is a poor base assumption (lots of second level tlds, etc). However, | |
| * for our purposes, the approach should be "good enough" for a long time. | |
| * @param {string} domainName The domain name parse the tld from | |
| * @returns {string} The TLD or an empty string | |
| */ | |
| export function getTld( domainName ) { | |
| const lastIndexOfDot = domainName.lastIndexOf( '.' ); | |
| if ( lastIndexOfDot === -1 ) { | |
| return ''; | |
| } | |
| let tld = parseDomainAgainstTldList( domainName, wpcomMultiLevelTlds ); | |
| if ( ! tld ) { | |
| tld = domainName.substring( lastIndexOfDot + 1 ); | |
| } | |
| return tld; | |
| } | |