Skip to content

Commit

Permalink
refactor: convert code to ES6
Browse files Browse the repository at this point in the history
Side effects:

STATE is no longer exported. This is not a "breaking change" properly
speaking because it was never advertized formally as part of the API.

BREAKING CHANGE:

It is no longer possible to load the library as-is through a
``script`` element. It needs building.

The library now assumes a modern runtime. It no longer contains any
code to polyfill what's missing. It is up to developers using this
code to deal with polyfills as needed.
  • Loading branch information
lddubeau committed Jul 2, 2018
1 parent 101ea50 commit fe81170
Show file tree
Hide file tree
Showing 52 changed files with 3,934 additions and 3,364 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: [
"lddubeau-base",
],
env: {
node: true,
},
};
62 changes: 37 additions & 25 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
var fs = require('fs'),
util = require('util'),
path = require('path'),
xml = fs.readFileSync(path.join(__dirname, 'test.xml'), 'utf8'),
saxes = require('../lib/saxes'),
parser = saxes.parser(),
inspector = function (ev) { return function (data) {
console.error('%s %s %j', this.line + ':' + this.column, ev, data)
"use strict";

/* eslint-disable no-console */

const fs = require("fs");
const path = require("path");
const saxes = require("../lib/saxes");

const parser = saxes.parser();

function inspector(ev) {
return function handler(data) {
console.error("%s %s %j", `${this.line}:${this.column}`, ev, data);
if (ev === "error") {
parser.resume()
parser.resume();
}
}}

saxes.EVENTS.forEach(function (ev) {
parser['on' + ev] = inspector(ev)
})
parser.onend = function () {
console.error('end')
console.error(parser)
};
}

// do this in random bits at a time to verify that it works.
(function () {
saxes.EVENTS.forEach((ev) => {
parser[`on${ev}`] = inspector(ev);
});

parser.onend = () => {
console.error("end");
console.error(parser);
};

let xml = fs.readFileSync(path.join(__dirname, "test.xml"), "utf8");
function processChunk() {
if (xml) {
var c = Math.ceil(Math.random() * 1000)
parser.write(xml.substr(0, c))
xml = xml.substr(c)
process.nextTick(arguments.callee)
} else parser.close()
}())
const c = Math.ceil(Math.random() * 1000);
parser.write(xml.substr(0, c));
xml = xml.substr(c);
process.nextTick(processChunk);
}
else {
parser.close();
}
}

processChunk();
6 changes: 6 additions & 0 deletions lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: "../.eslintrc.js",
rules: {
"no-continue": "off",
},
}
Loading

0 comments on commit fe81170

Please sign in to comment.