index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var Parser = require("./Parser.js"),
  2. DomHandler = require("domhandler");
  3. function defineProp(name, value){
  4. delete module.exports[name];
  5. module.exports[name] = value;
  6. return value;
  7. }
  8. module.exports = {
  9. Parser: Parser,
  10. Tokenizer: require("./Tokenizer.js"),
  11. ElementType: require("domelementtype"),
  12. DomHandler: DomHandler,
  13. get FeedHandler(){
  14. return defineProp("FeedHandler", require("./FeedHandler.js"));
  15. },
  16. get Stream(){
  17. return defineProp("Stream", require("./Stream.js"));
  18. },
  19. get WritableStream(){
  20. return defineProp("WritableStream", require("./WritableStream.js"));
  21. },
  22. get ProxyHandler(){
  23. return defineProp("ProxyHandler", require("./ProxyHandler.js"));
  24. },
  25. get DomUtils(){
  26. return defineProp("DomUtils", require("domutils"));
  27. },
  28. get CollectingHandler(){
  29. return defineProp("CollectingHandler", require("./CollectingHandler.js"));
  30. },
  31. // For legacy support
  32. DefaultHandler: DomHandler,
  33. get RssHandler(){
  34. return defineProp("RssHandler", this.FeedHandler);
  35. },
  36. //helper methods
  37. parseDOM: function(data, options) {
  38. var handler = new DomHandler(options);
  39. var parser = new Parser(handler, options);
  40. parser.end(data);
  41. return handler.dom;
  42. },
  43. parseFeed: function(feed, options){
  44. var handler = new module.exports.FeedHandler();
  45. var parser = new Parser(handler);
  46. parser.end(feed);
  47. return handler.dom;
  48. },
  49. createDomStream: function(cb, options, elementCb){
  50. var handler = new DomHandler(cb, options, elementCb);
  51. return new Parser(handler, options);
  52. },
  53. // List of all events that the parser emits
  54. EVENTS: { /* Format: eventname: number of arguments */
  55. attribute: 2,
  56. cdatastart: 0,
  57. cdataend: 0,
  58. text: 1,
  59. processinginstruction: 2,
  60. comment: 1,
  61. commentend: 0,
  62. closetag: 1,
  63. opentag: 2,
  64. opentagname: 1,
  65. error: 1,
  66. end: 0
  67. }
  68. };