# attr-pipeline

> Simple object validation and transformations.

Latest version **0.6.0** (published 2014-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install attr-pipeline
pnpm add attr-pipeline
yarn add attr-pipeline
bun add attr-pipeline
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2014-11-17 |
| First published | 2014-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adam Lee |
| Maintainers | admosity |
| Keywords | validation |

## Links

- npm: https://www.npmjs.com/package/attr-pipeline
- Repository: https://github.com/admosity/attr-pipeline
- Issues: https://github.com/admosity/attr-pipeline/issues
- npm.io page: https://npm.io/package/attr-pipeline

## Dependencies (3)

- [q](https://npm.io/package/q.md) ^1.1.1
- [async](https://npm.io/package/async.md) ^0.9.0
- [coffee-script](https://npm.io/package/coffee-script.md) ^1.8.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2014-11-17
- 0.5.0 — 2014-11-17
- 0.4.0 — 2014-11-16
- 0.3.0 — 2014-11-16
- 0.2.0 — 2014-11-15
- 0.1.1 — 2014-11-15

## README

# Attribute Pipeline

Easy to use no frills object validation/object transformations.

## Quick start

`npm install attr-pipeline`

```javascript
var ap = require('attr-pipeline');

var validator = new ap.Validator({
  attr1: {required: true},
  // attribute with pipeline
  // will only apply if the attribute is present in the object
  attr2: {
    // pipeline functions executed in order and only if attribute exists
    // if required is not supplied
    pipe: [
      // single argument functions must return a boolean (for success/failure)
      function(value) {
        return typeof value === 'string';
      },
      // transformations must have a callback
      function(value, callback) {
        return callback(null, value + " World!");
      }
    ]
  }
});

// EXAMPLES

// with callbacks

validator.validate({}, function(err, object) {
  // error here attr1 is required
});

validator.validate({attr1: "anything"}, function(err, object) {
  console.log(object); // {attr1: "anything"}
});

validator.validate({attr1: "anything", attr2: 1}, function(err, object) {
  // error here attr2 is not a string
});

validator.validate({attr1: "anything", attr2: "Hello"}, function(err, object) {
  console.log(object); // {attr1: "anything", attr2: "Hello World!"}
});

// as promises

validator.validate({})
  .then(function(object) {
    // does not execute
  })
  .catch(function(err) {
    // error here attr1 is required
  })
  .done();

validator.validate({attr1: "anything"})
  .then(function(object) {
    console.log(object); // {attr1: "anything"}
  })
  .catch(function(err) {
    // does not execute
  })
  .done();

validator.validate({attr1: "anything", attr2: 1})
  .then(function(object) {
    // does not execute
  })
  .catch(function(err) {
    // error here attr2 is not a string
  })
  .done();

validator.validate({attr1: "anything", attr2: "Hello"})
  .then(function(object) {
    console.log(object); // {attr1: "anything", attr2: "Hello World!"}
  })
  .catch(function(err) {
    // does not execute
  })
  .done();
```

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