index.js 634 B

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