UNPKG

1.1 kBJavaScriptView Raw
1/*
2 Copyright © 2018 Andrew Powell
3
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8 The above copyright notice and this permission notice shall be
9 included in all copies or substantial portions of this Source Code Form.
10*/
11const Input = require('postcss/lib/input');
12
13const Parser = require('./ValuesParser');
14const { stringify } = require('./ValuesStringifier');
15
16module.exports = {
17 parse(css, options) {
18 const input = new Input(css, options);
19 const parser = new Parser(input, options);
20
21 parser.parse();
22
23 const { root } = parser;
24 const ogToString = root.toString;
25
26 function toString(stringifier) {
27 return ogToString.bind(root)(stringifier || module.exports.stringify);
28 }
29
30 root.toString = toString.bind(root);
31
32 return parser.root;
33 },
34
35 stringify,
36
37 nodeToString(node) {
38 let result = '';
39
40 module.exports.stringify(node, (bit) => {
41 result += bit;
42 });
43
44 return result;
45 }
46};