@@ -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 */
3333function 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/**
0 commit comments