1.0.3 • Published 5 years ago

block-comment v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

block-comment

npm version Bower version Build Status Coverage Status

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.

2.0.0-3

5 years ago

2.0.0-2

5 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

10 years ago

0.0.0

10 years ago