Skip to content
Create a multi-line block comment from a string or an array
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.editorconfig
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
appveyor.yml
block-comment-cjs.js
block-comment.js
bower.json
cli.js
package.json
test-api.js
test-cli.js

README.md

block-comment.js

NPM version Bower version Build Status Build status Coverage Status Dependency Status devDependency Status

Create a multi-line block comment from a string or an array

var comment = blockComment('Hello\nworld.', {start: '!'})
console.log(comment);

yields:

/*!
 * Hello
 * World
*/

Installation

Package managers

npm

npm install block-comment

Bower

bower install block-comment

Duo

const blockComment = require('shinnn/block-comment.js');

Standalone

Download the script file directly.

API

blockComment(content [, option])

content: String or Array of 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 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Something went wrong with that request. Please try again.