Skip to content

Commit

Permalink
refactor: drop the parser function, rename SAXParser
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

The ``parser`` function is removed. Just create a new instance with
``new``.

``SAXParser`` is now ``SaxesParser.`` So ``new
require("saxes").SaxesParser(...)``.
  • Loading branch information
lddubeau committed Jul 10, 2018
1 parent 19c2a83 commit 0878a6c
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ guest.

```javascript
var saxes = require("./lib/saxes"),
parser = saxes.parser();
parser = new saxes.SaxesParser();

parser.onerror = function (e) {
// an error happened.
Expand Down
2 changes: 1 addition & 1 deletion examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require("fs");
const path = require("path");
const saxes = require("../lib/saxes");

const parser = saxes.parser();
const parser = new saxes.SaxesParser();

function inspector(ev) {
return function handler(data) {
Expand Down
7 changes: 2 additions & 5 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function isQuote(c) {
return c === "\"" || c === "'";
}

class SAXParser {
class SaxesParser {
/**
* @param {Object} opt The parser options.
*/
Expand Down Expand Up @@ -1684,7 +1684,4 @@ ${JSON.stringify(this.tagName)}.`);
}
}

exports.parser = function parser(opt) {
return new SAXParser(opt);
};
exports.SAXParser = SAXParser;
exports.SaxesParser = SaxesParser;
2 changes: 1 addition & 1 deletion test/conformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class SaxesDriver extends BaseDriver {
return this.resourceLoader.loadFile(resolvedURI)
.then((source) => {
const errors = [];
const parser = saxes.parser({
const parser = new saxes.SaxesParser({
xmlns: !test.forbidsNamespaces,
});
parser.onerror = (err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const saxes = require("../lib/saxes");
exports.test = function test(options) {
const { xml, name, expect: expected, fn } = options;
it(name, () => {
const parser = saxes.parser(options.opt);
const parser = new saxes.SaxesParser(options.opt);
let expectedIx = 0;
for (const ev of saxes.EVENTS) {
// eslint-disable-next-line no-loop-func
Expand Down
2 changes: 1 addition & 1 deletion test/not-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { expect } = require("chai");
const saxes = require("../");

it("parses a buffer", () => {
const parser = saxes.parser();
const parser = new saxes.SaxesParser();
let seen = false;
parser.onopentag = (node) => {
expect(node).to.deep.equal({ name: "x", attributes: {}, isSelfClosing: false });
Expand Down
2 changes: 1 addition & 1 deletion test/parser-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { test } = require(".");

function testPosition(name, chunks, expectedEvents) {
it(name, () => {
const parser = saxes.parser();
const parser = new saxes.SaxesParser();
for (const expectation of expectedEvents) {
parser[`on${expectation[0]}`] = function handler() {
// eslint-disable-next-line guard-for-in
Expand Down
2 changes: 1 addition & 1 deletion test/xml-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("xml declaration", () => {
});

it("well-formed", () => {
const parser = saxes.parser();
const parser = new saxes.SaxesParser();
let seen = false;
parser.onopentagstart = () => {
expect(parser.xmlDecl).to.deep.equal({
Expand Down

0 comments on commit 0878a6c

Please sign in to comment.