Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

retext

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retext - npm Package Compare versions

Comparing version 0.3.0-rc.1 to 0.3.0-rc.2

84

index.js

@@ -9,3 +9,3 @@ 'use strict';

/**
* Module dependencies.
* Dependencies.
*/

@@ -37,2 +37,4 @@

self.plugins = [];
self.ware = new Ware();

@@ -53,5 +55,13 @@ self.parser = parser;

*
* When `parse` or `run` is invoked, `plugin` is
* invoked with `node` and a `retext` instance.
* When `use` is called, the `plugin` is invoked with
* the retext instance and an `options` object.
* Code to initialize `plugin` should go here, such as
* functionality to modify the object model (TextOM),
* the parser (e.g., `parse-latin`), or the `retext`
* instance itsekf.
*
* Optionally `plugin` can return a function which is
* called every time the user invokes `parse` or `run`.
* When that happends, that function is invoked with
* a `Node` and an `options` object.
* If `plugin` contains asynchronous functionality, it

@@ -61,21 +71,9 @@ * should accept a third argument (`next`) and invoke

*
* `plugin.attach` is invoked with a `retext` instance
* when attached, enabling `plugin` to depend on other
* plugins.
*
* Code to initialize `plugin` should go into its `attach`
* method, such as functionality to modify the object model
* (TextOM), the parser (e.g., `parse-latin`), or the
* `retext` instance. `plugin.attach` is invoked when
* `plugin` is attached to a `retext` instance.
*
* @param {function(Node, Retext, Function?)} plugin -
* functionality to analyze and manipulate a node.
* @param {function(Retext)} plugin.attach - functionality
* to initialize `plugin`.
* @param {function(Retext, Object): function(Node, Object, Function?)} plugin
* @return this
*/
Retext.prototype.use = function (plugin) {
var self;
Retext.prototype.use = function (plugin, options) {
var self,
onparse;

@@ -89,9 +87,29 @@ if (typeof plugin !== 'function') {

if (typeof plugin.attach === 'function') {
throw new TypeError(
'Illegal invocation: `' + plugin + '` ' +
'is not a valid argument for ' +
'`Retext#use(plugin)`.\n' +
'This breaking change, the removal of ' +
'`attach`, occurred in 0.3.0-rc.2, see ' +
'GitHub for more information.'
);
}
self = this;
if (self.ware.fns.indexOf(plugin) === -1) {
self.ware.use(plugin);
/**
* Ware does not know which plugins are attached,
* only which `onrun` methods are. Thus, we have
* a custom list of `plugins`, and here we check
* against that.
*/
if (plugin.attach) {
plugin.attach(self);
if (self.plugins.indexOf(plugin) === -1) {
self.plugins.push(plugin);
onparse = plugin(self, options || {});
if (typeof onparse === 'function') {
self.ware.use(onparse);
}

@@ -110,2 +128,3 @@ }

* @param {string?} value - The value to transform.
* @param {Object} [options={}] - Optional settings.
* @param {function(Error, Node)} done - Callback to

@@ -116,6 +135,11 @@ * invoke when the transformations have completed.

Retext.prototype.parse = function (value, done) {
Retext.prototype.parse = function (value, options, done) {
var self,
nlcst;
if (!done) {
done = options;
options = null;
}
if (typeof done !== 'function') {

@@ -134,3 +158,3 @@ throw new TypeError(

self.run(nlcstToTextOM(self.TextOM, nlcst), done);
self.run(nlcstToTextOM(self.TextOM, nlcst), options, done);

@@ -147,2 +171,3 @@ return self;

* plugins to.
* @param {Object} [options={}] - Optional settings.
* @param {function(Error, Node)} done - Callback to

@@ -153,5 +178,10 @@ * invoke when the transformations have completed.

Retext.prototype.run = function (node, done) {
Retext.prototype.run = function (node, options, done) {
var self;
if (!done) {
done = options;
options = null;
}
if (typeof done !== 'function') {

@@ -169,3 +199,3 @@ throw new TypeError(

self.ware.run(node, self, done);
self.ware.run(node, options, done);

@@ -172,0 +202,0 @@ return self;

{
"name": "retext",
"version": "0.3.0-rc.1",
"version": "0.3.0-rc.2",
"description": "Extensible system for analysing and manipulating natural language",

@@ -27,7 +27,7 @@ "license": "MIT",

"devDependencies": {
"eslint": "^0.8.0",
"eslint": "^0.9.0",
"istanbul": "^0.3.0",
"jscs": "^1.7.0",
"matcha": "^0.5.0",
"mocha": "^1.21.0"
"mocha": "^2.0.0"
},

@@ -38,5 +38,5 @@ "scripts": {

"lint": "npm run-script lint-api && npm run-script lint-test && npm run-script lint-benchmark && npm run-script lint-style",
"lint-api": "node_modules/.bin/eslint index.js --env node --env browser --rule 'quotes: [2, single]'",
"lint-test": "node_modules/.bin/eslint test.js --env node --env mocha --rule 'quotes: [2, single]'",
"lint-benchmark": "node_modules/.bin/eslint benchmark.js --env node --global suite,set,bench --rule 'quotes: [2, single]'",
"lint-api": "node_modules/.bin/eslint index.js --env node --env browser",
"lint-test": "node_modules/.bin/eslint test.js --env node --env mocha",
"lint-benchmark": "node_modules/.bin/eslint benchmark.js --env node --global suite,set,bench",
"lint-style": "node_modules/.bin/jscs index.js test.js benchmark.js --reporter=inline",

@@ -43,0 +43,0 @@ "coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -- test.js",

@@ -97,9 +97,10 @@ # ![Retext logo](http://i58.tinypic.com/5xpx5z.png)

### Retext#use(plugin)
### Retext#use(function(Retext, Object), options?)
Takes a pluginβ€”a humble function. When `Retext#parse()` is invoked, the plugin will be invoked with the parsed tree, and the **Retext** instance as arguments. Returns self.
Takes a pluginβ€”a humble function to transform the object model.
Can return a function (`function(Node, Object, next)`) which is given the document as created by `Retext#parse()` before its given to the user.
### Retext#parse(value, function(Error, Node))
### Retext#parse(value, options?, function(Error, Node))
Parses the given source and when done passes either an error (the first argument), or the (by `use`d plugins, modified) tree (the second argument) to the callback.
Parses the given source and, when done, passes either an error (the first argument), or the (by `use`d plugins, modified) document (the second argument) to the callback.

@@ -120,2 +121,3 @@ ## Plugins

- [retext-link](https://github.com/wooorm/retext-link) β€” (**[demo](http://wooorm.github.io/retext-link/)**) β€” Detect links in text;
- [retext-live](https://github.com/wooorm/retext-live) β€” Change a node based on a (new?) value;
- [retext-metaphone](https://github.com/wooorm/retext-metaphone) β€” (**[demo](http://wooorm.github.io/retext-metaphone/)**) β€” Implementation of the Metaphone algorithm;

@@ -141,3 +143,3 @@ - [retext-porter-stemmer](https://github.com/wooorm/retext-porter-stemmer) β€” (**[demo](http://wooorm.github.io/retext-porter-stemmer/)**) β€” Implementation of [the Porter stemming algorithm](http://tartarus.org/martin/PorterStemmer/);

- retext-frequent-words β€” Like **retext-keywords**, but based on frequency and stop-words instead of a POS-tagger;
- retext-live β€” Detect changes in a textarea (contenteditable?), sync the diffs over to a **retext** tree, let plugins modify the content, and sync the diffs back to the textarea;
- retext-hyphen β€” Insert soft-hyphens where needed; this might have to be implemented with some sort of node which doesn't stringify;
- retext-location β€” Track the position of nodes (line, column);

@@ -149,3 +151,5 @@ - retext-no-pants β€” Opposite of **retext-smartypants**;

- retext-summary β€” Summarise text;
- retraverse β€” Like Estraverse;
- retext-sync β€” Detect changes in a textarea (or contenteditable?), sync the diffs over to a **retext** tree, let plugins modify the content, and sync the diffs back to the textarea;
- retext-typography β€” Applies typographic enhancements, like (or using?) retext-smartypants and retext-hyphen;
- retraverse β€” Like Estraverse.

@@ -152,0 +156,0 @@ ## Parsers

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