Socket
Socket
Sign inDemoInstall

@mozilla/readability

Package Overview
Dependencies
Maintainers
14
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mozilla/readability - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

CHANGELOG.md

11

package.json
{
"name": "@mozilla/readability",
"version": "0.3.0",
"version": "0.4.0",
"description": "A standalone version of the readability library used for Firefox Reader View.",

@@ -11,3 +11,4 @@ "main": "index.js",

"perf": "matcha benchmarks/benchmarks.js",
"perf-reference": "READABILITY_PERF_REFERENCE=1 matcha --reporter ./benchmarks/benchmark-reporter.js benchmarks/benchmarks.js"
"perf-reference": "READABILITY_PERF_REFERENCE=1 matcha --reporter ./benchmarks/benchmark-reporter.js benchmarks/benchmarks.js",
"release": "release-it"
},

@@ -28,11 +29,13 @@ "repository": {

"devDependencies": {
"@release-it/keep-a-changelog": "^2.2.2",
"chai": "^2.1.*",
"eslint": ">=4.2",
"htmltidy2": "^0.3.0",
"js-beautify": "^1.5.5",
"js-beautify": "^1.13.0",
"jsdom": "^13.1",
"matcha": "^0.6.0",
"mocha": "^2.2.*",
"mocha": "^8.2.0",
"release-it": "^14.2.2",
"sinon": "^7.3.2"
}
}

@@ -40,10 +40,18 @@ /* eslint-env es6:false */

* Decides whether or not the document is reader-able without parsing the whole thing.
*
* @return boolean Whether or not we suspect Readability.parse() will suceeed at returning an article object.
* @param {Object} options Configuration object.
* @param {number} [options.minContentLength=140] The minimum node content length used to decide if the document is readerable.
* @param {number} [options.minScore=20] The minumum cumulated 'score' used to determine if the document is readerable.
* @param {Function} [options.visibilityChecker=isNodeVisible] The function used to determine if a node is visible.
* @return {boolean} Whether or not we suspect Readability.parse() will suceeed at returning an article object.
*/
function isProbablyReaderable(doc, isVisible) {
if (!isVisible) {
isVisible = isNodeVisible;
function isProbablyReaderable(doc, options = {}) {
// For backward compatibility reasons 'options' can either be a configuration object or the function used
// to determine if a node is visible.
if (typeof options == "function") {
options = { visibilityChecker: options };
}
var defaultOptions = { minScore: 20, minContentLength: 140, visibilityChecker: isNodeVisible };
options = Object.assign(defaultOptions, options);
var nodes = doc.querySelectorAll("p, pre");

@@ -61,3 +69,3 @@

var set = new Set(nodes);
[].forEach.call(brNodes, function(node) {
[].forEach.call(brNodes, function (node) {
set.add(node.parentNode);

@@ -71,5 +79,6 @@ });

// this callback:
return [].some.call(nodes, function(node) {
if (!isVisible(node))
return [].some.call(nodes, function (node) {
if (!options.visibilityChecker(node)) {
return false;
}

@@ -87,9 +96,9 @@ var matchString = node.className + " " + node.id;

var textContentLength = node.textContent.trim().length;
if (textContentLength < 140) {
if (textContentLength < options.minContentLength) {
return false;
}
score += Math.sqrt(textContentLength - 140);
score += Math.sqrt(textContentLength - options.minContentLength);
if (score > 20) {
if (score > options.minScore) {
return true;

@@ -96,0 +105,0 @@ }

@@ -17,2 +17,3 @@ # Readability.js

* `content`: HTML string of processed article content
* `textContent`: text content of the article (all HTML removed)
* `length`: length of an article, in characters

@@ -88,40 +89,4 @@ * `excerpt`: article description, or short excerpt from the content

[![Build Status](https://travis-ci.org/mozilla/readability.svg?branch=master)](https://travis-ci.org/mozilla/readability)
Please see our [Contributing](CONTRIBUTING.md) document.
For outstanding issues, see the issue list in this repo, as well as this [bug list](https://bugzilla.mozilla.org/buglist.cgi?component=Reader%20Mode&product=Toolkit&bug_status=__open__&limit=0).
Any changes to Readability.js itself should be reviewed by an [appropriate Firefox/toolkit peer](https://wiki.mozilla.org/Modules/Firefox), such as [@gijsk](https://github.com/gijsk), since these changes will be merged to mozilla-central and shipped in Firefox.
To test local changes to Readability.js, you can use the [automated tests](#tests). There's a [node script](https://github.com/mozilla/readability/blob/master/test/generate-testcase.js) to help you create new ones.
## Tests
Please run [eslint](http://eslint.org/) as a first check that your changes are valid JS and adhere to our style guidelines.
To run the test suite:
$ mocha test/test-*.js
To run a specific test page by its name:
$ mocha test/test-*.js -g 001
To run the test suite in TDD mode:
$ mocha test/test-*.js -w
Combo time:
$ mocha test/test-*.js -w -g 001
## Benchmarks
Benchmarks for all test pages:
$ npm run perf
Reference benchmark:
$ npm run perf-reference
## License

@@ -128,0 +93,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc