Comparing version 1.12.0 to 1.13.0-beta.0
26
index.js
@@ -1,8 +0,6 @@ | ||
/*eslint no-var:0, prefer-arrow-callback: 0, object-shorthand: 0 */ | ||
'use strict'; | ||
import Punycode from 'punycode/punycode.js'; | ||
import rules from './data/rules.js'; | ||
var Punycode = require('punycode/'); | ||
var internals = {}; | ||
@@ -12,5 +10,5 @@ | ||
// | ||
// Read rules from file. | ||
// Parse rules from file. | ||
// | ||
internals.rules = require('./data/rules.json').map(function (rule) { | ||
internals.rules = rules.map(function (rule) { | ||
@@ -67,3 +65,3 @@ return { | ||
// | ||
exports.errorCodes = { | ||
export const errorCodes = { | ||
DOMAIN_TOO_SHORT: 'Domain name too short.', | ||
@@ -143,3 +141,3 @@ DOMAIN_TOO_LONG: 'Domain name too long. It should be no more than 255 chars.', | ||
// | ||
exports.parse = function (input) { | ||
export const parse = function (input) { | ||
@@ -165,3 +163,3 @@ if (typeof input !== 'string') { | ||
error: { | ||
message: exports.errorCodes[error], | ||
message: errorCodes[error], | ||
code: error | ||
@@ -257,3 +255,3 @@ } | ||
// | ||
exports.get = function (domain) { | ||
export const get = function (domain) { | ||
@@ -263,3 +261,3 @@ if (!domain) { | ||
} | ||
return exports.parse(domain).domain || null; | ||
return parse(domain).domain || null; | ||
}; | ||
@@ -271,6 +269,8 @@ | ||
// | ||
exports.isValid = function (domain) { | ||
export const isValid = function (domain) { | ||
var parsed = exports.parse(domain); | ||
var parsed = parse(domain); | ||
return Boolean(parsed.domain && parsed.listed); | ||
}; | ||
export default { parse, get, isValid }; |
{ | ||
"name": "psl", | ||
"version": "1.12.0", | ||
"version": "1.13.0-beta.0", | ||
"description": "Domain name parser based on the Public Suffix List", | ||
@@ -9,3 +9,11 @@ "repository": { | ||
}, | ||
"main": "index.js", | ||
"type": "module", | ||
"main": "./dist/psl.cjs", | ||
"exports": { | ||
".": { | ||
"import": "./dist/psl.mjs", | ||
"require": "./dist/psl.cjs" | ||
} | ||
}, | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
@@ -16,6 +24,5 @@ "lint": "eslint .", | ||
"watch": "mocha test/*.spec.js --watch", | ||
"prebuild": "./scripts/update-rules.js", | ||
"build": "browserify ./index.js --standalone=psl > ./dist/psl.js", | ||
"postbuild": "cat ./dist/psl.js | uglifyjs -c -m > ./dist/psl.min.js", | ||
"commit-and-pr": "commit-and-pr", | ||
"update-rules": "./scripts/update-rules.js", | ||
"build": "vite build", | ||
"postbuild": "ln -s ./psl.umd.cjs dist/psl.js && ln -s ./psl.umd.cjs dist/psl.min.js", | ||
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline --format=\"%h %s (%an <%ae>)\"" | ||
@@ -33,13 +40,12 @@ }, | ||
"devDependencies": { | ||
"@playwright/test": "^1.48.2", | ||
"browserify": "^17.0.1", | ||
"browserstack-node-sdk": "^1.34.21", | ||
"chai": "^5.1.2", | ||
"commit-and-pr": "^1.0.4", | ||
"eslint": "^9.14.0", | ||
"JSONStream": "^1.3.5", | ||
"@eslint/js": "^9.15.0", | ||
"@playwright/test": "^1.49.0", | ||
"@types/eslint__js": "^8.42.3", | ||
"browserstack-node-sdk": "^1.34.23", | ||
"eslint": "^9.15.0", | ||
"mocha": "^10.8.2", | ||
"request": "^2.88.2", | ||
"uglify-js": "^3.19.3" | ||
"typescript": "^5.6.3", | ||
"typescript-eslint": "^8.15.0", | ||
"vite": "^5.4.11" | ||
} | ||
} |
111
README.md
@@ -33,18 +33,62 @@ # psl (Public Suffix List) | ||
This module is available both for Node.js and the browser. See below for more | ||
details. | ||
### Node.js | ||
```sh | ||
npm install --save psl | ||
npm install psl | ||
``` | ||
#### ESM | ||
From version `v1.11.0` you can now import `psl` as ESM. | ||
```js | ||
import psl from 'psl'; | ||
``` | ||
#### CommonJS | ||
If your project still uses CommonJS on Node.js v12 or later (with support for | ||
conditional exports), you can continue importing the module like in previous | ||
versions. | ||
```js | ||
const psl = require('psl'); | ||
``` | ||
⚠️ If you are using Node.js v10 or older (😰), you can still use the latest | ||
version of this module, but you will need to import the bundled UMD. | ||
```js | ||
var psl = require('psl/dist/psl.umd.cjs'); | ||
``` | ||
### Browser | ||
Download [psl.min.js](https://raw.githubusercontent.com/lupomontero/psl/main/dist/psl.min.js) | ||
#### Using a bundler | ||
If you are using a bundler to build your app, you should be able to `import` | ||
and/or `require` the module just like in Node.js. | ||
#### ESM (using a CDN) | ||
In modern browsers you can also import the ESM directly from a `CDN`. For | ||
example: | ||
```js | ||
import psl from 'https://unpkg.com/psl@latest/dist/psl.mjs'; | ||
``` | ||
#### UMD / CommonJS | ||
Finally, you can still download [`dist/psl.umd.cjs`](https://raw.githubusercontent.com/lupomontero/psl/main/dist/psl.umd.cjs) | ||
and include it in a script tag. | ||
```html | ||
<script src="psl.min.js"></script> | ||
<script src="psl.umd.cjs"></script> | ||
``` | ||
This script is browserified and wrapped in a [umd](https://github.com/umdjs/umd) | ||
This script is bundled and wrapped in a [umd](https://github.com/umdjs/umd) | ||
wrapper so you should be able to use it standalone or together with a module | ||
@@ -55,4 +99,4 @@ loader. | ||
* https://cdnjs.cloudflare.com/ajax/libs/psl/1.9.0/psl.min.js | ||
* https://unpkg.com/psl@1.9.0/dist/psl.min.js | ||
* https://cdnjs.cloudflare.com/ajax/libs/psl/latest/psl.min.js | ||
* https://unpkg.com/psl@latest/dist/psl.min.js | ||
@@ -71,9 +115,10 @@ ## API | ||
#### Example: | ||
#### Examples | ||
Parse domain without subdomain: | ||
```js | ||
var psl = require('psl'); | ||
import psl from 'psl'; | ||
// Parse domain without subdomain | ||
var parsed = psl.parse('google.com'); | ||
const parsed = psl.parse('google.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -83,5 +128,10 @@ console.log(parsed.sld); // 'google' | ||
console.log(parsed.subdomain); // null | ||
``` | ||
// Parse domain with subdomain | ||
var parsed = psl.parse('www.google.com'); | ||
Parse domain with subdomain: | ||
```js | ||
import psl from 'psl'; | ||
const parsed = psl.parse('www.google.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -91,5 +141,10 @@ console.log(parsed.sld); // 'google' | ||
console.log(parsed.subdomain); // 'www' | ||
``` | ||
// Parse domain with nested subdomains | ||
var parsed = psl.parse('a.b.c.d.foo.com'); | ||
Parse domain with nested subdomains: | ||
```js | ||
import psl from 'psl'; | ||
const parsed = psl.parse('a.b.c.d.foo.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -105,6 +160,6 @@ console.log(parsed.sld); // 'foo' | ||
#### Example: | ||
#### Examples | ||
```js | ||
var psl = require('psl'); | ||
import psl from 'psl'; | ||
@@ -162,3 +217,3 @@ // null input. | ||
```js | ||
var psl = require('psl'); | ||
import psl from 'psl'; | ||
@@ -170,19 +225,17 @@ psl.isValid('google.com'); // true | ||
## Testing and Building | ||
Test are written using [`mocha`](https://mochajs.org/) and can be | ||
run in two different environments: `node` and `phantomjs`. | ||
There are tests both for Node.js and the browser (using [Playwright](https://playwright.dev) | ||
and [BrowserStack](https://www.browserstack.com/)). | ||
```sh | ||
# This will run `eslint`, `mocha` and `karma`. | ||
# Run tests in node. | ||
npm test | ||
# Run tests in browserstack. | ||
npm run test:browserstack | ||
# Individual test environments | ||
# Run tests in node only. | ||
./node_modules/.bin/mocha test | ||
# Run tests in phantomjs only. | ||
./node_modules/.bin/karma start ./karma.conf.js --single-run | ||
# Update rules from publicsuffix.org | ||
npm run update-rules | ||
# Build data (parse raw list) and create dist files | ||
# Build ESM, CJS and UMD and create dist files | ||
npm run build | ||
@@ -193,3 +246,2 @@ ``` | ||
## Acknowledgements | ||
@@ -202,3 +254,2 @@ | ||
## License | ||
@@ -208,3 +259,3 @@ | ||
Copyright (c) 2017 Lupo Montero <lupomontero@gmail.com> | ||
Copyright (c) 2014-2024 Lupo Montero <lupomontero@gmail.com> | ||
@@ -211,0 +262,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
711448
9
13
21307
268
0
Yes