block-comment v1.0.3
block-comment
Create a multiline block comment from a string
or an Array
const comment = blockComment('Hello\nworld.', {start: '!'})
console.log(comment);
yields:
/*!
* Hello
* World
*/
Installation
Package managers
npm
npm install block-comment
Bower
bower install block-comment
API
import blockComment from 'block-comment';
blockComment(content , option)
content: string
or string[]
option: Object
Return: string
It returns a string
of ECMAScript multi-line comment.
When content is a string
, the result reflects the newlines of content.
blockComment('foo\nbar\r\nbaz'); //=> '/*\n * foo\n * bar\n * baz\n*/'
You can also specify content with an Array
.
blockComment(['foo', 'bar']); //=> '/*\n * foo\n * bar\n*/'
option.start
Type: string
Default: ''
Adds a string immediately after /*
.
For example, if you use some JavaScript compression tools such as grunt-contrib-uglify and gulp-uglify, you can preserve the comment by adding !
;
blockComment('foo', {start: '!'}); //=> '/*!\n * foo\n*/'
Properties
This function has three properties used as components of the comment template.
blockComment.open
Type: String
Default: '/*'
blockComment.linePrefix
Type: String
Default: ' *'
blockComment.close
Type: String
Default: '*/'
You can overwrite these properties if you want to modify the comment template. However, you don't have to care about them in most cases.
blockComment.open = '/**********';
blockComment.close = '**********/';
blockComment('foo'); //=> '/**********\n * foo\n**********/'
CLI
You can use this module as a CLI tool by installing it globally.
Usage
Usage1: block-comment <string>
Usage2: cat <file> | block-comment <string>
Options:
--start, -s <string> Add something (e.g. `!`) to the first line
--help, -h Print usage information
--version, -v Print version
License
Copyright (c) 2014 - 2018 Shinnosuke Watanabe
Licensed under the MIT License.