index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 () {
  19. var ownKeys = function(o) {
  20. ownKeys = Object.getOwnPropertyNames || function (o) {
  21. var ar = [];
  22. for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
  23. return ar;
  24. };
  25. return ownKeys(o);
  26. };
  27. return function (mod) {
  28. if (mod && mod.__esModule) return mod;
  29. var result = {};
  30. if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
  31. __setModuleDefault(result, mod);
  32. return result;
  33. };
  34. })();
  35. var __importDefault = (this && this.__importDefault) || function (mod) {
  36. return (mod && mod.__esModule) ? mod : { "default": mod };
  37. };
  38. Object.defineProperty(exports, "__esModule", { value: true });
  39. exports.DomUtils = exports.getFeed = exports.ElementType = exports.QuoteType = exports.Tokenizer = exports.DefaultHandler = exports.DomHandler = exports.Parser = void 0;
  40. exports.parseDocument = parseDocument;
  41. exports.parseDOM = parseDOM;
  42. exports.createDocumentStream = createDocumentStream;
  43. exports.createDomStream = createDomStream;
  44. exports.parseFeed = parseFeed;
  45. const Parser_js_1 = require("./Parser.js");
  46. var Parser_js_2 = require("./Parser.js");
  47. Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return Parser_js_2.Parser; } });
  48. const domhandler_1 = require("domhandler");
  49. var domhandler_2 = require("domhandler");
  50. Object.defineProperty(exports, "DomHandler", { enumerable: true, get: function () { return domhandler_2.DomHandler; } });
  51. // Old name for DomHandler
  52. Object.defineProperty(exports, "DefaultHandler", { enumerable: true, get: function () { return domhandler_2.DomHandler; } });
  53. // Helper methods
  54. /**
  55. * Parses the data, returns the resulting document.
  56. *
  57. * @param data The data that should be parsed.
  58. * @param options Optional options for the parser and DOM handler.
  59. */
  60. function parseDocument(data, options) {
  61. const handler = new domhandler_1.DomHandler(undefined, options);
  62. new Parser_js_1.Parser(handler, options).end(data);
  63. return handler.root;
  64. }
  65. /**
  66. * Parses data, returns an array of the root nodes.
  67. *
  68. * Note that the root nodes still have a `Document` node as their parent.
  69. * Use `parseDocument` to get the `Document` node instead.
  70. *
  71. * @param data The data that should be parsed.
  72. * @param options Optional options for the parser and DOM handler.
  73. * @deprecated Use `parseDocument` instead.
  74. */
  75. function parseDOM(data, options) {
  76. return parseDocument(data, options).children;
  77. }
  78. /**
  79. * Creates a parser instance, with an attached DOM handler.
  80. *
  81. * @param callback A callback that will be called once parsing has been completed, with the resulting document.
  82. * @param options Optional options for the parser and DOM handler.
  83. * @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
  84. */
  85. function createDocumentStream(callback, options, elementCallback) {
  86. const handler = new domhandler_1.DomHandler((error) => callback(error, handler.root), options, elementCallback);
  87. return new Parser_js_1.Parser(handler, options);
  88. }
  89. /**
  90. * Creates a parser instance, with an attached DOM handler.
  91. *
  92. * @param callback A callback that will be called once parsing has been completed, with an array of root nodes.
  93. * @param options Optional options for the parser and DOM handler.
  94. * @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
  95. * @deprecated Use `createDocumentStream` instead.
  96. */
  97. function createDomStream(callback, options, elementCallback) {
  98. const handler = new domhandler_1.DomHandler(callback, options, elementCallback);
  99. return new Parser_js_1.Parser(handler, options);
  100. }
  101. var Tokenizer_js_1 = require("./Tokenizer.js");
  102. Object.defineProperty(exports, "Tokenizer", { enumerable: true, get: function () { return __importDefault(Tokenizer_js_1).default; } });
  103. Object.defineProperty(exports, "QuoteType", { enumerable: true, get: function () { return Tokenizer_js_1.QuoteType; } });
  104. /*
  105. * All of the following exports exist for backwards-compatibility.
  106. * They should probably be removed eventually.
  107. */
  108. exports.ElementType = __importStar(require("domelementtype"));
  109. const domutils_1 = require("domutils");
  110. var domutils_2 = require("domutils");
  111. Object.defineProperty(exports, "getFeed", { enumerable: true, get: function () { return domutils_2.getFeed; } });
  112. const parseFeedDefaultOptions = { xmlMode: true };
  113. /**
  114. * Parse a feed.
  115. *
  116. * @param feed The feed that should be parsed, as a string.
  117. * @param options Optionally, options for parsing. When using this, you should set `xmlMode` to `true`.
  118. */
  119. function parseFeed(feed, options = parseFeedDefaultOptions) {
  120. return (0, domutils_1.getFeed)(parseDOM(feed, options));
  121. }
  122. exports.DomUtils = __importStar(require("domutils"));
  123. //# sourceMappingURL=index.js.map