{"library":"psl","title":"PSL Domain Parser","description":"psl is a JavaScript library designed for parsing domain names based on the widely adopted Public Suffix List (PSL). This list is a community-maintained resource, primarily initiated by the Mozilla Project, which identifies \"public suffixes\"—domain parts under which users can directly register names (e.g., .com, .co.uk, .pvt.k12.wy.us). The library's current stable version is 1.15.0. It receives regular updates to its internal Public Suffix List rules, ensuring accuracy with the latest additions and changes, with the most recent update occurring in v1.15.0 (December 2024). Key differentiators include its adherence to the official PSL, testing against Mozilla's own test data, and significant performance enhancements introduced in v1.14.0 (over 100x improvement for parsing). It provides robust support for both Node.js and browser environments, offering ESM, CommonJS, and UMD distributions, and includes TypeScript type definitions since v1.11.0, making it suitable for modern JavaScript and TypeScript projects.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install psl"],"cli":null},"imports":["import psl from 'psl';","const psl = require('psl');","import type { ParsedDomain } from 'psl';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import psl from 'psl';\n\n// Parse a simple domain\nconst simpleDomain = 'example.com';\nconst parsedSimple = psl.parse(simpleDomain);\nconsole.log(`Parsing \"${simpleDomain}\":`);\nconsole.log(`  TLD: ${parsedSimple.tld}`); // 'com'\nconsole.log(`  SLD: ${parsedSimple.sld}`); // 'example'\nconsole.log(`  Domain: ${parsedSimple.domain}`); // 'example.com'\nconsole.log(`  Subdomain: ${parsedSimple.subdomain}`); // null\n\n// Parse a domain with multiple subdomains\nconst complexDomain = 'a.b.c.foo.co.uk';\nconst parsedComplex = psl.parse(complexDomain);\nconsole.log(`\\nParsing \"${complexDomain}\":`);\nconsole.log(`  TLD: ${parsedComplex.tld}`); // 'co.uk'\nconsole.log(`  SLD: ${parsedComplex.sld}`); // 'foo'\nconsole.log(`  Domain: ${parsedComplex.domain}`); // 'foo.co.uk'\nconsole.log(`  Subdomain: ${parsedComplex.subdomain}`); // 'a.b.c'\n\n// Get just the domain name (SLD + TLD)\nconst domainOnly = psl.get('www.sub.example.net');\nconsole.log(`\\nGetting domain for \"www.sub.example.net\": ${domainOnly}`); // 'example.net'\n\n// Handle invalid or null input for psl.get\nconst invalidDomain = psl.get('invalid');\nconst nullDomain = psl.get(null);\nconsole.log(`Getting domain for \"invalid\": ${invalidDomain}`); // null\nconsole.log(`Getting domain for null: ${nullDomain}`); // null","lang":"typescript","description":"Demonstrates how to parse various domain name structures, extract components (TLD, SLD, subdomain), and retrieve the base domain using `psl.parse()` and `psl.get()`, including handling null inputs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}