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

remark plugin to add a usage example to your readme

  • 6.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-72.47%
Maintainers
5
Weekly downloads
 
Created
Source

remark-usage

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to add a usage example to a readme.

Install

npm:

npm install remark-usage

Usage

This section is rendered by this module from example.js.

Dependencies:

var fs = require('fs')
var remark = require('remark')
var usage = require('remark-usage') // This is changed from `./index.js` to `remark-usage`

Read and parse readme.md:

var readme = fs.readFileSync('readme.md', 'utf-8')
var ast = remark()
  .use(usage)
  .parse(readme)

Log something with a language flag:

[**remark**][remark] plugin to add a [usage][] example to a readme.

Or without language:

## Install

Log something which is never captured:

function neverCalled() {
  console.log('javascript', 'alert("test")')
}

Log something which isn’t captured because it’s not a string.

console.log(this)

API

remark().use(usage[, options])

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.

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 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
options
options.cwd

Path to a directory containing a node module (string?). Used to infer name, main, and example.

options.name

Name of the module (string?). Inferred from package.jsons name property. Used to rewrite require('.') to require('some-name').

options.main

Path to the main script (string?). Resolved from package.jsons main property (or index.js). Used to rewrite require('./index.js') to require('some-name').

options.example

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

Heading to look for (string?, default: 'usage'). Wrapped in new RegExp('^(' + value + ')$', 'i');.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

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

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 16 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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