Socket
Socket
Sign inDemoInstall

sax

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sax - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

examples/big-not-pretty.xml

106

examples/pretty-print.js

@@ -1,72 +0,74 @@

var printer = require("../lib/sax").parser(false, {lowercasetags:true, trim:true}),
sys = require("sys"),
fs = require("fs");
var sax = require("../lib/sax")
, printer = sax.createStream(false, {lowercasetags:true, trim:true})
, fs = require("fs")
function entity (str) {
return str.replace('"', '"');
return str.replace('"', '"')
}
printer.tabstop = 2;
printer.level = 0;
printer.tabstop = 2
printer.level = 0
printer.indent = function () {
sys.print("\n");
print("\n")
for (var i = this.level; i > 0; i --) {
for (var j = this.tabstop; j > 0; j --) {
sys.print(" ");
print(" ")
}
}
}
printer.onopentag = function (tag) {
this.indent();
this.level ++;
sys.print("<"+tag.name);
printer.on("opentag", function (tag) {
this.indent()
this.level ++
print("<"+tag.name)
for (var i in tag.attributes) {
sys.print(" "+i+"=\""+entity(tag.attributes[i])+"\"");
print(" "+i+"=\""+entity(tag.attributes[i])+"\"")
}
sys.print(">");
print(">")
})
printer.on("text", ontext)
printer.on("doctype", ontext)
function ontext (text) {
this.indent()
print(text)
}
printer.ontext = printer.ondoctype = function (text) {
this.indent();
sys.print(text);
}
printer.onclosetag = function (tag) {
this.level --;
this.indent();
sys.print("</"+tag+">");
}
printer.oncdata = function (data) {
this.indent();
sys.print("<![CDATA["+data+"]]>");
}
printer.oncomment = function (comment) {
this.indent();
sys.print("<!--"+comment+"-->");
}
printer.onerror = function (error) {
sys.debug(error);
throw error;
}
printer.on("closetag", function (tag) {
this.level --
this.indent()
print("</"+tag+">")
})
printer.on("cdata", function (data) {
this.indent()
print("<![CDATA["+data+"]]>")
})
printer.on("comment", function (comment) {
this.indent()
print("<!--"+comment+"-->")
})
printer.on("error", function (error) {
console.error(error)
throw error
})
if (!process.argv[2]) {
throw new Error("Please provide an xml file to prettify\n"+
"TODO: read from stdin or take a file");
"TODO: read from stdin or take a file")
}
var xmlfile = require("path").join(process.cwd(), process.argv[2]);
fs.open(xmlfile, "r", 0666, function (er, fd) {
if (er) throw er;
(function R () {
fs.read(fd, 1024, null, "utf8", function (er, data, bytesRead) {
if (er) throw er;
if (data) {
printer.write(data);
R();
} else {
fs.close(fd);
printer.close();
}
});
})();
});
var xmlfile = require("path").join(process.cwd(), process.argv[2])
var fstr = fs.createReadStream(xmlfile, { encoding: "utf8" })
function print (c) {
if (!process.stdout.write(c)) {
fstr.pause()
}
}
process.stdout.on("drain", function () {
fstr.resume()
})
fstr.pipe(printer)

@@ -26,3 +26,25 @@ // wrapper for non-node envs

sax.EVENTS = // for discoverability.
[ "text"
, "processinginstruction"
, "sgmldeclaration"
, "doctype"
, "comment"
, "attribute"
, "opentag"
, "closetag"
, "opencdata"
, "cdata"
, "closecdata"
, "error"
, "end"
, "ready"
, "script"
, "opennamespace"
, "closenamespace"
]
function SAXParser (strict, opt) {
if (!(this instanceof SAXParser)) return new SAXParser(strict, opt)
var parser = this

@@ -124,19 +146,5 @@ clearBuffers(parser)

var streamWraps =
[ "opentag"
, "closetag"
, "text"
, "attribute"
, "error"
, "doctype"
, "processinginstruction"
, "sgmldeclaration"
, "comment"
, "opencdata"
, "cdata"
, "closecdata"
, "opennamespace"
, "closenamespace"
, "ready"
]
var streamWraps = sax.EVENTS.filter(function (ev) {
return ev !== "error" && ev !== "end"
})

@@ -148,2 +156,4 @@ function createStream (strict, opt) {

function SAXStream (strict, opt) {
if (!(this instanceof SAXStream)) return new SAXStream(strict, opt)
Stream.apply(me)

@@ -164,2 +174,6 @@

me.emit("error", er)
// if didn't throw, then means error was handled.
// go ahead and clear error, so we can write again.
me._parser.error = null
}

@@ -285,21 +299,2 @@

S = sax.STATE
sax.EVENTS = // for discoverability.
[ "text"
, "processinginstruction"
, "sgmldeclaration"
, "doctype"
, "comment"
, "attribute"
, "opentag"
, "closetag"
, "opencdata"
, "cdata"
, "closecdata"
, "error"
, "end"
, "ready"
, "script"
, "opennamespace"
, "closenamespace"
]

@@ -306,0 +301,0 @@ function emit (parser, event, data) {

{ "name" : "sax"
, "description": "An evented streaming XML parser in JavaScript"
, "author" : "Isaac Z. Schlueter <i@izs.me>"
, "version" : "0.3.0"
, "version" : "0.3.1"
, "main" : "lib/sax"

@@ -6,0 +6,0 @@ , "license" : "MIT"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc