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

remark-usage

Package Overview
Dependencies
Maintainers
5
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-usage - npm Package Compare versions

Comparing version 6.1.3 to 6.1.4

84

index.js

@@ -24,4 +24,4 @@ 'use strict'

/* List of locations to look for an example. */
var EXAMPLES = [
// List of locations to look for an example.
var examples = [
'docs/example.js',

@@ -34,11 +34,11 @@ 'doc/example.js',

/* Expressions. */
var EXPRESSION_LOG = /(console\.log\()(.+)(\);?)/g
var EXPRESSION_REQUIRE = /(require\()(.+)(\);?)/g
var EXPRESSION_COMMENT = /^(\s*)(\/\/)(\s*)(.+)/
// Expressions.
var expressionLog = /(console\.log\()(.+)(\);?)/g
var expressionRequire = /(require\()(.+)(\);?)/g
var expressionComment = /^(\s*)(\/\/)(\s*)(.+)/
/* Constants. */
var DEFAULT_HEADING = 'usage'
// Constants.
var defaultHeading = 'usage'
/* Post-process the example document. */
// Post-process the example document.
function postprocess(value, logs, options) {

@@ -54,7 +54,7 @@ var tokens = []

EXPRESSION_LOG.lastIndex = 0
match = EXPRESSION_LOG.exec(value)
expressionLog.lastIndex = 0
match = expressionLog.exec(value)
while (match) {
end = EXPRESSION_LOG.lastIndex
end = expressionLog.lastIndex

@@ -80,3 +80,3 @@ content = value.slice(start, end - match[0].length)

start = end
match = EXPRESSION_LOG.exec(value)
match = expressionLog.exec(value)
}

@@ -129,3 +129,3 @@

/* Update the example section. */
// Update the example section.
function usage(options) {

@@ -161,3 +161,3 @@ var settings = {}

} else {
EXAMPLES.some(some)
examples.some(some)
}

@@ -170,3 +170,3 @@

header = toExpression(options.heading || DEFAULT_HEADING)
header = toExpression(options.heading || defaultHeading)

@@ -191,8 +191,8 @@ return transform

/* Construct a transformer based on `options`. */
// Construct a transformer based on `options`.
function runFactory(options) {
return run
/* Add an example section based on a valid example
* JavaScript document to a `Usage` section. */
// Add an example section based on a valid example JavaScript document to a
// `Usage` section.
function run(start, nodes, end) {

@@ -209,5 +209,4 @@ var logs = {}

example +
'`. ' +
'Pass an `example` or use a file at: ' +
EXAMPLES.join(', ')
'`. Pass an `example` or use a file at: ' +
examples.join(', ')
)

@@ -222,3 +221,3 @@ }

/* To Do: better tmp file management. */
// To Do: better tmp file management.
stop = cept(console, 'log', intercept)

@@ -246,3 +245,3 @@

/* Add markdown. */
// Add Markdown.
return [start].concat(postprocess(source, logs, options), end)

@@ -263,19 +262,15 @@

/* Transform a script into an intermediate nodes,
* removes the IDs from `console.log` invocations,
* and resolves the main `require` call. */
// Transform a script into an intermediate nodes, removes the IDs from
// `console.log` calls, and resolves the main `require` call.
function script(source, options) {
var tokens
/* Make sure the require to the main module
* is showed as if it was a require from
* `./node_modules`.
*
* For example, when the example file
* (`test/example.js`) requires the main file (as
* listed in `test/package.json`, `main: "module.js"`)
* as `./module`, it is replaced with `test`. */
source = source.replace(EXPRESSION_REQUIRE, replace)
// Make sure the require to the main module is shown as if it was a require
// from `./node_modules`.
// For example, when the example file (`test/example.js`) requires the main
// file (as listed in `test/package.json`, `main: "module.js"`) as `./module`,
// it is replaced with `test`.
source = source.replace(expressionRequire, replace)
/* Transform comments into markdown: */
// Transform comments into markdown:
tokens = []

@@ -295,3 +290,3 @@

if (options.main === filepath && options.name) {
/* Honour quote style. */
// Honour quote style.
quote = $2.charAt(0)

@@ -306,3 +301,3 @@

function each(line) {
var match = line.match(EXPRESSION_COMMENT)
var match = line.match(expressionComment)

@@ -316,7 +311,7 @@ tokens.push({

/* Preprocess `value` to add IDs to `console.log` invocations. */
// Preprocess `value` to add IDs to `console.log` invocations.
function preprocess(value) {
var index = 0
return value.replace(EXPRESSION_LOG, replace)
return value.replace(expressionLog, replace)

@@ -329,4 +324,3 @@ function replace($0, $1, $2, $3) {

/* Parse markdown into nodes, without positional
* information. */
// Parse Markdown into nodes, without positional information.
function parse(value) {

@@ -336,3 +330,3 @@ return processor.parse(value, {position: false}).children

/* Transform a log into an mdast `code` node. */
// Transform a log into an mdast `code` node.
function log(info) {

@@ -342,5 +336,5 @@ return {type: 'code', lang: info.lang, value: info.value}

/* Transform a string into an applicable expression. */
// Transform a string into an applicable expression.
function toExpression(value) {
return new RegExp('^(' + value + ')$', 'i')
}
{
"name": "remark-usage",
"version": "6.1.3",
"description": "Add a usage example to your README",
"version": "6.1.4",
"description": "remark plugin to add a usage example to your readme",
"license": "MIT",
"keywords": [
"text",
"unified",
"remark",
"plugin",
"mdast",
"markdown",

@@ -16,3 +19,5 @@ "plain",

"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Ben Briggs <beneb.info@gmail.com>",
"Nick Baugh <niftylettuce@gmail.com>"
],

@@ -33,11 +38,11 @@ "files": [

"devDependencies": {
"is-hidden": "^1.0.1",
"is-hidden": "^1.0.0",
"negate": "^1.0.0",
"nyc": "^13.0.0",
"prettier": "^1.14.2",
"nyc": "^14.0.0",
"prettier": "^1.0.0",
"remark": "^10.0.0",
"remark-cli": "^6.0.0",
"remark-preset-wooorm": "^4.0.0",
"remark-preset-wooorm": "^5.0.0",
"tape": "^4.0.0",
"xo": "^0.23.0"
"xo": "^0.24.0"
},

@@ -44,0 +49,0 @@ "scripts": {

@@ -6,13 +6,14 @@ # remark-usage

[![Downloads][downloads-badge]][downloads]
[![Chat][chat-badge]][chat]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
Add a [usage][] example to a README with [**remark**][remark].
[**remark**][remark] plugin to add a [usage][] example to a readme.
## Installation
## Install
[npm][]:
```bash
```sh
npm install remark-usage

@@ -45,3 +46,3 @@ ```

```markdown
Add a [usage][] example to a README with [**remark**][remark].
[**remark**][remark] plugin to add a [usage][] example to a readme.
```

@@ -52,3 +53,3 @@

```
## Installation
## Install
```

@@ -74,20 +75,22 @@

### `remark.use(usage[, options])`
### `remark().use(usage[, options])`
Adds `example.js` to the `Usage` section in a `readme.md`.
Add `example.js` to the `Usage` section in a readme.
Removes the current content between the heading containing the text “usage”,
and the next heading of the same (or higher) depth, and replaces it with
the example.
Removes the current content between the heading containing the text “usage”, and
the next heading of the same (or higher) depth, and replaces it with the
example.
The example is run as JavaScript. Line comments are parsed as Markdown.
The example is run as JavaScript.
Line comments are parsed as Markdown.
Calls to `console.log()` are exposed as code blocks, containing the logged
values (optionally with a language flag).
It’s easiest to check out and compare [`example.js`][example-js] with the
above [Usage][] section.
It’s easiest to check out and compare [`example.js`][example-js] with the above
[Usage][] section.
* Operate this from an npm package, or provide a `cwd`
* Make sure no side effects occur when running `example.js`
* Don’t do weird things. This is mostly regexes
* Don’t do weird things.
This is mostly regexes

@@ -98,34 +101,37 @@ ##### `options`

`string?` — Path to a directory containing a node module. Used to infer `name`,
`main`, and `example`.
Path to a directory containing a node module (`string?`).
Used to infer `name`, `main`, and `example`.
###### `options.name`
`string?` — Name of the module, inferred from `package.json`s `name` property.
Used to rewrite `require('./index.js')` to `require('some-name')`.
Name of the module (`string?`).
Inferred from `package.json`s `name` property.
Used to rewrite `require('.')` to `require('some-name')`.
###### `options.main`
`string?` — Path to the main script. Resolved from `package.json`s `main`
property (or `index.js`). Used to rewrite `require('./index.js')` to
`require('some-name')`.
Path to the main script (`string?`).
Resolved from `package.json`s `main` property (or `index.js`).
Used to rewrite `require('./index.js')` to `require('some-name')`.
###### `options.example`
`string?` — Path to the example script. `remark-usage` checks for
`docs/example.js`, `doc/example.js`, `examples/index.js`, `example/index.js`,
and `example.js`.
Path to the example script (`string?`).
`remark-usage` checks for `docs/example.js`, `doc/example.js`,
`examples/index.js`, `example/index.js`, and `example.js`.
###### `options.heading`
`string?`, default: `'usage'` — Heading to look for, wrapped in
`new RegExp('^(' + value + ')$', 'i');`.
Heading to look for (`string?`, default: `'usage'`).
Wrapped in `new RegExp('^(' + value + ')$', 'i');`.
## Contribute
See [`contributing.md` in `remarkjs/remark`][contributing] for ways to get
started.
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.
This project has a [Code of Conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.

@@ -138,3 +144,3 @@ ## License

[build-badge]: https://img.shields.io/travis/remarkjs/remark-usage.svg
[build-badge]: https://img.shields.io/travis/remarkjs/remark-usage/master.svg

@@ -151,5 +157,5 @@ [build]: https://travis-ci.org/remarkjs/remark-usage

[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-usage.svg
[chat]: https://spectrum.chat/unified/remark
[size]: https://bundlephobia.com/result?p=remark-usage

@@ -162,2 +168,16 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[chat]: https://spectrum.chat/unified/remark
[npm]: https://docs.npmjs.com/cli/install
[health]: https://github.com/remarkjs/.github
[contributing]: https://github.com/remarkjs/.github/blob/master/contributing.md
[support]: https://github.com/remarkjs/.github/blob/master/support.md
[coc]: https://github.com/remarkjs/.github/blob/master/code-of-conduct.md
[license]: license

@@ -167,4 +187,2 @@

[npm]: https://docs.npmjs.com/cli/install
[remark]: https://github.com/remarkjs/remark

@@ -175,5 +193,1 @@

[example-js]: example.js
[contributing]: https://github.com/remarkjs/remark/blob/master/contributing.md
[coc]: https://github.com/remarkjs/remark/blob/master/code-of-conduct.md
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