Socket
Socket
Sign inDemoInstall

unified

Package Overview
Dependencies
9
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.4.2 to 9.0.0

18

index.js
'use strict'
var bail = require('bail')
var buffer = require('is-buffer')
var extend = require('extend')
var bail = require('bail')
var plain = require('is-plain-obj')
var trough = require('trough')
var vfile = require('vfile')
var trough = require('trough')
var plain = require('is-plain-obj')

@@ -40,3 +41,12 @@ // Expose a frozen processor.

function pipelineStringify(p, ctx) {
ctx.file.contents = p.stringify(ctx.tree, ctx.file)
var result = p.stringify(ctx.tree, ctx.file)
var file = ctx.file
if (result === undefined || result === null) {
// Empty.
} else if (typeof result === 'string' || buffer(result)) {
file.contents = result
} else {
file.result = result
}
}

@@ -43,0 +53,0 @@

{
"name": "unified",
"version": "8.4.2",
"description": "Interface for processing text using syntax trees",
"version": "9.0.0",
"description": "Interface for parsing, inspecting, transforming, and serializing content through syntax trees",
"license": "MIT",
"keywords": [
"unified",
"process",

@@ -12,2 +13,8 @@ "parse",

"stringify",
"serialize",
"ast",
"cst",
"syntax",
"tree",
"content",
"rehype",

@@ -42,2 +49,3 @@ "retext",

"extend": "^3.0.0",
"is-buffer": "^2.0.0",
"is-plain-obj": "^2.0.0",

@@ -49,5 +57,5 @@ "trough": "^1.0.0",

"browserify": "^16.0.0",
"c8": "^6.0.0",
"dtslint": "^2.0.0",
"prettier": "^1.0.0",
"c8": "^7.0.0",
"dtslint": "^3.0.0",
"prettier": "^2.0.0",
"remark-cli": "^7.0.0",

@@ -57,3 +65,3 @@ "remark-preset-wooorm": "^6.0.0",

"tinyify": "^2.0.0",
"xo": "^0.25.0"
"xo": "^0.28.0"
},

@@ -82,7 +90,9 @@ "scripts": {

"rules": {
"guard-for-in": "off",
"import/no-extraneous-dependencies": "off",
"unicorn/prefer-type-error": "off",
"unicorn/prefer-reflect-apply": "off"
"unicorn/prefer-reflect-apply": "off",
"guard-for-in": "off"
},
"ignores": [
"types",
"unified.js"

@@ -93,3 +103,9 @@ ]

"plugins": [
"preset-wooorm"
"preset-wooorm",
[
"toc",
{
"heading": "contents"
}
]
]

@@ -96,0 +112,0 @@ },

@@ -13,4 +13,5 @@ # [![unified][logo]][site]

**unified** is an interface for processing text using syntax trees.
It’s what powers [**remark**][remark], [**retext**][retext], and
[**rehype**][rehype], and allows for processing between formats.
It’s what powers [**remark**][remark] (Markdown), [**retext**][retext] (natural
language), and [**rehype**][rehype] (HTML), and allows for processing between
formats.

@@ -21,10 +22,10 @@ ## Intro

[MDX][] to embed [JSX][], and [Prettier][] to format it.
It’s used in about 300k projects on GitHub and has about 10m downloads each
It’s used in about 350k projects on GitHub and has about 15m downloads each
month on npm: you’re probably using it.
Some notable users are [Node.js][], [ZEIT][], [Netlify][], [GitHub][],
Some notable users are [Node.js][], [ZEIT][], [Netlify][], [GitHub][],
[Mozilla][], [WordPress][], [Adobe][], [Facebook][], [Google][], and many more.
* To read about what we are up to, follow us on [Medium][] and [Twitter][]
* To read about what we are up to, follow us [Twitter][]
* For a less technical and more practical introduction to unified, visit
[`unifiedjs.com`][site] and try its introductory [Guides][]
[`unifiedjs.com`][site] and peruse its [Learn][] section
* Browse [awesome unified][awesome] to find out more about the ecosystem

@@ -34,3 +35,3 @@ * Questions?

* Check out [Contribute][] below to find out how to help out, or become a
backer or sponsor on [Open Collective][collective]
backer or sponsor on [OpenCollective][collective]

@@ -43,24 +44,33 @@ ## Sponsors

<tr valign="top">
<td width="20%" align="center">
<a href="https://zeit.co"><img src="https://avatars1.githubusercontent.com/u/14985020?s=400&v=4"></a>
<br><br>🥇
<a href="https://zeit.co">ZEIT</a>
<td width="33.33%" align="center" colspan="2">
<a href="https://www.gatsbyjs.org">Gatsby</a><br>🥇<br><br>
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=900&v=4"></a>
</td>
<td width="20%" align="center">
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=400&v=4"></a>
<br><br>🥇
<a href="https://www.gatsbyjs.org">Gatsby</a></td>
<td width="20%" align="center">
<a href="https://www.netlify.com"><img src="https://avatars1.githubusercontent.com/u/7892489?s=400&v=4"></a>
<br><br>🥇
<a href="https://www.netlify.com">Netlify</a>
<td width="33.33%" align="center" colspan="2">
<a href="https://zeit.co">ZEIT</a><br>🥇<br><br>
<!--OC has a sharper image-->
<a href="https://zeit.co"><img src="https://images.opencollective.com/zeit/d8a5bee/logo/512.png"></a>
</td>
<td width="20%" align="center">
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=400&v=4"></a>
<br><br>
<a href="https://www.holloway.com">Holloway</a>
<td width="33.33%" align="center" colspan="2">
<a href="https://www.netlify.com">Netlify</a><br>🥇<br><br>
<!--OC has a sharper image-->
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/512.png"></a>
</td>
<td width="20%" align="center">
</tr>
<tr valign="top">
<td width="16.67%" align="center">
<a href="https://www.holloway.com">Holloway</a><br><br><br>
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=300&v=4"></a>
</td>
<td width="16.67%" align="center">
<a href="https://themeisle.com">ThemeIsle</a><br>🥉<br><br>
<a href="https://themeisle.com"><img src="https://twitter-avatar.now.sh/themeisle"></a>
</td>
<td width="16.67%" align="center">
<a href="https://boostio.co">BoostIO</a><br>🥉<br><br>
<a href="https://boostio.co"><img src="https://avatars1.githubusercontent.com/u/13612118?s=300&v=4"></a>
</td>
<td width="50%" align="center" colspan="3">
<br><br><br><br>
<a href="https://opencollective.com/unified"><strong>You?</strong>
<a href="https://opencollective.com/unified"><strong>You?</strong></a>
</td>

@@ -70,4 +80,2 @@ </tr>

[**Read more about the unified collective on Medium »**][announcement]
## Install

@@ -82,4 +90,4 @@

This package comes with types.
If you’re using TypeScript, make sure to also install [`@types/unist`][ts-unist]
and [`@types/vfile`][ts-vfile].
If you’re using TypeScript, make sure to also install
[`@types/unist`][ts-unist].

@@ -103,3 +111,3 @@ ## Use

.use(html)
.process('# Hello world!', function(err, file) {
.process('# Hello world!', function (err, file) {
console.error(report(err || file))

@@ -130,3 +138,3 @@ console.log(String(file))

## Table of Contents
## Contents

@@ -156,3 +164,3 @@ * [Description](#description)

**unified** is an interface for processing text using syntax trees.
Syntax trees are a representation understandable to programs.
Syntax trees are a representation of text understandable to programs.
Those programs, called [*plugin*][plugin]s, take these trees and inspect and

@@ -187,3 +195,3 @@ modify them.

When processors are exposed from a module (for example, `unified` itself) they
should not be configured directly, as that would change their behaviour for all
should not be configured directly, as that would change their behavior for all
module users.

@@ -204,8 +212,9 @@ Those processors are [*frozen*][freeze] and they should be called to create a

* [**nlcst**][nlcst] — Natural language
* [**xast**][xast] — XML
###### List of Processors
###### List of processors
The following projects process different [*syntax tree*][syntax-tree] formats.
They parse text to a syntax tree and compile that back to text.
These processors can be used as is, or their parser and stringifier can be mixed
These processors can be used as is, or their parser and compiler can be mixed
and matched with **unified** and plugins to process between different syntaxes.

@@ -217,3 +226,3 @@

###### List of Plugins
###### List of plugins

@@ -225,2 +234,4 @@ The below [**plugins**][plugin] work with **unified**, on all [*syntax

— Ignore messages for unchanged lines in Travis
* [`unified-message-control`](https://github.com/unifiedjs/unified-message-control)
— Enable, disable, and ignore messages

@@ -271,11 +282,6 @@ See [**remark**][remark-plugins], [**rehype**][rehype-plugins], and

.use(styleGuide)
.use(
remark2retext,
unified()
.use(english)
.use(equality)
)
.use(remark2retext, unified().use(english).use(equality))
.use(remark2rehype)
.use(html)
.process('*Emphasis* and _stress_, you guys!', function(err, file) {
.process('*Emphasis* and _stress_, you guys!', function (err, file) {
console.error(report(err || file))

@@ -346,5 +352,3 @@ console.log(String(file))

function onconcat(buf) {
var doc = remark()
.processSync(buf)
.toString()
var doc = remark().processSync(buf).toString()

@@ -360,2 +364,6 @@ process.stdout.write(doc)

If the processor is already using this plugin, the previous plugin configuration
is changed based on the options that are passed in.
The plugin is not added a second time.
###### Signatures

@@ -395,14 +403,13 @@

// Plugin with options:
.use(plugin, {})
.use(pluginA, {x: true, y: true})
// Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
.use(pluginA, {y: false, z: true})
// Plugins:
.use([plugin, pluginB])
.use([pluginB, pluginC])
// Two plugins, the second with options:
.use([plugin, [pluginB, {}]])
.use([pluginD, [pluginE, {}]])
// Preset with plugins and settings:
.use({plugins: [plugin, [pluginB, {}]], settings: {position: false}})
.use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
// Settings only:
.use({settings: {position: false}})
function plugin() {}
function pluginB() {}
```

@@ -438,5 +445,3 @@

var tree = unified()
.use(markdown)
.parse('# Hello world!')
var tree = unified().use(markdown).parse('# Hello world!')

@@ -449,11 +454,12 @@ console.log(tree)

```js
{ type: 'root',
children:
[ { type: 'heading',
depth: 1,
children: [Array],
position: [Position] } ],
position:
{ start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 15, offset: 14 } } }
{
type: 'root',
children: [
{type: 'heading', depth: 1, children: [Array], position: [Position]}
],
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 15, offset: 14}
}
}
```

@@ -477,7 +483,7 @@

Stringify a [*syntax tree*][syntax-tree] to text.
Compile a [*syntax tree*][syntax-tree].
###### Parameters
* `node` ([`Node`][node]) — [*Syntax tree*][syntax-tree] to stringify
* `node` ([`Node`][node]) — [*Syntax tree*][syntax-tree] to compile
* `file` ([`VFile`][vfile], optional) — [*File*][file], any value accepted by

@@ -488,3 +494,3 @@ `vfile()`

`string` (see notes) — Textual representation of the [*syntax
`string` or `Buffer` (see notes) — Textual representation of the [*syntax
tree*][syntax-tree]

@@ -499,6 +505,7 @@

Be aware that [*compiler*][compiler]s typically, but not always, return
`string`.
unified typically compiles by serializing: most [*compiler*][compiler]s return
`string` (or `Buffer`).
Some compilers, such as the one configured with [`rehype-react`][rehype-react],
return other values (in this case, a React tree).
If you’re using a compiler doesn’t serialize, expect different result values.
When using TypeScript, cast the type on your side.

@@ -508,3 +515,3 @@

The below example shows how `stringify` can be used to stringify a syntax tree.
The below example shows how `stringify` can be used to serialize a syntax tree.

@@ -518,5 +525,3 @@ ```js

var doc = unified()
.use(html)
.stringify(tree)
var doc = unified().use(html).stringify(tree)

@@ -598,3 +603,3 @@ console.log(doc)

.use(references)
.run(tree, function(err, tree) {
.run(tree, function (err, tree) {
if (err) throw err

@@ -608,9 +613,9 @@ console.log(tree)

```js
{ type: 'root',
children:
[ { type: 'paragraph', children: [Array] },
{ type: 'definition',
identifier: '1',
title: undefined,
url: undefined } ] }
{
type: 'root',
children: [
{type: 'paragraph', children: [Array]},
{type: 'definition', identifier: '1', title: undefined, url: undefined}
]
}
```

@@ -656,4 +661,4 @@

The parsed, transformed, and stringified value is exposed on
[`file.contents`][vfile-contents].
The parsed, transformed, and compiled value is exposed on
[`file.contents`][vfile-contents] or `file.result` (see notes).

@@ -673,2 +678,10 @@ ###### Note

unified typically compiles by serializing: most [*compiler*][compiler]s return
`string` (or `Buffer`).
Some compilers, such as the one configured with [`rehype-react`][rehype-react],
return other values (in this case, a React tree).
If you’re using a compiler that serializes, the result is available at
`file.contents`.
Otherwise, the result is available at `file.result`.
###### Example

@@ -695,6 +708,6 @@

.then(
function(file) {
function (file) {
console.log(String(file))
},
function(err) {
function (err) {
console.error(String(err))

@@ -747,3 +760,3 @@ }

.use(stringify)
.process('@wooorm', function(err, file) {
.process('@wooorm', function (err, file) {
console.error(report(err || file))

@@ -779,2 +792,5 @@ console.log(String(file))

The parsed, transformed, and compiled value is exposed on
[`file.contents`][vfile-contents] or `file.result` (see notes).
###### Note

@@ -787,8 +803,9 @@

Be aware that [*compiler*][compiler]s typically, but not always, return
`string`.
unified typically compiles by serializing: most [*compiler*][compiler]s return
`string` (or `Buffer`).
Some compilers, such as the one configured with [`rehype-react`][rehype-react],
return other values (in this case, a React tree).
When using TypeScript, cast the type of [`file.contents`][vfile-contents] on
your side.
If you’re using a compiler that serializes, the result is available at
`file.contents`.
Otherwise, the result is available at `file.result`.

@@ -914,6 +931,3 @@ ###### Example

module.exports = unified()
.use(parse)
.use(stringify)
.freeze()
module.exports = unified().use(parse).use(stringify).freeze()
```

@@ -935,3 +949,3 @@

frozen rehype interface because it does not call `rehype`.
If this behaviour was allowed it would result in unexpected behaviour so an
If this behavior was allowed it would result in unexpected behavior so an
error is thrown.

@@ -974,3 +988,3 @@ **This is invalid**:

Plugins are a concept.
They materialise as [`attacher`][attacher]s.
They materialize as [`attacher`][attacher]s.

@@ -1004,3 +1018,3 @@ ###### Example

```markdown
# Hello, World!
# Hello, world!
```

@@ -1024,3 +1038,3 @@

.use(stringify)
.process(vfile.readSync('index.md'), function(err, file) {
.process(vfile.readSync('index.md'), function (err, file) {
console.error(report(err || file))

@@ -1042,3 +1056,3 @@ if (file) {

```html
<h1>Hello, World!</h1>
<h1>Hello, world!</h1>
```

@@ -1048,3 +1062,3 @@

**Attachers** are materialised [*plugin*][plugin]s.
**Attachers** are materialized [*plugin*][plugin]s.
An attacher is a function that can receive options and

@@ -1139,7 +1153,7 @@ [*configures*][configuration] the processor.

```markdown
# Hello, World!
# Hello, world!
_Emphasis_ and **importance**.
## Table of Contents
## Table of contents

@@ -1161,3 +1175,3 @@ ## API

.use(preset)
.process(vfile.readSync('readme.md'), function(err, file) {
.process(vfile.readSync('readme.md'), function (err, file) {
console.error(report(err || file))

@@ -1180,7 +1194,7 @@

```markdown
# Hello, World!
# Hello, world!
*Emphasis* and **importance**.
## Table of Contents
## Table of contents

@@ -1207,4 +1221,4 @@ * [API](#api)

This project has a [Code of Conduct][coc].
By interacting with this repository, organisation, or community you agree to
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

@@ -1281,13 +1295,7 @@

[ts-vfile]: https://www.npmjs.com/package/@types/vfile
[site]: https://unifiedjs.com
[medium]: https://medium.com/unifiedjs
[announcement]: https://medium.com/unifiedjs/collectively-evolving-through-crowdsourcing-22c359ea95cc
[twitter]: https://twitter.com/unifiedjs
[guides]: https://unifiedjs.com/#guides
[learn]: https://unifiedjs.com/learn/

@@ -1308,2 +1316,4 @@ [spectrum]: https://spectrum.chat/unified

[xast]: https://github.com/syntax-tree/xast
[unist]: https://github.com/syntax-tree/unist

@@ -1310,0 +1320,0 @@

@@ -292,5 +292,6 @@ // TypeScript Version: 3.4

*/
interface Attacher<S extends any[] = [Settings?], P = Settings> {
(this: Processor<P>, ...settings: S): Transformer | void
}
type Attacher<S extends any[] = [Settings?], P = Settings> = (
this: Processor<P>,
...settings: S
) => Transformer | void

@@ -312,9 +313,11 @@ /**

*/
interface Transformer {
(
node: Node,
file: VFile,
next?: (error: Error | null, tree: Node, file: VFile) => {}
): Error | Node | Promise<Node> | void | Promise<void>
}
type Transformer = (
node: Node,
file: VFile,
next?: (
error: Error | null,
tree: Node,
file: VFile
) => Record<string, unknown>
) => Error | Node | Promise<Node> | void | Promise<void>

@@ -337,11 +340,3 @@ /**

*/
interface ParserConstructor {
/**
* Creates a Parser
*
* @param text Text to transform into AST node(s)
* @param file File associated with text
*/
new (text: string, file: VFile): Parser
}
type ParserConstructor = new (text: string, file: VFile) => Parser

@@ -373,11 +368,3 @@ /**

*/
interface CompilerConstructor {
/**
* Creates a Compiler
*
* @param node Node/tree to be stringified
* @param file File associated with node
*/
new (node: Node, file: VFile): Compiler
}
type CompilerConstructor = new (node: Node, file: VFile) => Compiler

@@ -384,0 +371,0 @@ /**

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc