index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. var __importDefault = (this && this.__importDefault) || function (mod) {
  26. return (mod && mod.__esModule) ? mod : { "default": mod };
  27. };
  28. Object.defineProperty(exports, "__esModule", { value: true });
  29. exports.DefaultHandler = exports.DomUtils = exports.parseFeed = exports.getFeed = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DomHandler = exports.Parser = void 0;
  30. var Parser_js_1 = require("./Parser.js");
  31. Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return Parser_js_1.Parser; } });
  32. var domhandler_1 = require("domhandler");
  33. Object.defineProperty(exports, "DomHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
  34. Object.defineProperty(exports, "DefaultHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
  35. // Helper methods
  36. /**
  37. * Parses the data, returns the resulting document.
  38. *
  39. * @param data The data that should be parsed.
  40. * @param options Optional options for the parser and DOM builder.
  41. */
  42. function parseDocument(data, options) {
  43. var handler = new domhandler_1.DomHandler(undefined, options);
  44. new Parser_js_1.Parser(handler, options).end(data);
  45. return handler.root;
  46. }
  47. exports.parseDocument = parseDocument;
  48. /**
  49. * Parses data, returns an array of the root nodes.
  50. *
  51. * Note that the root nodes still have a `Document` node as their parent.
  52. * Use `parseDocument` to get the `Document` node instead.
  53. *
  54. * @param data The data that should be parsed.
  55. * @param options Optional options for the parser and DOM builder.
  56. * @deprecated Use `parseDocument` instead.
  57. */
  58. function parseDOM(data, options) {
  59. return parseDocument(data, options).children;
  60. }
  61. exports.parseDOM = parseDOM;
  62. /**
  63. * Creates a parser instance, with an attached DOM handler.
  64. *
  65. * @param cb A callback that will be called once parsing has been completed.
  66. * @param options Optional options for the parser and DOM builder.
  67. * @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
  68. */
  69. function createDomStream(cb, options, elementCb) {
  70. var handler = new domhandler_1.DomHandler(cb, options, elementCb);
  71. return new Parser_js_1.Parser(handler, options);
  72. }
  73. exports.createDomStream = createDomStream;
  74. var Tokenizer_js_1 = require("./Tokenizer.js");
  75. Object.defineProperty(exports, "Tokenizer", { enumerable: true, get: function () { return __importDefault(Tokenizer_js_1).default; } });
  76. /*
  77. * All of the following exports exist for backwards-compatibility.
  78. * They should probably be removed eventually.
  79. */
  80. var ElementType = __importStar(require("domelementtype"));
  81. exports.ElementType = ElementType;
  82. var domutils_1 = require("domutils");
  83. Object.defineProperty(exports, "getFeed", { enumerable: true, get: function () { return domutils_1.getFeed; } });
  84. /**
  85. * Parse a feed.
  86. *
  87. * @param feed The feed that should be parsed, as a string.
  88. * @param options Optionally, options for parsing. When using this, you should set `xmlMode` to `true`.
  89. */
  90. function parseFeed(feed, options) {
  91. if (options === void 0) { options = { xmlMode: true }; }
  92. return (0, domutils_1.getFeed)(parseDOM(feed, options));
  93. }
  94. exports.parseFeed = parseFeed;
  95. exports.DomUtils = __importStar(require("domutils"));
  96. //# sourceMappingURL=index.js.map