grim-wrapper
v1.2.4
Published
Rewrap comment blocks to make them readable
Readme
Grim Wrapper
Rewrap comment blocks to make them readable.
Features
- Very small, no dependencies.
- Works in most popular programming languages, Markdown, and plain text.
- Supports Markdown lists and JavaDoc/JSDoc/XMLDoc tags.
- Limited scope to a single paragraph (part of a comment separated by empty lines).
- Almost zero config: the only option is maximum line length.
Getting started
- Install Grim Wrapper from npm:
npm install grim-wrapper- Call the
wrapCommentfunction with the comment text and the desired maximum line length. Note that it works with comment paragraphs (lines between “empty” lines).
import { wrapComment } from 'grim-wrapper';
wrapComment(
'// Bicycle rights disrupt craft beer butcher bagel biodiesel vintage asymmetrical wet cappuccino underconsuption High Life Prenzlauer Berg chia kitsch.',
80
);
// →
// Bicycle rights disrupt craft beer butcher bagel biodiesel vintage
// asymmetrical wet cappuccino underconsuption High Life Prenzlauer Berg chia
// kitsch.Motivation
I’ve been using Rewrap for a long time, but it doesn’t always do what I want:
- No support for JSX comments.
- Often weird formatting of multiline comments (
/* ... */, etc.). - I don’t like the way it format Markdown todos and JSDoc tags.
Check out samples to get an idea how it formats comments.
Guidelines
- Separate the comment from the marker with a space (
// Commentor/* Comment */). - Write in sentence case (
Comment here, comment there). - Finish sentences with a dot (
.) for JSDoc comments, feel free to skip it for single-line comments. - Prefer line comments (
//or#) to block comments (/* ... */) for documenting code inside functions. - Prefer JSDocs comments (
/** ... */) to document functions, methods, classes, constants, types, etc. - Prefer comments on their own line. Avoid end-of-line comments.
- Use prefixes such as
TODOorHACKto highlight unfinished or hacky code.
Sources
- Google style guides
- Airbnb JavaScript style guide
- Principles of writing consistent, idiomatic CSS by Nicolas Gallagher
- CSS guidelines by Harry Roberts
- jQuery HTML Style Guide
Sponsoring
This software has been developed with lots of coffee, buy me one more cup to keep it going.
Contributing
Bug fixes are welcome, but not new features. Please take a moment to review the contributing guidelines.
Authors and license
Artem Sapegin and contributors.
MIT License, see the included License.md file.

