# postcss-message-helpers

> PostCSS helpers to throw or output GNU style messages

Latest version **2.0.0** (published 2015-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-message-helpers
pnpm add postcss-message-helpers
yarn add postcss-message-helpers
bun add postcss-message-helpers
```

## 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 | 2.0.0 |
| Published | 2015-01-26 |
| First published | 2014-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Maxime Thirouin |
| Maintainers | moox |
| Keywords | css, postcss, postcss-plugins, messages, error, warning |

## Links

- npm: https://www.npmjs.com/package/postcss-message-helpers
- Repository: https://github.com/MoOx/postcss-message-helpers
- Issues: https://github.com/MoOx/postcss-message-helpers/issues
- npm.io page: https://npm.io/package/postcss-message-helpers

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2015-01-26
- 1.1.1 — 2014-11-25
- 1.1.0 — 2014-11-24
- 1.0.0 — 2014-11-24

## README

# postcss-message-helpers [![Build Status](https://travis-ci.org/MoOx/postcss-message-helpers.png)](https://travis-ci.org/MoOx/postcss-message-helpers)

> [PostCSS](https://github.com/postcss/postcss) helpers to throw or output GNU style messages.

This modules offers you some function to throw or just output messages with [GNU style](https://www.gnu.org/prep/standards/html_node/Errors.html): `sourcefile:lineno:column: message`

## Installation

```console
$ npm install postcss-message-helpers
```

```js
var messageHelpers = require("postcss-message-helpers")
```

## Usage

### `var fnValue = messageHelpers.try(fn, source)`

Execute `fn` an return the value.
If an exception is thrown during the process, the exception will be catched, enhanced from source & re-throw.

### `var sourceMessage = messageHelpers.message(message, source)`

Returns a message like `sourcefile:lineno:column: message`.  
`source` should be a postcss source object from a node.

### `var source = messageHelpers.source(source)`

Returns `sourcefile:lineno:column` for a given `source` postcss object.

### Example

```js
// dependencies
var fs = require("fs")
var postcss = require("postcss")
var messageHelpers = require("postcss-message-helpers")

// css to be processed
var css = fs.readFileSync("input.css", "utf8")

// process css
var output = postcss()
  .use(function(styles) {
    styles.eachDecl(function transformDecl(decl) {
      // will catch, adjust error stack, line, column & message (gnu style) then re-throw
      messageHelpers.try(function IwillThrow() {
        if (decl.value.indexOf("error(") > -1) {
          throw new Error("error detected: " + decl.value)
        }
      }, decl.source)

      // will output a gnu style warning
      if (decl.value.indexOf("warning(") > -1) {
        console.warning(messageHelpers.message("warning: " + decl.value, decl.source))
      }
    })
  })
  .process(css)
  .css
```

Checkout [tests](test) for more examples.

---

## Contributing

Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.

    $ git clone https://github.com/MoOx/postcss-message-helpers.git
    $ git checkout -b patch-1
    $ npm install
    $ npm test

## [Changelog](CHANGELOG.md)

## [License](LICENSE)

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