{"id":13527262,"url":"https://github.com/lupomontero/psl","last_synced_at":"2025-05-13T20:21:02.313Z","repository":{"id":21859094,"uuid":"25182475","full_name":"lupomontero/psl","owner":"lupomontero","description":"JavaScript domain name parser based on the Public Suffix List","archived":false,"fork":false,"pushed_at":"2025-04-11T14:21:22.000Z","size":2118,"stargazers_count":407,"open_issues_count":22,"forks_count":80,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-28T11:55:02.389Z","etag":null,"topics":["domain-name","domain-parser","javascript","public-suffix-list"],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/psl","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lupomontero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["lupomontero"],"tidelift":"npm/psl"}},"created_at":"2014-10-13T23:41:02.000Z","updated_at":"2025-04-06T12:19:40.000Z","dependencies_parsed_at":"2024-09-20T00:01:25.475Z","dependency_job_id":"82972b97-20ad-4595-85a4-b9ebfadc09e7","html_url":"https://github.com/lupomontero/psl","commit_stats":{"total_commits":241,"total_committers":7,"mean_commits":34.42857142857143,"dds":0.07468879668049788,"last_synced_commit":"b7c43bcce4fae13e1a8da91db97c75246818ec94"},"previous_names":["wrangr/psl"],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupomontero%2Fpsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupomontero%2Fpsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupomontero%2Fpsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupomontero%2Fpsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lupomontero","download_url":"https://codeload.github.com/lupomontero/psl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020682,"owners_count":22000761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-name","domain-parser","javascript","public-suffix-list"],"created_at":"2024-08-01T06:01:44.356Z","updated_at":"2025-05-13T20:21:02.269Z","avatar_url":"https://github.com/lupomontero.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lupomontero","https://tidelift.com/funding/github/npm/psl"],"categories":["JavaScript"],"sub_categories":[],"readme":"# psl (Public Suffix List)\n\n[![Node.js CI](https://github.com/lupomontero/psl/actions/workflows/node.js.yml/badge.svg)](https://github.com/lupomontero/psl/actions/workflows/node.js.yml)\n\n`psl` is a `JavaScript` domain name parser based on the\n[Public Suffix List](https://publicsuffix.org/).\n\nThis implementation is tested against the\n[test data hosted by Mozilla](http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1)\nand kindly provided by [Comodo](https://www.comodo.com/).\n\nCross browser testing provided by\n[\u003cimg alt=\"BrowserStack\" width=\"160\" src=\"./browserstack-logo.svg\" /\u003e](https://www.browserstack.com/)\n\n## What is the Public Suffix List?\n\nThe Public Suffix List is a cross-vendor initiative to provide an accurate list\nof domain name suffixes.\n\nThe Public Suffix List is an initiative of the Mozilla Project, but is\nmaintained as a community resource. It is available for use in any software,\nbut was originally created to meet the needs of browser manufacturers.\n\nA \"public suffix\" is one under which Internet users can directly register names.\nSome examples of public suffixes are \".com\", \".co.uk\" and \"pvt.k12.wy.us\". The\nPublic Suffix List is a list of all known public suffixes.\n\nSource: http://publicsuffix.org\n\n## Installation\n\nThis module is available both for Node.js and the browser. See below for more\ndetails.\n\n### Node.js\n\nThis module is tested on Node.js v8, v10, v12, v14, v16, v18, v20 and v22. See\n[`.github/workflows/node.js.yml`](.github/workflows/node.js.yml).\n\n```sh\nnpm install psl\n```\n\n#### ESM\n\nFrom version `v1.13.0` you can now import `psl` as ESM.\n\n```js\nimport psl from 'psl';\n```\n\n#### CommonJS\n\nIf your project still uses CommonJS, you can continue importing the module like\nin previous versions.\n\n```js\nconst psl = require('psl');\n```\n\n### Browser\n\n#### Using a bundler\n\nIf you are using a bundler to build your app, you should be able to `import`\nand/or `require` the module just like in Node.js.\n\n#### ESM (using a CDN)\n\nIn modern browsers you can also import the ESM directly from a `CDN`. For\nexample:\n\n```js\nimport psl from 'https://unpkg.com/psl@latest/dist/psl.mjs';\n```\n\n#### UMD / CommonJS\n\nFinally, you can still download [`dist/psl.umd.cjs`](https://raw.githubusercontent.com/lupomontero/psl/main/dist/psl.umd.cjs)\nand include it in a script tag.\n\n```html\n\u003cscript src=\"psl.umd.cjs\"\u003e\u003c/script\u003e\n```\n\nThis script is bundled and wrapped in a [umd](https://github.com/umdjs/umd)\nwrapper so you should be able to use it standalone or together with a module\nloader.\n\nThe script is also available on most popular CDNs. For example:\n\n* https://unpkg.com/psl@latest/dist/psl.umd.cjs\n\n## API\n\n### `psl.parse(domain)`\n\nParse domain based on Public Suffix List. Returns an `Object` with the following\nproperties:\n\n* `tld`: Top level domain (this is the _public suffix_).\n* `sld`: Second level domain (the first private part of the domain name).\n* `domain`: The domain name is the `sld` + `tld`.\n* `subdomain`: Optional parts left of the domain.\n\n#### Examples\n\nParse domain without subdomain:\n\n```js\nimport psl from 'psl';\n\nconst parsed = psl.parse('google.com');\nconsole.log(parsed.tld); // 'com'\nconsole.log(parsed.sld); // 'google'\nconsole.log(parsed.domain); // 'google.com'\nconsole.log(parsed.subdomain); // null\n```\n\nParse domain with subdomain:\n\n```js\nimport psl from 'psl';\n\nconst parsed = psl.parse('www.google.com');\nconsole.log(parsed.tld); // 'com'\nconsole.log(parsed.sld); // 'google'\nconsole.log(parsed.domain); // 'google.com'\nconsole.log(parsed.subdomain); // 'www'\n```\n\nParse domain with nested subdomains:\n\n```js\nimport psl from 'psl';\n\nconst parsed = psl.parse('a.b.c.d.foo.com');\nconsole.log(parsed.tld); // 'com'\nconsole.log(parsed.sld); // 'foo'\nconsole.log(parsed.domain); // 'foo.com'\nconsole.log(parsed.subdomain); // 'a.b.c.d'\n```\n\n### `psl.get(domain)`\n\nGet domain name, `sld` + `tld`. Returns `null` if not valid.\n\n#### Examples\n\n```js\nimport psl from 'psl';\n\n// null input.\npsl.get(null); // null\n\n// Mixed case.\npsl.get('COM'); // null\npsl.get('example.COM'); // 'example.com'\npsl.get('WwW.example.COM'); // 'example.com'\n\n// Unlisted TLD.\npsl.get('example'); // null\npsl.get('example.example'); // 'example.example'\npsl.get('b.example.example'); // 'example.example'\npsl.get('a.b.example.example'); // 'example.example'\n\n// TLD with only 1 rule.\npsl.get('biz'); // null\npsl.get('domain.biz'); // 'domain.biz'\npsl.get('b.domain.biz'); // 'domain.biz'\npsl.get('a.b.domain.biz'); // 'domain.biz'\n\n// TLD with some 2-level rules.\npsl.get('uk.com'); // null);\npsl.get('example.uk.com'); // 'example.uk.com');\npsl.get('b.example.uk.com'); // 'example.uk.com');\n\n// More complex TLD.\npsl.get('c.kobe.jp'); // null\npsl.get('b.c.kobe.jp'); // 'b.c.kobe.jp'\npsl.get('a.b.c.kobe.jp'); // 'b.c.kobe.jp'\npsl.get('city.kobe.jp'); // 'city.kobe.jp'\npsl.get('www.city.kobe.jp'); // 'city.kobe.jp'\n\n// IDN labels.\npsl.get('食狮.com.cn'); // '食狮.com.cn'\npsl.get('食狮.公司.cn'); // '食狮.公司.cn'\npsl.get('www.食狮.公司.cn'); // '食狮.公司.cn'\n\n// Same as above, but punycoded.\npsl.get('xn--85x722f.com.cn'); // 'xn--85x722f.com.cn'\npsl.get('xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'\npsl.get('www.xn--85x722f.xn--55qx5d.cn'); // 'xn--85x722f.xn--55qx5d.cn'\n```\n\n### `psl.isValid(domain)`\n\nCheck whether a domain has a valid Public Suffix. Returns a `Boolean` indicating\nwhether the domain has a valid Public Suffix.\n\n#### Example\n\n```js\nimport psl from 'psl';\n\npsl.isValid('google.com'); // true\npsl.isValid('www.google.com'); // true\npsl.isValid('x.yz'); // false\n```\n\n## Testing and Building\n\nThere are tests both for Node.js and the browser (using [Playwright](https://playwright.dev)\nand [BrowserStack](https://www.browserstack.com/)).\n\n```sh\n# Run tests in node.\nnpm test\n# Run tests in browserstack.\nnpm run test:browserstack\n\n# Update rules from publicsuffix.org\nnpm run update-rules\n\n# Build ESM, CJS and UMD and create dist files\nnpm run build\n```\n\nFeel free to fork if you see possible improvements!\n\n## Acknowledgements\n\n* Mozilla Foundation's [Public Suffix List](https://publicsuffix.org/)\n* Thanks to Rob Stradling of [Comodo](https://www.comodo.com/) for providing\n  test data.\n* Inspired by [weppos/publicsuffix-ruby](https://github.com/weppos/publicsuffix-ruby)\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014-2024 Lupo Montero \u003clupomontero@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupomontero%2Fpsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flupomontero%2Fpsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupomontero%2Fpsl/lists"}