json-lines-kit
Advanced tools
Comparing version 0.1.0 to 0.2.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var NEW_LINE = '\n'; | ||
var JSONLinesStream = (function () { | ||
@@ -17,10 +16,11 @@ function JSONLinesStream(callback) { | ||
JSONLinesStream.prototype.popLineFromBuffer = function () { | ||
var firstNewLine = this.buffer.indexOf(NEW_LINE) + 1; | ||
if (firstNewLine) { | ||
return; | ||
var firstNewLineCluster = this.buffer.match(/(\n+)/); | ||
if (!firstNewLineCluster) { | ||
return null; | ||
} | ||
var candidateJsonLine = this.buffer.slice(0, firstNewLine).trim(); | ||
var firstNewLineBreakPoint = firstNewLineCluster.index + firstNewLineCluster[1].length; | ||
var candidateJsonLine = this.buffer.slice(0, firstNewLineBreakPoint).trim(); | ||
try { | ||
var line = JSON.parse(candidateJsonLine); | ||
this.buffer = this.buffer.slice(firstNewLine); | ||
this.buffer = this.buffer.slice(firstNewLineBreakPoint); | ||
return line; | ||
@@ -37,6 +37,8 @@ } | ||
JSONLinesStream.prototype.consumeBuffer = function () { | ||
var line = this.popLineFromBuffer(); | ||
var line; | ||
do { | ||
this.emit(line); | ||
line = this.popLineFromBuffer(); | ||
if (line) { | ||
this.emit(line); | ||
} | ||
} while (line); | ||
@@ -43,0 +45,0 @@ }; |
{ | ||
"name": "json-lines-kit", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Lightweight toolkit for dealing with JSON lines", | ||
@@ -22,5 +22,6 @@ "main": "lib/main.js", | ||
"tsc": "tsc", | ||
"test": "mocha -r ts-node/register src/**/*.spec.ts" | ||
"test": "mocha -r ts-node/register src/**/*.spec.ts", | ||
"prepublish": "tsc" | ||
}, | ||
"dependencies": {} | ||
} |
# json-lines-kit | ||
[![Build Status](https://travis-ci.com/sourcelair/json-lines-kit.svg?branch=master)](https://travis-ci.com/sourcelair/json-lines-kit) | ||
json-lines-kit is a set of lightweight utilities for dealing with the [JSON Lines format](http://jsonlines.org/). | ||
@@ -4,0 +6,0 @@ |
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
8564
178
15