Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 650d63b

Browse files
committed
cssnext can now return a postcss instance
This will be nice when postcss 3 will be released Ref #3
1 parent c34c3ee commit 650d63b

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# 0.4.2 - 2014-11-02
2+
13
- support !important for custom properties ([ref](https://github.com/postcss/postcss-custom-properties/issues/12))
24
- echo a warning when using a non root custom properties ([ref](https://github.com/postcss/postcss-custom-properties/issues/13))
5+
- cssnext can return a postcss instance of no string given ([ref](https://github.com/cssnext/cssnext/issues/3))
36

47
# 0.4.1 - 2014-11-01
58

index.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ module.exports = cssnext
2626
/**
2727
* Process a CSS `string`
2828
*
29-
* @param {String} string
30-
* @param {Object} options
31-
* @return {String}
29+
* @param {String} string (optional)
30+
* @param {Object} options (optional)
31+
* @return {String} if string is given, or {Object} (postcss instance)
3232
*/
3333
function cssnext(string, options) {
34-
// ensure options is an object
35-
options = options || {}
34+
if (arguments.length === 0) {
35+
options = {}
36+
}
37+
if (arguments.length === 1 && typeof string === "object") {
38+
options = string
39+
string = undefined
40+
}
41+
else {
42+
options = options || {}
43+
}
44+
3645
var features = options.features || {}
3746

3847
// default sourcemap
@@ -58,15 +67,20 @@ function cssnext(string, options) {
5867
postcss.use(require("csswring").postcss)
5968
}
6069

61-
var result = postcss.process(string, options)
70+
if (string) {
71+
var result = postcss.process(string, options)
6272

63-
// default behavior, cssnext returns a css string
64-
if (options.map === null || options.map === defaultMap) {
65-
return result.css
66-
}
73+
// default behavior, cssnext returns a css string
74+
if (options.map === null || options.map === defaultMap) {
75+
return result.css
76+
}
6777

68-
// if a specific map has been asked, we are returning css + map
69-
return result
78+
// if a specific map has been asked, we are returning css + map
79+
return result
80+
}
81+
else {
82+
return postcss
83+
}
7084
}
7185

7286
/**

test/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var cssnextStandalone = require("../dist/cssnext.js")
44

55
test("cssnext", function(t) {
66
t.ok(typeof cssnext("html{}") === "string", "should return a string")
7+
var postcssInstance = cssnext()
8+
t.ok(typeof postcssInstance === "object" && postcssInstance.process, "should return a postcss instance")
79

810
t.end()
911
})

0 commit comments

Comments
 (0)