eventsource-parser
Advanced tools
+1
-1
@@ -93,3 +93,3 @@ "use strict"; | ||
| let lineEnd = -1; | ||
| if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) { | ||
| if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) { | ||
| incompleteLine = chunk.slice(searchIndex); | ||
@@ -96,0 +96,0 @@ break; |
+11
-11
@@ -32,3 +32,3 @@ /** | ||
| */ | ||
| event?: string | ||
| event?: string | undefined | ||
| /** | ||
@@ -38,3 +38,3 @@ * ID of the message, if any was provided by the server. Can be used by clients to keep the | ||
| */ | ||
| id?: string | ||
| id?: string | undefined | ||
| /** | ||
@@ -56,4 +56,4 @@ * The data received for this message | ||
| * Feeds the parser another chunk. The method _does not_ return a parsed message. | ||
| * Instead, if the chunk was a complete message (or completed a previously incomplete message), | ||
| * it will invoke the `onParse` callback used to create the parsers. | ||
| * Instead, callbacks passed when creating the parser will be triggered once we see enough data | ||
| * for a valid/invalid parsing step (see {@link ParserCallbacks}). | ||
| * | ||
@@ -91,11 +91,11 @@ * @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages. | ||
| */ | ||
| field?: string | ||
| field?: string | undefined | ||
| /** | ||
| * In the case of an unknown field encountered in the stream, this will be the value of the field. | ||
| */ | ||
| value?: string | ||
| value?: string | undefined | ||
| /** | ||
| * The line that caused the error, if available. | ||
| */ | ||
| line?: string | ||
| line?: string | undefined | ||
| constructor( | ||
@@ -125,3 +125,3 @@ message: string, | ||
| */ | ||
| onEvent?: (event: EventSourceMessage) => void | ||
| onEvent?: ((event: EventSourceMessage) => void) | undefined | ||
| /** | ||
@@ -132,3 +132,3 @@ * Callback for when the server sends a new reconnection interval through the `retry` field. | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
| /** | ||
@@ -139,3 +139,3 @@ * Callback for when a comment is encountered in the stream. | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
| /** | ||
@@ -148,5 +148,5 @@ * Callback for when an error occurs during parsing. This is a catch-all for any errors | ||
| */ | ||
| onError?: (error: ParseError) => void | ||
| onError?: ((error: ParseError) => void) | undefined | ||
| } | ||
| export {} |
+11
-11
@@ -32,3 +32,3 @@ /** | ||
| */ | ||
| event?: string | ||
| event?: string | undefined | ||
| /** | ||
@@ -38,3 +38,3 @@ * ID of the message, if any was provided by the server. Can be used by clients to keep the | ||
| */ | ||
| id?: string | ||
| id?: string | undefined | ||
| /** | ||
@@ -56,4 +56,4 @@ * The data received for this message | ||
| * Feeds the parser another chunk. The method _does not_ return a parsed message. | ||
| * Instead, if the chunk was a complete message (or completed a previously incomplete message), | ||
| * it will invoke the `onParse` callback used to create the parsers. | ||
| * Instead, callbacks passed when creating the parser will be triggered once we see enough data | ||
| * for a valid/invalid parsing step (see {@link ParserCallbacks}). | ||
| * | ||
@@ -91,11 +91,11 @@ * @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages. | ||
| */ | ||
| field?: string | ||
| field?: string | undefined | ||
| /** | ||
| * In the case of an unknown field encountered in the stream, this will be the value of the field. | ||
| */ | ||
| value?: string | ||
| value?: string | undefined | ||
| /** | ||
| * The line that caused the error, if available. | ||
| */ | ||
| line?: string | ||
| line?: string | undefined | ||
| constructor( | ||
@@ -125,3 +125,3 @@ message: string, | ||
| */ | ||
| onEvent?: (event: EventSourceMessage) => void | ||
| onEvent?: ((event: EventSourceMessage) => void) | undefined | ||
| /** | ||
@@ -132,3 +132,3 @@ * Callback for when the server sends a new reconnection interval through the `retry` field. | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
| /** | ||
@@ -139,3 +139,3 @@ * Callback for when a comment is encountered in the stream. | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
| /** | ||
@@ -148,5 +148,5 @@ * Callback for when an error occurs during parsing. This is a catch-all for any errors | ||
| */ | ||
| onError?: (error: ParseError) => void | ||
| onError?: ((error: ParseError) => void) | undefined | ||
| } | ||
| export {} |
+1
-1
@@ -91,3 +91,3 @@ class ParseError extends Error { | ||
| let lineEnd = -1; | ||
| if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) { | ||
| if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) { | ||
| incompleteLine = chunk.slice(searchIndex); | ||
@@ -94,0 +94,0 @@ break; |
@@ -18,3 +18,3 @@ /** | ||
| */ | ||
| event?: string | ||
| event?: string | undefined | ||
| /** | ||
@@ -24,3 +24,3 @@ * ID of the message, if any was provided by the server. Can be used by clients to keep the | ||
| */ | ||
| id?: string | ||
| id?: string | undefined | ||
| /** | ||
@@ -70,11 +70,11 @@ * The data received for this message | ||
| */ | ||
| field?: string | ||
| field?: string | undefined | ||
| /** | ||
| * In the case of an unknown field encountered in the stream, this will be the value of the field. | ||
| */ | ||
| value?: string | ||
| value?: string | undefined | ||
| /** | ||
| * The line that caused the error, if available. | ||
| */ | ||
| line?: string | ||
| line?: string | undefined | ||
| constructor( | ||
@@ -106,3 +106,3 @@ message: string, | ||
| */ | ||
| onError?: 'terminate' | ((error: Error) => void) | ||
| onError?: ('terminate' | ((error: Error) => void)) | undefined | ||
| /** | ||
@@ -113,3 +113,3 @@ * Callback for when a reconnection interval is sent from the server. | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
| /** | ||
@@ -120,5 +120,5 @@ * Callback for when a comment is encountered in the stream. | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
| } | ||
| export {} |
+8
-8
@@ -18,3 +18,3 @@ /** | ||
| */ | ||
| event?: string | ||
| event?: string | undefined | ||
| /** | ||
@@ -24,3 +24,3 @@ * ID of the message, if any was provided by the server. Can be used by clients to keep the | ||
| */ | ||
| id?: string | ||
| id?: string | undefined | ||
| /** | ||
@@ -70,11 +70,11 @@ * The data received for this message | ||
| */ | ||
| field?: string | ||
| field?: string | undefined | ||
| /** | ||
| * In the case of an unknown field encountered in the stream, this will be the value of the field. | ||
| */ | ||
| value?: string | ||
| value?: string | undefined | ||
| /** | ||
| * The line that caused the error, if available. | ||
| */ | ||
| line?: string | ||
| line?: string | undefined | ||
| constructor( | ||
@@ -106,3 +106,3 @@ message: string, | ||
| */ | ||
| onError?: 'terminate' | ((error: Error) => void) | ||
| onError?: ('terminate' | ((error: Error) => void)) | undefined | ||
| /** | ||
@@ -113,3 +113,3 @@ * Callback for when a reconnection interval is sent from the server. | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
| /** | ||
@@ -120,5 +120,5 @@ * Callback for when a comment is encountered in the stream. | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
| } | ||
| export {} |
+4
-4
| { | ||
| "name": "eventsource-parser", | ||
| "version": "3.0.3", | ||
| "version": "3.0.5", | ||
| "description": "Streaming, source-agnostic EventSource/Server-Sent Events parser", | ||
@@ -67,5 +67,5 @@ "sideEffects": false, | ||
| "devDependencies": { | ||
| "@sanity/pkg-utils": "^7.2.2", | ||
| "@sanity/pkg-utils": "^8.0.0", | ||
| "@sanity/semantic-release-preset": "^5.0.0", | ||
| "@types/node": "^18.0.0", | ||
| "@types/node": "^20.19.0", | ||
| "@typescript-eslint/eslint-plugin": "^7.0.0", | ||
@@ -79,3 +79,3 @@ "@typescript-eslint/parser": "^7.0.0", | ||
| "rimraf": "^6.0.1", | ||
| "rollup-plugin-visualizer": "^5.12.0", | ||
| "rollup-plugin-visualizer": "^6.0.3", | ||
| "semantic-release": "^24.2.3", | ||
@@ -82,0 +82,0 @@ "typescript": "^5.8.3", |
+1
-1
@@ -34,3 +34,3 @@ # eventsource-parser | ||
| console.log('id: %s', event.id || '<none>') | ||
| console.log('name: %s', event.name || '<none>') | ||
| console.log('event: %s', event.event || '<none>') | ||
| console.log('data: %s', event.data) | ||
@@ -37,0 +37,0 @@ } |
+3
-3
@@ -21,3 +21,3 @@ /** | ||
| */ | ||
| field?: string | ||
| field?: string | undefined | ||
@@ -27,3 +27,3 @@ /** | ||
| */ | ||
| value?: string | ||
| value?: string | undefined | ||
@@ -33,3 +33,3 @@ /** | ||
| */ | ||
| line?: string | ||
| line?: string | undefined | ||
@@ -36,0 +36,0 @@ constructor( |
+7
-1
@@ -203,3 +203,9 @@ /** | ||
| } else if (crIndex !== -1) { | ||
| lineEnd = crIndex | ||
| // CR at the end of a chunk might be part of a CRLF sequence that spans chunks, | ||
| // so we shouldn't treat it as a line terminator (yet) | ||
| if (crIndex === chunk.length - 1) { | ||
| lineEnd = -1 | ||
| } else { | ||
| lineEnd = crIndex | ||
| } | ||
| } else if (lfIndex !== -1) { | ||
@@ -206,0 +212,0 @@ lineEnd = lfIndex |
+3
-3
@@ -19,3 +19,3 @@ import {createParser} from './parse.ts' | ||
| */ | ||
| onError?: 'terminate' | ((error: Error) => void) | ||
| onError?: ('terminate' | ((error: Error) => void)) | undefined | ||
@@ -27,3 +27,3 @@ /** | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
@@ -35,3 +35,3 @@ /** | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
| } | ||
@@ -38,0 +38,0 @@ |
+8
-8
@@ -13,4 +13,4 @@ import type {ParseError} from './errors.ts' | ||
| * Feeds the parser another chunk. The method _does not_ return a parsed message. | ||
| * Instead, if the chunk was a complete message (or completed a previously incomplete message), | ||
| * it will invoke the `onParse` callback used to create the parsers. | ||
| * Instead, callbacks passed when creating the parser will be triggered once we see enough data | ||
| * for a valid/invalid parsing step (see {@link ParserCallbacks}). | ||
| * | ||
@@ -47,3 +47,3 @@ * @param chunk - The chunk to parse. Can be a partial, eg in the case of streaming messages. | ||
| */ | ||
| event?: string | ||
| event?: string | undefined | ||
@@ -54,3 +54,3 @@ /** | ||
| */ | ||
| id?: string | ||
| id?: string | undefined | ||
@@ -76,3 +76,3 @@ /** | ||
| */ | ||
| onEvent?: (event: EventSourceMessage) => void | ||
| onEvent?: ((event: EventSourceMessage) => void) | undefined | ||
@@ -84,3 +84,3 @@ /** | ||
| */ | ||
| onRetry?: (retry: number) => void | ||
| onRetry?: ((retry: number) => void) | undefined | ||
@@ -92,3 +92,3 @@ /** | ||
| */ | ||
| onComment?: (comment: string) => void | ||
| onComment?: ((comment: string) => void) | undefined | ||
@@ -102,3 +102,3 @@ /** | ||
| */ | ||
| onError?: (error: ParseError) => void | ||
| onError?: ((error: ParseError) => void) | undefined | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
76415
2.18%938
0.64%