# action-comment

> Matipulate files, text or scripts, enabling the modification of pre-defined blocks with intelligent comments.

Latest version **1.0.1** (published 2019-09-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install action-comment
pnpm add action-comment
yarn add action-comment
bun add action-comment
```

Provides the command `action-comment`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-09-03 |
| First published | 2017-02-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Philippe Assis |
| Maintainers | philippeassis |

## Links

- npm: https://www.npmjs.com/package/action-comment
- Repository: https://github.com/PhilippeAssis/actionComment
- Homepage: https://github.com/PhilippeAssis/actionComment#readme
- Issues: https://github.com/PhilippeAssis/actionComment/issues
- npm.io page: https://npm.io/package/action-comment

## Dependencies (1)

- [simple-flags](https://npm.io/package/simple-flags.md) ^1.2.4

## Recent versions

- 1.0.1 (latest) — 2019-09-03
- 1.0.0 — 2019-09-03
- 0.0.4 — 2017-02-14
- 0.0.3 — 2017-02-14
- 0.0.2 — 2017-02-14
- 0.0.1 — 2017-02-10

## README

# actionComment
Matipulate files, text or scripts, enabling the modification of pre-defined blocks with intelligent comments.

### Reason
Need a handler to modify scripts according to need, before running the build


```javascript
actionComment(content || String, handlers || Object{Function}, commentTag = '#!')
```

## Use
#### myFile.txt
```yml
#!addName:start
My name is #name,
your name
is #name too.
#!addName:end

My name is Jack,
your name
is #!insertName too.
```

#### example.js
```javascript
actionComment(
    fs.readFileSync('myFile.txt').toString(), 
    {
      insertName(){
          return `Jack`
      },
      addName(line){
          return line.replace('#name', 'Martin')
      }
    }, 
    '#!'
)
```

#### Result
```text
My name is Martin,
your name
is Martin too.

My name is Jack,
your name
is Jack too.
```

## Create handles
Handlers receive the following parameters:
 - content: `String`
 - line: `Int` line number
 - position: `array`: [init position, end position] 

They may return a promise

#### Handler example
```javascript
function handler(content, line, position){
    return line
}

async function handlerPromise(content, line, position){
    return line
}
```

## CLI
```bash
action-comment [target: path] --handler [path] --output [path] --tag [string] 
```
 - target: Target file
 - output: File that will be created, if nothing happens, exit stdout.
 - handler: Nodejs module with handlers
 - tag: Comment tag

---
_Source: https://npm.io/package/action-comment · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
