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.
npm install pslVerified import paths — ran on the pinned version, not inferred.
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.
Ensure you are using `psl@^1.13.0` for consistent ESM and CommonJS support. Check your `package.json` and lock files.
Upgrade to `psl@^1.14.0` or newer to benefit from the substantial performance enhancements.
Regularly update `psl` to the latest minor or patch versions (e.g., `npm update psl` or `yarn upgrade psl`) to incorporate the most recent Public Suffix List rules.
Change `const psl = require('psl');` to `import psl from 'psl';`. Ensure your project's `package.json` or file extension correctly signals ESM if you intend to use `import`.Change `import psl from 'psl';` to `const psl = require('psl');`. If you intend to use ESM, configure your project as a module (e.g., add `"type": "module"` to `package.json` or use `.mjs` file extension).Always check if the result of `psl.parse(domain)` is `null` before attempting to access its properties. For example: `const parsed = psl.parse(domain); if (parsed) { console.log(parsed.tld); } else { console.log('Invalid domain or null input'); }`.No dependency data recorded yet.