Skip to content

Commit 865a431

Browse files
committed
Add docs
1 parent 4dcaf4d commit 865a431

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

readme.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
postcss-icss
22
============
33

4-
A CSS Modules parser to extract tokens from the css file. Provides opportunity to process multiple files. Supports both synchronous and asynchronous file loaders.
4+
A CSS Modules parser to extract tokens from the css file. Provides opportunity to process multiple files.
55

66
## API
77

8-
In order to use it you should provide a `fetch` function which should load contents of files and process it with the PostCSS instance. `fetch` function should return tokens or promise object which will resolve into tokens.
8+
In order to use it you should provide a `fetch` function which should load contents of files and process it with the PostCSS instance.
9+
`fetch` function should return promise object which will resolve into tokens.
910

10-
```javascript
11-
var Parser = require('postcss-modules-parser');
11+
```js
12+
const ICSS = require('postcss-icss');
1213

13-
/**
14-
* @param {string} to Path to the new file. Could be any.
15-
* @param {string} from Path to the source file. Should be absolute.
16-
* @return {object} Tokens
17-
*/
18-
function fetch(to, from) {
14+
function fetch(importee, importerDir, processor) {
1915
// load content
20-
return instance.process(css, {from: filename}).root.tokens;
16+
return processor.process(css, { from: filename })
17+
.then(result => result.messages.find(d => d.type === "icss").exportTokens);
2118
}
2219

23-
new Parser({fetch: fetch});
20+
postcss([ ICSS({ fetch }) ]);
2421
```
25-
26-
See the examples:
27-
- asynchronous loader: [test/helper/async-loader.js](https://github.com/css-modules/postcss-modules-parser/blob/master/test/helper/async-loader.js)
28-
- synchronous loader: [test/helper/sync-loader.js](https://github.com/css-modules/postcss-modules-parser/blob/master/test/helper/sync-loader.js)

0 commit comments

Comments
 (0)