or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

component-manipulation.mdfragment-extensions.mdindex.mdipv6-support.mdjquery-integration.mdnormalization-encoding.mdpath-manipulation.mdquery-management.mdresolution-comparison.mdsecond-level-domains.mdstatic-utilities.mduri-construction.mduri-templates.md

second-level-domains.mddocs/

0

# Second Level Domains

1

2

Support for second-level domain (SLD) detection and extraction with comprehensive country-specific domain knowledge.

3

4

## Capabilities

5

6

### Second Level Domain Detection

7

8

```javascript { .api }

9

/**

10

* Check if domain has a known second-level domain

11

* @param domain - Domain to check

12

* @returns Boolean indicating SLD presence

13

*/

14

SecondLevelDomains.has(domain: string): boolean;

15

16

/**

17

* Check if domain is a known second-level domain

18

* @param domain - Domain to check

19

* @returns Boolean indicating if domain is an SLD

20

*/

21

SecondLevelDomains.is(domain: string): boolean;

22

23

/**

24

* Get second-level domain portion of domain

25

* @param domain - Domain to extract SLD from

26

* @returns SLD portion or null if none

27

*/

28

SecondLevelDomains.get(domain: string): string | null;

29

30

/**

31

* Object containing SLD mappings by top-level domain

32

*/

33

SecondLevelDomains.list: object;

34

35

/**

36

* Restore previous SecondLevelDomains variable

37

* @returns Previous SecondLevelDomains variable value

38

*/

39

SecondLevelDomains.noConflict(): any;

40

```

41

42

**Usage Examples:**

43

44

```javascript

45

// Import SecondLevelDomains module

46

import SecondLevelDomains from 'urijs/src/SecondLevelDomains';

47

48

// Check for second-level domains

49

console.log(SecondLevelDomains.has('bbc.co.uk')); // true

50

console.log(SecondLevelDomains.has('example.com')); // false

51

52

// Check if domain is an SLD

53

console.log(SecondLevelDomains.is('co.uk')); // true

54

console.log(SecondLevelDomains.is('com')); // false

55

56

// Extract SLD portion

57

console.log(SecondLevelDomains.get('bbc.co.uk')); // 'co.uk'

58

console.log(SecondLevelDomains.get('example.com')); // null

59

60

// Various country examples

61

console.log(SecondLevelDomains.get('site.com.au')); // 'com.au'

62

console.log(SecondLevelDomains.get('blog.gov.uk')); // 'gov.uk'

63

console.log(SecondLevelDomains.get('shop.co.jp')); // 'co.jp'

64

65

// Use with URI.js for domain parsing

66

const uri = new URI('http://www.bbc.co.uk/news');

67

console.log(uri.hostname()); // 'www.bbc.co.uk'

68

console.log(uri.domain()); // 'bbc' (excludes SLD)

69

console.log(uri.tld()); // 'co.uk' (includes SLD)

70

console.log(uri.is('sld')); // true

71

72

// Access SLD list directly

73

console.log(SecondLevelDomains.list.uk); // ['co', 'gov', 'ac', ...]

74

console.log(SecondLevelDomains.list.au); // ['com', 'gov', 'edu', ...]

75

```