remark-license

2018-11-14 admin

remark-license是什么

什么是remark-license,Add a license section to your README

remark-license使用教程帮助文档

remark-license Build Status Coverage Status Chat

Add a license section to a README with remark.

Installation

npm:

npm install remark-license

Usage

Say we have the following file, example.md:

## License

Something nondescript.

And our script, example.js, looks as follows:

var fs = require('fs')
var remark = require('remark')
var license = require('remark-license')

remark()
  .use(license)
  .process(fs.readFileSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

## License

[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)

API

remark.use(license[, options])

Add a license section to heading containing /^licen[cs]e$/i. Replaces the original content of the section. Does nothing when no heading is found. Does nothing when the processed file is the license file (such for a license heading in license.md).

options
options.name

string, optional — License holder. Detected from the package.json in the current working directory, supporting both object and string format of author. Throws when neither given nor detected.

options.license

string, optional — SPDX identifier. Detected from the license field in the package.json in the current working directory. Deprecated license objects are not supported. Throws when neither given nor detected.

options.file

string, optional — File-name of license file. Detected from the files in the current working directory, in which case the first file matching /^licen[cs]e(?=$|\.)/i is used. If there is no given or found license file, but options.license is a known SPDX identifier, the URL to the license on spdx.org is used.

options.url

string, optional — URL to license holder. Detected from the package.json in the current working directory, supporting both object and string format of author. http:// is prepended if url starts without HTTP or HTTPS protocol.

options.ignoreFinalDefinitions

Ignore final definitions otherwise in the section (boolean, default: true).

Detection

Detection of package.json and files in the current working directory is based on the current working directory as set on the given vfile.

If you want to set the cwd yourself (the default is process.cwd()), you can pass in a vfile or vfile options to .process like so:

var fs = require('fs')
var path = require('path')
var remark = require('remark')
var license = require('remark-license')

remark()
  .use(license)
  .process(
    {
      cwd: path.join('.', 'some', 'path', 'to', 'a', 'directory'),
      contents: fs.readFileSync('example.md')
    },
    function(err, file) {
      if (err) throw err
      console.log(String(file))
    }
  )

Related

Contribute

See contributing.md in remarkjs/remark for ways to get started.

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

License

MIT © Titus Wormer

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-45387.html

文章标题:remark-license

回到顶部