New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

xml-stream

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-stream - npm Package Compare versions

Comparing version 0.4.1 to 0.4.3

20

examples/http-stream.js

@@ -6,4 +6,4 @@ var http = require('http');

var request = http.get({
host: 'twitter.com',
path: '/statuses/user_timeline/301879799.rss' // @pandalog
host: 'api.twitter.com',
path: '/1/statuses/user_timeline/dimituri.rss'
}).on('response', function(response) {

@@ -19,3 +19,3 @@ // Pass the response as UTF-8 to XmlStream

item.title = item.title.match(/^[^:]+/)[0] + ' on ' +
item.pubDate.replace(/ +[0-9]{4}/, '');
item.pubDate.replace(/ \+[0-9]{4}/, '');
});

@@ -28,10 +28,10 @@

// highlight Twitter-specific and other links
var url = /(^|\s+)([a-z]+(?:\/\/)?:[^\s]+)/ig;
var hashtag = /(^|\s+)(#[\w]+)/g;
var username = /(^|\s+)@([\w]+)/g;
var url = /\b[a-zA-Z][a-zA-Z0-9\+\.\-]+:[^\s]+/g;
var hashtag = /\b#[\w]+/g;
var username = /\b@([\w]+)/g;
element.$text = element.$text
.replace(/^[^:]+:\s+/, '')
.replace(url, '$1<a href="$2">$2</a>')
.replace(hashtag, '$1<a href="https://twitter.com/search/$2">$2</a>')
.replace(username, '$1<a href="https://twitter.com/$2">@$2</a>');
.replace(/^[^:]+:\s+/, '') //strip username prefix from tweet
.replace(url, '<a href="$0">$0</a>')
.replace(hashtag, '<a href="https://twitter.com/search/$0">$0</a>')
.replace(username, '<a href="https://twitter.com/$1">$0</a>');
});

@@ -38,0 +38,0 @@

@@ -59,2 +59,3 @@ var events = require('events')

this._collect = false;
this._parser = undefined;

@@ -73,3 +74,3 @@ // Set input stream encoding and create an iconv instance,

function makeEncoder(encoding) {
if (encoding && !/^utf-?8$/.test(encoding)) {
if (encoding && !/^utf-?8$/i.test(encoding)) {
return new Iconv(encoding, 'utf8');

@@ -172,2 +173,25 @@ }

// pause expat
XmlStream.prototype.pause = function() {
this._stream.pause();
this._suspended = true;
if( !this._parser.pause() ) {
throw(new Error("Cannot pause parser: "+this._parser.getError()));
}
}
// resume expat
XmlStream.prototype.resume = function() {
this._suspended = false;
if( !this._parser.resume() ) {
throw(new Error("Cannot resume parser: "+this._parser.getError()));
}
// resume stream only if parser hasn't been paused again
if( !this._suspended ) {
this._stream.resume();
}
}
// Normalizes the selector and returns the new version and its parts.

@@ -203,3 +227,3 @@ function normalizeSelector(selector) {

if (__own.call(this._finalStates, selector.normalized)) {
finalState = this._finalStates[selector.normalized];
var finalState = this._finalStates[selector.normalized];
} else {

@@ -221,3 +245,3 @@ var n = selector.parts.length;

}
finalState = this._lastState++;
var finalState = this._lastState++;
this._finalStates[selector.normalized] = finalState;

@@ -311,2 +335,4 @@ }

var xml = new expat.Parser('utf-8');
this._parser = xml;
this._suspended = false;
var stack = [];

@@ -487,3 +513,3 @@ var trace = {};

if (!xml.parse(data, false)) {
self.emit('error', xml.getError());
self.emit('error', new Error(xml.getError()+" in line "+xml.getCurrentLineNumber()));
}

@@ -503,3 +529,3 @@ }

if (/^\s*<[^>]+>/.test(prelude)) {
var matches = prelude.match(/^\s*<\?xml[^>]+encoding="(.+)"[^>]*\?>/);
var matches = prelude.match(/^\s*<\?xml[^>]+encoding="(.+?)"[^>]*\?>/);
self._encoding = matches ? matches[1] : 'utf8';

@@ -517,3 +543,3 @@ self._encoder = makeEncoder(self._encoding);

if (!xml.parse('', true)) {
self.emit('error', xml.getError());
self.emit('error', new Error(xml.getError()+" in line "+xml.getCurrentLineNumber()));
}

@@ -520,0 +546,0 @@ self.emit('end');

@@ -9,6 +9,6 @@ {

],
"version": "0.4.1",
"version": "0.4.3",
"author": "AssistUnion <info@assistunion.com>",
"maintainers": [
"Anatoly Ressin <aarnow@gmail.com>",
"Anatoly Ressin <anatoly@assistunion.com>",
"Dimitry Solovyov <dimituri@gmail.com> (http://100-hour.com)"

@@ -21,8 +21,5 @@ ],

"dependencies": {
"iconv": "~1.1.3",
"node-expat": "~1.4.3"
"iconv": "~2.0.0",
"node-expat": "~2.0.0"
},
"engines": {
"node": ">=0.6.0"
},
"directories": {

@@ -29,0 +26,0 @@ "lib": "./lib"

@@ -125,1 +125,14 @@ # XmlStream

```
# Pause and resume parsing
If you want parsing to pause (for example, until some asynchronous operation
of yours is finished), you can pause and resume XML parsing:
```javascript
xml.pause();
myAsyncFunction( function() {
xml.resume();
});
```
Beware that resume() **must not** be called from within a handler callback.
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