eventsource-parser
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -6,3 +6,2 @@ 'use strict'; | ||
}); | ||
function createParser(onParse) { | ||
@@ -21,3 +20,2 @@ let isFirstChunk; | ||
}; | ||
function reset() { | ||
@@ -32,10 +30,7 @@ isFirstChunk = true; | ||
} | ||
function feed(chunk) { | ||
buffer = buffer ? buffer + chunk : chunk; | ||
if (isFirstChunk && hasBom(buffer)) { | ||
buffer = buffer.slice(BOM.length); | ||
} | ||
isFirstChunk = false; | ||
@@ -45,3 +40,2 @@ const length = buffer.length; | ||
let discardTrailingNewline = false; | ||
while (position < length) { | ||
@@ -52,13 +46,9 @@ if (discardTrailingNewline) { | ||
} | ||
discardTrailingNewline = false; | ||
} | ||
let lineLength = -1; | ||
let fieldLength = startingFieldLength; | ||
let character; | ||
for (let index = startingPosition; lineLength < 0 && index < length; ++index) { | ||
character = buffer[index]; | ||
if (character === ":" && fieldLength < 0) { | ||
@@ -73,3 +63,2 @@ fieldLength = index - position; | ||
} | ||
if (lineLength < 0) { | ||
@@ -83,7 +72,5 @@ startingPosition = length - position; | ||
} | ||
parseEventStreamLine(buffer, position, fieldLength, lineLength); | ||
position += lineLength + 1; | ||
} | ||
if (position === length) { | ||
@@ -95,3 +82,2 @@ buffer = ""; | ||
} | ||
function parseEventStreamLine(lineBuffer, index, fieldLength, lineLength) { | ||
@@ -105,15 +91,14 @@ if (lineLength === 0) { | ||
data: data.slice(0, -1) | ||
// remove trailing newline | ||
}); | ||
data = ""; | ||
eventId = void 0; | ||
} | ||
eventName = void 0; | ||
return; | ||
} | ||
const noValue = fieldLength < 0; | ||
const field = lineBuffer.slice(index, index + (noValue ? lineLength : fieldLength)); | ||
let step = 0; | ||
if (noValue) { | ||
@@ -126,7 +111,5 @@ step = lineLength; | ||
} | ||
const position = index + step; | ||
const valueLength = lineLength - step; | ||
const value = lineBuffer.slice(position, position + valueLength).toString(); | ||
if (field === "data") { | ||
@@ -140,3 +123,2 @@ data += value ? "".concat(value, "\n") : "\n"; | ||
const retry = parseInt(value, 10); | ||
if (!Number.isNaN(retry)) { | ||
@@ -151,10 +133,7 @@ onParse({ | ||
} | ||
const BOM = [239, 187, 191]; | ||
function hasBom(buffer) { | ||
return BOM.every((charCode, index) => buffer.charCodeAt(index) === charCode); | ||
} | ||
exports.createParser = createParser; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "eventsource-parser", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Streaming, source-agnostic EventSource/Server-Sent Events parser", | ||
"sideEffects": false, | ||
"type": "commonjs", | ||
"types": "./dist/index.d.ts", | ||
"source": "./src/index.ts", | ||
"module": "./dist/index.esm.js", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
@@ -15,6 +14,11 @@ ".": { | ||
"source": "./src/index.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"default": "./dist/index.mjs" | ||
} | ||
"node": { | ||
"import": "./dist/index.cjs.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"import": "./dist/index.esm.js", | ||
"default": "./dist/index.esm.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
@@ -41,10 +45,10 @@ "scripts": { | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14.18" | ||
}, | ||
"devDependencies": { | ||
"@sanity/pkg-utils": "^1.9.0", | ||
"@sanity/pkg-utils": "^2.2.3", | ||
"@types/jest": "^27.5.1", | ||
"@types/node": "^12.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.7.0", | ||
"@typescript-eslint/parser": "^5.7.0", | ||
"@typescript-eslint/eslint-plugin": "^5.49.0", | ||
"@typescript-eslint/parser": "^5.49.0", | ||
"eslint": "^7.32.0", | ||
@@ -54,6 +58,7 @@ "eslint-config-prettier": "^8.3.0", | ||
"jest": "^28.1.0", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"prettier": "^2.8.3", | ||
"rimraf": "^4.1.2", | ||
"rollup-plugin-visualizer": "^5.9.0", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "^4.5.4" | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -60,0 +65,0 @@ "bugs": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40854
12
574
14