index.js 629 B

12345678910111213141516171819202122232425262728
  1. var parse = require('./parse');
  2. var walk = require('./walk');
  3. var stringify = require('./stringify');
  4. function ValueParser(value) {
  5. if (this instanceof ValueParser) {
  6. this.nodes = parse(value);
  7. return this;
  8. }
  9. return new ValueParser(value);
  10. }
  11. ValueParser.prototype.toString = function () {
  12. return Array.isArray(this.nodes) ? stringify(this.nodes) : '';
  13. };
  14. ValueParser.prototype.walk = function (cb, bubble) {
  15. walk(this.nodes, cb, bubble);
  16. return this;
  17. };
  18. ValueParser.unit = require('./unit');
  19. ValueParser.walk = walk;
  20. ValueParser.stringify = stringify;
  21. module.exports = ValueParser;