https://github.com/dev-build-deploy/comment-it
Source file comment management library
https://github.com/dev-build-deploy/comment-it
Last synced: about 2 months ago
JSON representation
Source file comment management library
- Host: GitHub
- URL: https://github.com/dev-build-deploy/comment-it
- Owner: dev-build-deploy
- Created: 2023-06-22T11:54:30.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-10-14T16:08:17.000Z (6 months ago)
- Last Synced: 2025-10-17T03:55:32.771Z (6 months ago)
- Language: TypeScript
- Size: 457 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSES/CC0-1.0.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# CommentIt - Comment Extraction Library
Extract comment blocks from your files.
## Features
* Simple to use
* Extracts single- and multiline- comment blocks
* Supports a range of [languages](./src/languages/languages.json) covering the top 25 languages used in GitHub (+ more)
## Basic Usage
```typescript
import { extractComments } from "@dev-build-deploy/comment-it";
const file = "README.md";
// Check if the file is supported by CommentIt
if (isSupported(file)) {
const config = {
/** Only consider comments in the first ..n lines */
maxLines: 20,
/** Group sequential singleline comments into a comment block */
groupSingleline: true,
};
// Retrieve each comment block using an iterator
for await (const comment of extractComments(file), /* OPTIONAL */ config) {
console.log(JSON.stringify(comment, null, 2));
}
}
```
The above example will result in:
```json
{
"type": "multiline",
"format": { "start": ""},
"contents": [
{
"line": 1,
"column": { "start": 0, "end": 4 },
"raw": "",
"value": ""
}
]
}
{
"type": "multiline",
"format": { "start": "" },
"contents": [
{
"line": 16,
"column": { "start": 0, "end": 45 },
"raw": "",
"value": "Hee hee, hid a comment block in here"
}
]
}
```
## Custom Language(s)
You can use the `addLanguage()` function to add new languages to the validation set:
```typescript
import { addLanguage } from "@dev-build-deploy/comment-it";
addLanguage({
name: "Pingu Language",
filenames: [".pingu"],
extensions: [".noot"],
singleline: "{%NOOTNOOT%}",
});
```
The same function can also be used to override a (default) configuration. For example,
the following code snippet replaces the comment prefix from `;` to `#` for files with
the`.ini` file extension:
```typescript
import { addLanguage } from "@dev-build-deploy/comment-it";
addLanguage({
name: "Custom ini",
extensions: [".ini"],
singleline: "#",
});
```
## Contributing
If you have suggestions for how comment-it could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
For more, check out the [Contributing Guide](CONTRIBUTING.md).
## License
- [MIT](./LICENSES/MIT.txt) © 2023 Kevin de Jong \
[SemVer 2.0.0]: https://semver.org