Skip to content

Commit aad2c6c

Browse files
committed
new fork
1 parent cd31f09 commit aad2c6c

File tree

7 files changed

+134
-128
lines changed

7 files changed

+134
-128
lines changed

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ecmaFeatures:
55
env:
66
browser: true
77
node: true
8+
es6: true
89

910
rules:
1011
comma-dangle: [2, "always-multiline"]
@@ -74,7 +75,6 @@ rules:
7475
quote-props: [2, "as-needed"]
7576
quotes: [2, "single", "avoid-escape"]
7677
semi: [2, "never"]
77-
space-after-keywords: 2
78+
keyword-spacing: 2
7879
space-before-blocks: 2
7980
space-infix-ops: 2
80-
space-return-throw-case: 2

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ language: node_js
22
node_js:
33
- "stable"
44
- "4"
5-
- "0.12"

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# postcss-processor-splicer
22
[![version](https://img.shields.io/npm/v/postcss-processor-splicer.svg)](https://www.npmjs.org/package/postcss-processor-splicer)
3-
[![status](https://travis-ci.org/zoubin/postcss-processor-splicer.svg?branch=master)](https://travis-ci.org/zoubin/postcss-processor-splicer)
4-
[![coverage](https://img.shields.io/coveralls/zoubin/postcss-processor-splicer.svg)](https://coveralls.io/github/zoubin/postcss-processor-splicer)
5-
[![dependencies](https://david-dm.org/zoubin/postcss-processor-splicer.svg)](https://david-dm.org/zoubin/postcss-processor-splicer)
6-
[![devDependencies](https://david-dm.org/zoubin/postcss-processor-splicer/dev-status.svg)](https://david-dm.org/zoubin/postcss-processor-splicer#info=devDependencies)
3+
[![status](https://travis-ci.org/reducejs/postcss-processor-splicer.svg?branch=master)](https://travis-ci.org/reducejs/postcss-processor-splicer)
4+
[![coverage](https://img.shields.io/coveralls/reducejs/postcss-processor-splicer.svg)](https://coveralls.io/github/reducejs/postcss-processor-splicer)
5+
[![dependencies](https://david-dm.org/reducejs/postcss-processor-splicer.svg)](https://david-dm.org/reducejs/postcss-processor-splicer)
6+
[![devDependencies](https://david-dm.org/reducejs/postcss-processor-splicer/dev-status.svg)](https://david-dm.org/reducejs/postcss-processor-splicer#info=devDependencies)
7+
![node](https://img.shields.io/node/v/postcss-processor-splicer.svg)
78

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

@@ -26,11 +27,11 @@ var B = postcss.plugin('B', createCreator('b'))
2627
var C = postcss.plugin('C', createCreator('c'))
2728
var D = postcss.plugin('D', createCreator('d'))
2829

29-
var pipeline = Pipeline([
30+
var pipeline = new Pipeline([
3031
A, // creator
3132
B(), // plugin
3233
postcss([C()]), // processor
33-
Pipeline([[D, { name: 'd' }]]), // pipeline
34+
new Pipeline([[D, { name: 'd' }]]), // pipeline
3435
])
3536

3637
Promise.resolve()
@@ -175,7 +176,7 @@ d{}
175176
176177
```
177178

178-
## pipeline = Pipeline(creators)
179+
## pipeline = new Pipeline(creators)
179180
Create a pipeline of creators.
180181

181182
### creators

example/splicer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ var B = postcss.plugin('B', createCreator('b'))
1414
var C = postcss.plugin('C', createCreator('c'))
1515
var D = postcss.plugin('D', createCreator('d'))
1616

17-
var pipeline = Pipeline([
17+
var pipeline = new Pipeline([
1818
A, // creator
1919
B(), // plugin
2020
postcss([C()]), // processor
21-
Pipeline([[D, { name: 'd' }]]), // pipeline
21+
new Pipeline([[D, { name: 'd' }]]), // pipeline
2222
])
2323

2424
Promise.resolve()

index.js

Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,117 @@
1-
var postcss = require('postcss')
1+
'use strict'
22

3-
module.exports = Pipeline
4-
module.exports.build = build
3+
const postcss = require('postcss')
54

6-
function Pipeline(creators) {
7-
if (!(this instanceof Pipeline)) {
8-
return new Pipeline(creators)
5+
class Pipeline {
6+
constructor(creators) {
7+
this.creators = []
8+
this.splice.apply(this, [0, 0].concat(creators || []))
99
}
10-
this.creators = []
11-
this.splice.apply(this, [0, 0].concat(creators || []))
12-
}
1310

14-
Pipeline.prototype.build = function() {
15-
if (arguments.length === 0) {
16-
return build(this.creators)
17-
}
18-
var creators = []
19-
;[].forEach.call(arguments, function (creator) {
20-
if (
21-
typeof creator === 'string' ||
22-
typeof creator === 'number'
23-
) {
24-
creator = this.get(creator)
11+
build() {
12+
if (arguments.length === 0) {
13+
return build(this.creators)
2514
}
26-
creators.push.apply(creators, this.normalize(creator))
27-
}, this)
28-
29-
return build(creators)
30-
}
31-
32-
Pipeline.prototype.get = function(i) {
33-
if (arguments.length < 1) {
34-
return null
15+
var creators = []
16+
;[].forEach.call(arguments, function (creator) {
17+
if (
18+
typeof creator === 'string' ||
19+
typeof creator === 'number'
20+
) {
21+
creator = this.get(creator)
22+
}
23+
creators.push.apply(creators, this.normalize(creator))
24+
}, this)
25+
26+
return build(creators)
3527
}
36-
if (arguments.length === 1) {
37-
i = this.indexOf(i)
38-
return i === -1 ? null : this.creators[i]
39-
}
40-
return [].map.call(arguments, function (n) {
41-
return this.get(n)
42-
}, this)
43-
}
4428

45-
Pipeline.prototype.indexOf = function(i) {
46-
if (typeof i === 'number') {
47-
return i
48-
}
49-
for (var j = 0, len = this.creators.length; j < len; ++j) {
50-
if (equal(this.creators[j][0], i)) {
51-
return j
29+
get(i) {
30+
if (arguments.length < 1) {
31+
return null
32+
}
33+
if (arguments.length === 1) {
34+
i = this.indexOf(i)
35+
return i === -1 ? null : this.creators[i]
5236
}
37+
return [].map.call(arguments, function (n) {
38+
return this.get(n)
39+
}, this)
5340
}
54-
return -1
55-
}
56-
57-
Pipeline.prototype.splice = function() {
58-
var args = []
5941

60-
;[].forEach.call(arguments, function (creator, i) {
61-
if (i === 0) {
62-
return args.push(this.indexOf(creator))
42+
indexOf(i) {
43+
if (typeof i === 'number') {
44+
return i
6345
}
64-
if (i === 1) {
65-
return args.push(creator)
46+
for (var j = 0, len = this.creators.length; j < len; ++j) {
47+
if (equal(this.creators[j][0], i)) {
48+
return j
49+
}
6650
}
67-
args.push.apply(args, this.normalize(creator))
68-
}, this)
69-
70-
return this.creators.splice.apply(this.creators, args)
71-
}
72-
73-
Pipeline.prototype.push = function() {
74-
var args = [this.creators.length, 0]
75-
args.push.apply(args, arguments)
76-
this.splice.apply(this, args)
77-
}
51+
return -1
52+
}
7853

79-
Pipeline.prototype.unshift = function() {
80-
var args = [0, 0]
81-
args.push.apply(args, arguments)
82-
this.splice.apply(this, args)
83-
}
54+
splice() {
55+
var args = []
8456

85-
Pipeline.prototype.pop = function() {
86-
return this.creators.pop()
87-
}
57+
;[].forEach.call(arguments, function (creator, i) {
58+
if (i === 0) {
59+
return args.push(this.indexOf(creator))
60+
}
61+
if (i === 1) {
62+
return args.push(creator)
63+
}
64+
args.push.apply(args, this.normalize(creator))
65+
}, this)
8866

89-
Pipeline.prototype.shift = function() {
90-
return this.creators.shift()
91-
}
67+
return this.creators.splice.apply(this.creators, args)
68+
}
9269

93-
Pipeline.prototype.normalize = function(creator) {
94-
if (creator && creator.creators) {
95-
// Pipeline instance
96-
return creator.creators
70+
push() {
71+
var args = [this.creators.length, 0]
72+
args.push.apply(args, arguments)
73+
this.splice.apply(this, args)
9774
}
98-
if (creator && creator.plugins) {
99-
// postcss Processor instance
100-
return creator.plugins.map(function (plugin) {
101-
return [ plugin ]
102-
})
75+
76+
unshift() {
77+
var args = [0, 0]
78+
args.push.apply(args, arguments)
79+
this.splice.apply(this, args)
10380
}
104-
if (!Array.isArray(creator)) {
105-
creator = [ creator ]
81+
82+
pop() {
83+
return this.creators.pop()
10684
}
107-
if (typeof creator[0] === 'function') {
108-
return [ creator ]
85+
86+
shift() {
87+
return this.creators.shift()
10988
}
110-
var crt = this.get(creator[0])
111-
if (!crt) {
112-
return []
89+
90+
normalize(creator) {
91+
if (creator && creator.creators) {
92+
// Pipeline instance
93+
return creator.creators
94+
}
95+
if (creator && creator.plugins) {
96+
// postcss Processor instance
97+
return creator.plugins.map(function (plugin) {
98+
return [ plugin ]
99+
})
100+
}
101+
if (!Array.isArray(creator)) {
102+
creator = [ creator ]
103+
}
104+
if (typeof creator[0] === 'function') {
105+
return [ creator ]
106+
}
107+
var crt = this.get(creator[0])
108+
if (!crt) {
109+
return []
110+
}
111+
crt = crt.slice()
112+
crt.splice.apply(crt, [1, 0].concat(creator.slice(1)))
113+
return [ crt ]
113114
}
114-
crt = crt.slice()
115-
crt.splice.apply(crt, [1, 0].concat(creator.slice(1)))
116-
return [ crt ]
117115
}
118116

119117
function equal(creator, p) {
@@ -132,3 +130,6 @@ function build(creators) {
132130
}))
133131
}
134132

133+
module.exports = Pipeline
134+
module.exports.build = build
135+

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"description": "Sugar way to build a postcss processor pipeline",
55
"main": "index.js",
66
"scripts": {
7-
"test": "npm run lint && tap --cov test/*.js",
7+
"test": "npm run lint && tap test/*.js",
88
"lint": "eslint *.js 'lib/**/*.js' test/*.js bin/*.js",
9-
"coveralls": "COVERALLS_REPO_TOKEN=RYtcZjwjolY7R6ZsTRH3Z94Ld9Bw1pKxB npm test"
9+
"coveralls": "COVERALLS_REPO_TOKEN=kNCeXyi8zTqkycIz0vWogdql5yursVWrf tap --cov test/*.js"
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/zoubin/postcss-processor-splicer.git"
13+
"url": "git+https://github.com/reducejs/postcss-processor-splicer.git"
1414
},
1515
"keywords": [
1616
"postcss",
@@ -20,15 +20,18 @@
2020
],
2121
"author": "zoubin",
2222
"license": "MIT",
23+
"engines": {
24+
"node": ">=4.2.1"
25+
},
2326
"bugs": {
24-
"url": "https://github.com/zoubin/postcss-processor-splicer/issues"
27+
"url": "https://github.com/reducejs/postcss-processor-splicer/issues"
2528
},
26-
"homepage": "https://github.com/zoubin/postcss-processor-splicer#readme",
29+
"homepage": "https://github.com/reducejs/postcss-processor-splicer#readme",
2730
"dependencies": {
2831
"postcss": "^5.0.10"
2932
},
3033
"devDependencies": {
31-
"eslint": "^1.10.1",
32-
"tap": "^2.3.1"
34+
"eslint": "^2.1.0",
35+
"tap": "^5.0.0"
3336
}
3437
}

0 commit comments

Comments
 (0)