Comparing version 1.11.0 to 1.12.0
26
index.js
@@ -1,6 +0,8 @@ | ||
import Punycode from 'punycode/punycode.js'; | ||
/*eslint no-var:0, prefer-arrow-callback: 0, object-shorthand: 0 */ | ||
'use strict'; | ||
import rules from './data/rules.js'; | ||
var Punycode = require('punycode/'); | ||
var internals = {}; | ||
@@ -10,5 +12,5 @@ | ||
// | ||
// Parse rules from file. | ||
// Read rules from file. | ||
// | ||
internals.rules = rules.map(function (rule) { | ||
internals.rules = require('./data/rules.json').map(function (rule) { | ||
@@ -65,3 +67,3 @@ return { | ||
// | ||
export const errorCodes = { | ||
exports.errorCodes = { | ||
DOMAIN_TOO_SHORT: 'Domain name too short.', | ||
@@ -141,3 +143,3 @@ DOMAIN_TOO_LONG: 'Domain name too long. It should be no more than 255 chars.', | ||
// | ||
export const parse = function (input) { | ||
exports.parse = function (input) { | ||
@@ -163,3 +165,3 @@ if (typeof input !== 'string') { | ||
error: { | ||
message: errorCodes[error], | ||
message: exports.errorCodes[error], | ||
code: error | ||
@@ -255,3 +257,3 @@ } | ||
// | ||
export const get = function (domain) { | ||
exports.get = function (domain) { | ||
@@ -261,3 +263,3 @@ if (!domain) { | ||
} | ||
return parse(domain).domain || null; | ||
return exports.parse(domain).domain || null; | ||
}; | ||
@@ -269,8 +271,6 @@ | ||
// | ||
export const isValid = function (domain) { | ||
exports.isValid = function (domain) { | ||
var parsed = parse(domain); | ||
var parsed = exports.parse(domain); | ||
return Boolean(parsed.domain && parsed.listed); | ||
}; | ||
export default { parse, get, isValid }; |
{ | ||
"name": "psl", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Domain name parser based on the Public Suffix List", | ||
@@ -9,10 +9,3 @@ "repository": { | ||
}, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./dist/psl.mjs", | ||
"require": "./dist/psl.cjs" | ||
} | ||
}, | ||
"types": "types/index.d.ts", | ||
"main": "index.js", | ||
"scripts": { | ||
@@ -23,5 +16,6 @@ "lint": "eslint .", | ||
"watch": "mocha test/*.spec.js --watch", | ||
"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", | ||
"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", | ||
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline --format=\"%h %s (%an <%ae>)\"" | ||
@@ -39,12 +33,13 @@ }, | ||
"devDependencies": { | ||
"@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", | ||
"@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", | ||
"mocha": "^10.8.2", | ||
"typescript": "^5.6.3", | ||
"typescript-eslint": "^8.15.0", | ||
"vite": "^5.4.11" | ||
"request": "^2.88.2", | ||
"uglify-js": "^3.19.3" | ||
} | ||
} | ||
} |
111
README.md
@@ -33,62 +33,18 @@ # 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 psl | ||
npm install --save 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 | ||
#### 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) | ||
Download [psl.min.js](https://raw.githubusercontent.com/lupomontero/psl/main/dist/psl.min.js) | ||
and include it in a script tag. | ||
```html | ||
<script src="psl.umd.cjs"></script> | ||
<script src="psl.min.js"></script> | ||
``` | ||
This script is bundled and wrapped in a [umd](https://github.com/umdjs/umd) | ||
This script is browserified 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 | ||
@@ -99,4 +55,4 @@ loader. | ||
* https://cdnjs.cloudflare.com/ajax/libs/psl/latest/psl.min.js | ||
* https://unpkg.com/psl@latest/dist/psl.min.js | ||
* https://cdnjs.cloudflare.com/ajax/libs/psl/1.9.0/psl.min.js | ||
* https://unpkg.com/psl@1.9.0/dist/psl.min.js | ||
@@ -115,10 +71,9 @@ ## API | ||
#### Examples | ||
#### Example: | ||
Parse domain without subdomain: | ||
```js | ||
import psl from 'psl'; | ||
var psl = require('psl'); | ||
const parsed = psl.parse('google.com'); | ||
// Parse domain without subdomain | ||
var parsed = psl.parse('google.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -128,10 +83,5 @@ console.log(parsed.sld); // 'google' | ||
console.log(parsed.subdomain); // null | ||
``` | ||
Parse domain with subdomain: | ||
```js | ||
import psl from 'psl'; | ||
const parsed = psl.parse('www.google.com'); | ||
// Parse domain with subdomain | ||
var parsed = psl.parse('www.google.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -141,10 +91,5 @@ console.log(parsed.sld); // 'google' | ||
console.log(parsed.subdomain); // 'www' | ||
``` | ||
Parse domain with nested subdomains: | ||
```js | ||
import psl from 'psl'; | ||
const parsed = psl.parse('a.b.c.d.foo.com'); | ||
// Parse domain with nested subdomains | ||
var parsed = psl.parse('a.b.c.d.foo.com'); | ||
console.log(parsed.tld); // 'com' | ||
@@ -160,6 +105,6 @@ console.log(parsed.sld); // 'foo' | ||
#### Examples | ||
#### Example: | ||
```js | ||
import psl from 'psl'; | ||
var psl = require('psl'); | ||
@@ -217,3 +162,3 @@ // null input. | ||
```js | ||
import psl from 'psl'; | ||
var psl = require('psl'); | ||
@@ -225,17 +170,19 @@ psl.isValid('google.com'); // true | ||
## Testing and Building | ||
There are tests both for Node.js and the browser (using [Playwright](https://playwright.dev) | ||
and [BrowserStack](https://www.browserstack.com/)). | ||
Test are written using [`mocha`](https://mochajs.org/) and can be | ||
run in two different environments: `node` and `phantomjs`. | ||
```sh | ||
# Run tests in node. | ||
# This will run `eslint`, `mocha` and `karma`. | ||
npm test | ||
# Run tests in browserstack. | ||
npm run test:browserstack | ||
# Update rules from publicsuffix.org | ||
npm run update-rules | ||
# 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 | ||
# Build ESM, CJS and UMD and create dist files | ||
# Build data (parse raw list) and create dist files | ||
npm run build | ||
@@ -246,2 +193,3 @@ ``` | ||
## Acknowledgements | ||
@@ -254,2 +202,3 @@ | ||
## License | ||
@@ -259,3 +208,3 @@ | ||
Copyright (c) 2014-2024 Lupo Montero <lupomontero@gmail.com> | ||
Copyright (c) 2017 Lupo Montero <lupomontero@gmail.com> | ||
@@ -262,0 +211,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
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
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
529162
10
11
21038
2
217
4
No