index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. new Parser(handler, options).end(data);
  40. return handler.dom;
  41. },
  42. parseFeed: function(feed, options){
  43. var handler = new module.exports.FeedHandler(options);
  44. new Parser(handler, options).end(feed);
  45. return handler.dom;
  46. },
  47. createDomStream: function(cb, options, elementCb){
  48. var handler = new DomHandler(cb, options, elementCb);
  49. return new Parser(handler, options);
  50. },
  51. // List of all events that the parser emits
  52. EVENTS: { /* Format: eventname: number of arguments */
  53. attribute: 2,
  54. cdatastart: 0,
  55. cdataend: 0,
  56. text: 1,
  57. processinginstruction: 2,
  58. comment: 1,
  59. commentend: 0,
  60. closetag: 1,
  61. opentag: 2,
  62. opentagname: 1,
  63. error: 1,
  64. end: 0
  65. }
  66. };