Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igorskyflyer/npm-comment-it
π Formats the provided string as a comment, either a single or a multi line comment for the given programming language. π»
https://github.com/igorskyflyer/npm-comment-it
back-end comments formatter igorskyflyer javascript mocha node nodejs string utility
Last synced: 2 days ago
JSON representation
π Formats the provided string as a comment, either a single or a multi line comment for the given programming language. π»
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-comment-it
- Owner: igorskyflyer
- License: mit
- Created: 2021-07-23T21:36:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T22:54:34.000Z (over 1 year ago)
- Last Synced: 2024-04-26T15:05:12.046Z (7 months ago)
- Topics: back-end, comments, formatter, igorskyflyer, javascript, mocha, node, nodejs, string, utility
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@igor.dvlpr/comment-it
- Size: 217 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# /\* CommentIt! \*/
π Formats the provided string as a comment, either a single or a multi line comment for the given programming language. π»
π 62 languages are currently supported - even Carbon,
an upcoming C++ successor made by Google π€
π Support further development
I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. β
Thank you for supporting my efforts! ππ
@igorskyflyer
## π΅πΌ Usage
Install it by executing:
```shell
npm i "@igor.dvlpr/comment-it"
```
## π€ΉπΌ API
#### getLanguageIds()
```ts
getLanguageIds(): string[]
```Gets IDs of all available language formatters. Language formatters are callable as `comment.`. See more below at [`comment`](#comment).
#### language()
```ts
language(id: string): CommentFormatter | null
```Performs a case-insensitive search for a language formatter with the provided `id` and returns it - if one is found - else returns null.
#### supportsLanguage()
```ts
supportsLanguage(id: string): boolean
```Returns whether the given language formatter is supported, **case-insensitive**.
See the [comment](#comment) object below for available valid identifiers.
#### alias()
```ts
alias(id: CommentLanguage, alias: string): boolean
```Adds an alias for an existing comment formatter. Returns true upon success, false otherwise.
#### comment
An `object` where all formatters are stored.
`comment`'s properties/formatters:
- **`comment.ada`** - Ada
- **`comment.bash`** - Bash
- **`comment.batch`** - Batch
- **`comment.c`** - C
- **`comment.carbon`** - Carbon
- **`comment.cSharp`** - C#
- **`comment.coffeeScript`** - CoffeeScript
- **`comment.cpp`** - C++
- **`comment.crystal`** - Crystal
- **`comment.css`** - CSS
- **`comment.dart`** - Dart
- **`comment.delphi`** - Delphi
- **`comment.dockerFile`** - Dockerfile
- **`comment.elixir`** - Elixir
- **`comment.erlang`** - Erlang
- **`comment.euphoria`** - Euphoria
- **`comment.fortran`** - Fortran
- **`comment.fSharp`** - F#
- **`comment.genie`** - Genie
- **`comment.go`** - Go
- **`comment.groovy`** - Groovy
- **`comment.hack`** - Hack
- **`comment.haskell`** - Haskell
- **`comment.html`** - HTML
- **`comment.icon`** - Icon
- **`comment.java`** - Java
- **`comment.javaScript`** - JavaScript
- **`comment.jsx`** - JSX
- **`comment.julia`** - Julia
- **`comment.kotlin`** - Kotlin
- **`comment.lisp`** - Lisp
- **`comment.liveCode`** - LiveCode
- **`comment.lua`** - Lua
- **`comment.maple`** - Maple
- **`comment.matlab`** - MATLAB
- **`comment.mercury`** - Mercury
- **`comment.mql4`** - MQL4
- **`comment.objectiveC`** - Objective-C
- **`comment.objectiveCpp`** - Objective-C++
- **`comment.oz`** - Oz
- **`comment.pascal`** - Pascal
- **`comment.perl`** - Perl
- **`comment.php`** - PHP
- **`comment.powerShell`** - PowerShell
- **`comment.pug`** - Pug/Jade
- **`comment.python`** - Python
- **`comment.q`** - Q
- **`comment.r`** - R
- **`comment.razor`** - Razor
- **`comment.red`** - Red
- **`comment.ring`** - Ring
- **`comment.ruby`** - Ruby
- **`comment.rust`** - Rust
- **`comment.scala`** - Scala
- **`comment.sql`** - SQL
- **`comment.swift`** - Swift
- **`comment.typeScript`** - TypeScript
- **`comment.vala`** - Vala
- **`comment.visualBasic`** - VisualBasic
- **`comment.vue`** - Vue
- **`comment.vueHtml`** - VueHtml
- **`comment.xml`** - XML
Each formatter exposes two functions, `single()` for single-line comments and `multi()` for multi-line comments.
##### single()
```ts
single(value: string): string
```Returns a single-line comment formatted for the selected language.
##### multi()
```ts
multi(value: string): string
```Returns a multi-line comment formatted for the selected language.
### Examples
```ts
import { comment, supportsLanguage } from '@igor.dvlpr/comment-it'const singleLine: string = 'hello world'
const multiLine: string = `helloworld
this is a test`
console.log(comment.javaScript.single(singleLine)) // prints '// hello world'
console.log(comment.jsx.single(singleLine)) // prints '{/* hello world */}'
console.log(comment.coffeeScript.multi(multiLine)) // prints '###\nhello\n\n\nworld\n\nthis is a test\n###'
// note: new lines in the example results are written as-is for brevity
console.log(supportsLanguage('lua')) // prints true
console.log(supportsLanguage('TYPEscript')) // prints true
console.log(supportsLanguage('foo')) // prints false
```---
## πͺͺ License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-comment-it/blob/main/LICENSE).
---
## 𧬠Related
[@igor.dvlpr/mapped-replacer](https://www.npmjs.com/package/@igor.dvlpr/mapped-replacer)
> _πΊ Zero-dependency Map and RegExp based string replacer with Unicode support. π_
[@igor.dvlpr/jmap](https://www.npmjs.com/package/@igor.dvlpr/jmap)
> _πΆοΈ Reads a JSON file into a Map. π»_
[@igor.dvlpr/strip-html-headings](https://www.npmjs.com/package/@igor.dvlpr/strip-html-headings)
> _π Strips HTML headings! π€_
[@igor.dvlpr/strip-headings](https://www.npmjs.com/package/@igor.dvlpr/strip-headings)
> _βΈ Strips Markdown headings! πΉ_
[@igor.dvlpr/unc-path](https://www.npmjs.com/package/@igor.dvlpr/unc-path)
> _π₯½ Provides ways of parsing UNC paths and checking whether they are valid. π±_
>
> Provided by **Igor DimitrijeviΔ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).
>