# postcss-processor-splicer

> Sugar way to build a postcss processor pipeline

Latest version **3.0.0** (published 2016-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-processor-splicer
pnpm add postcss-processor-splicer
yarn add postcss-processor-splicer
bun add postcss-processor-splicer
```

## 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 | 3.0.0 |
| Published | 2016-02-19 |
| First published | 2015-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.2.1 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zoubin |
| Maintainers | zoubin |
| Keywords | postcss, plugin, processor, pipeline |

## Links

- npm: https://www.npmjs.com/package/postcss-processor-splicer
- Repository: https://github.com/reducejs/postcss-processor-splicer
- Homepage: https://github.com/reducejs/postcss-processor-splicer#readme
- Issues: https://github.com/reducejs/postcss-processor-splicer/issues
- npm.io page: https://npm.io/package/postcss-processor-splicer

## Dependencies (1)

- [postcss](https://npm.io/package/postcss.md) ^5.0.10

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2016-02-19
- 2.1.0 — 2015-12-08
- 2.0.0 — 2015-11-09
- 1.0.0 — 2015-11-03

## README

# postcss-processor-splicer
[![version](https://img.shields.io/npm/v/postcss-processor-splicer.svg)](https://www.npmjs.org/package/postcss-processor-splicer)
[![status](https://travis-ci.org/reducejs/postcss-processor-splicer.svg?branch=master)](https://travis-ci.org/reducejs/postcss-processor-splicer)
[![coverage](https://img.shields.io/coveralls/reducejs/postcss-processor-splicer.svg)](https://coveralls.io/github/reducejs/postcss-processor-splicer)
[![dependencies](https://david-dm.org/reducejs/postcss-processor-splicer.svg)](https://david-dm.org/reducejs/postcss-processor-splicer)
[![devDependencies](https://david-dm.org/reducejs/postcss-processor-splicer/dev-status.svg)](https://david-dm.org/reducejs/postcss-processor-splicer#info=devDependencies)
![node](https://img.shields.io/node/v/postcss-processor-splicer.svg)

Allow your postcss plugin pipeline to be modified like an array.

## Example

```javascript
var postcss = require('postcss')
var Pipeline = require('postcss-processor-splicer')

function createCreator(name) {
  return function (opts) {
    return function (root) {
      root.append( { selector: opts && opts.name || name } )
    }
  }
}

var A = postcss.plugin('A', createCreator('a'))
var B = postcss.plugin('B', createCreator('b'))
var C = postcss.plugin('C', createCreator('c'))
var D = postcss.plugin('D', createCreator('d'))

var pipeline = new Pipeline([
  A, // creator
  B(), // plugin
  postcss([C()]), // processor
  new Pipeline([[D, { name: 'd' }]]),  // pipeline
])

Promise.resolve()
  .then(function () {
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'apply all plugins: A, B, C, D'))
  })
  .then(function () {
    return pipeline.build('B', 'C')
      .process('x{}')
      .then(log.bind(null, 'apply plugins B, C with default options'))
  })
  .then(function () {
    return pipeline.build(['A', { name: '.a' }], ['D', { name: '.d' }])
      .process('x{}')
      .then(log.bind(null, 'apply plugins A, D with options (only valid for creators)'))
  })
  .then(function () {
    pipeline.splice('B', 2)
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'splice, delete B, C'))
  })
  .then(function () {
    pipeline.unshift(B())
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'unshift plugin B'))
  })
  .then(function () {
    pipeline.push(C)
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'push creator C'))
  })
  .then(function () {
    pipeline.get('C').push({ name: '.c' })
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'modify default options for creator C'))
  })
  .then(function () {
    pipeline.pop()
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'pop creator C'))
  })
  .then(function () {
    pipeline.shift()
    return pipeline.build()
      .process('x{}')
      .then(log.bind(null, 'shift plugin B'))
  })
  .catch(function (err) {
    console.log(err)
  })

function log(title, result) {
  console.log('\n')
  console.log('x'.repeat(40))
  console.log(title, ':')
  console.log(result.css)
}


```

output:

```
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
apply all plugins: A, B, C, D :
x{}
a{}
b{}
c{}
d{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
apply plugins B, C with default options :
x{}
b{}
c{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
apply plugins A, D with options (only valid for creators) :
x{}
.a{}
.d{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
splice, delete B, C :
x{}
a{}
d{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unshift plugin B :
x{}
b{}
a{}
d{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
push creator C :
x{}
b{}
a{}
d{}
c{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
modify default options for creator C :
x{}
b{}
a{}
d{}
.c{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
pop creator C :
x{}
b{}
a{}
d{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shift plugin B :
x{}
a{}
d{}


```

## pipeline = new Pipeline(creators)
Create a pipeline of creators.

### creators

Type: `Array`

Elements could be postcss plugins, postcss plugin creators, instances of Pipeline.
To set default options, just pass an array as the element.


### pipeline.[ArrayLikeMethods]
Modify the builtin creators.

`ArrayLikeMethods` could be one of the following:

* `splice`
* `push`
* `pop`
* `shift`
* `unshift`

### creator = pipeline.get(...postcssPlugin)
Get the internal representation of the creators according to the given plugin names or indexes.

#### creator
Representation of a creator.

Type: `Array`

The first element could be a postcss plugin function,
or postcss creator function (created with `postcss.plugin`).

Other elements are passed to the creator as options when build the plugin function.

#### postcssPlugin

Type: `String`, `Number`

Plugin name, or indexes in the pipeline.

### pipeline.build(...creators)

Create a postcss processor from given creators,
or creators in the pipeline.

You can use the plugin name or index to specify the plugin.

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