# stylelint-formatter-utils

> Helpful utilities for building custom stylelint formatters.

Latest version **1.1.0** (published 2019-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install stylelint-formatter-utils
pnpm add stylelint-formatter-utils
yarn add stylelint-formatter-utils
bun add stylelint-formatter-utils
```

## 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.1.0 |
| Published | 2019-09-19 |
| First published | 2019-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shawn Allen |
| Maintainers | shawnbot |
| Keywords | stylelint, utilities |

## Links

- npm: https://www.npmjs.com/package/stylelint-formatter-utils
- npm.io page: https://npm.io/package/stylelint-formatter-utils

## Dependencies (2)

- [git-url-parse](https://npm.io/package/git-url-parse.md) ^11.1.2
- [remote-origin-url](https://npm.io/package/remote-origin-url.md) ^2.0.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-09-19
- 0.0.0-ba66dd4 (canary) — 2019-12-30
- 0.0.0-a91ddb7 — 2019-09-19
- 0.0.0-42e14f4 — 2019-09-19
- 0.0.0-bd2e263 — 2019-09-19
- 0.0.0-012e16a — 2019-09-19
- 0.0.0-1d77675 — 2019-09-19
- 1.0.0 — 2019-09-19
- 0.0.0-9776fdf — 2019-09-19

## README

# stylelint-formatter-utils
Helpful utilities for building custom stylelint formatters.

## Install
```
npm install stylelint-formatter-utils
```

## Usage
The `stylelint-formatter-utils` module has the following exports:

### `Table`
This is a class for outputting tabular data:

```js
const {Table} = require('stylelint-formatter-utils')
const table = new Table({
  delimiter: ',',
  columns: ['source', 'line']
})
console.log(table.format([
  {source: 'x.css', line: 10},
  {source: 'y.css', line: 5}
])
// outputs:
// source,line
// x.css,10
// y.css,5
```

Want to generate a Markdown table? Get it from the [markdown exports](#markdown).


## `getHeadRef()`
Get the git head ref, which is useful for generating links to source code.

```js
const {getHeadRef} = require('stylelint-formatter-utils')
const {repository} = require('./package.json')
const head = getHeadRef()
console.log(`browse this ref: https://github.com/${repository}/tree/${ref}`)
```

## `getRepoURL()`
Get the repo URL from the git origin remote.

```js
const {getRepoURL} = require('stylelint-formatter-utils')
console.log(`check out this repo: ${getRepoURL()}`)
```

## `stripCwd(path[, cwd])`
Strip the current working directory from the lefthand side of the input `path`.
If `cwd` is not provided or empty, we get it from `process.cwd()`.

```js
const {stripCwd} = require('stylelint-formatter-utils')
console.log(`this file is: ${stripCwd(__filename)}`)
```

## Markdown
You can get a couple of Markdown-specific helpers from the `stylelint-formatter-utils/markdown` endpoint:

### MarkdownTable

```js
const {MarkdownTable, link} = require('stylelint-formatter-utils/markdown')
const table = new MarkdownTable({
  columns: [
    {title: 'rule', format: ({rule}) => {
      return link(rule, `https://stylelint.io/user-guide/rules/${rule}`)
    }},
    {title: 'path', format: ({source, line}) => {
      return link(`${source}@${line}`, `https://github.com/my/repo/blob/master/${source}#L${line}`)
    }}
  ]
})
```

### `markdown.link(text, url)`
Returns a Markdown link in the format `[text](url)`.

### `markdown.code(text)`
Returns the string wrapped in backticks.

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