json-text-sequence
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -1,9 +0,6 @@ | ||
'use strict' | ||
import {DelimitedStream} from '@sovpro/delimited-stream' | ||
import {Transform} from 'stream' | ||
const stream = require('stream') | ||
const {DelimitedStream} = require('@sovpro/delimited-stream') | ||
export const RS = '\x1e' | ||
const RS = '\x1e' | ||
exports.RS = RS | ||
// Parse a JSON text sequence stream as defined in | ||
@@ -43,7 +40,7 @@ // {http://tools.ietf.org/html/draft-ietf-json-text-sequence | ||
// process.stdin.pipe(p); | ||
class JSONSequenceParser extends stream.Transform { | ||
export class JSONSequenceParser extends Transform { | ||
/** | ||
* Create a JSONSequenceParser instance. | ||
* | ||
* @param {stream.TransformOptions} [opts] Stream options. | ||
* @param {import('stream').TransformOptions} [opts] Stream options. | ||
*/ | ||
@@ -86,6 +83,2 @@ constructor(opts = {}) { | ||
/** @deprecated */ | ||
exports.parser = JSONSequenceParser | ||
exports.Parser = JSONSequenceParser | ||
// Generate a JSON text sequence stream as defined in | ||
@@ -101,7 +94,7 @@ // {http://tools.ietf.org/html/draft-ietf-json-text-sequence | ||
// g.write({foo: true, bar: 1}) | ||
class JSONSequenceGenerator extends stream.Transform { | ||
export class JSONSequenceGenerator extends Transform { | ||
/** | ||
* Create a JSONSequenceGenerator instance. | ||
* | ||
* @param {stream.TransformOptions} [opts] Stream options. | ||
* @param {import('stream').TransformOptions} [opts] Stream options. | ||
*/ | ||
@@ -130,4 +123,5 @@ constructor(opts = {}) { | ||
/** @deprecated */ | ||
exports.generator = JSONSequenceGenerator | ||
exports.Generator = JSONSequenceGenerator | ||
export { | ||
JSONSequenceParser as Parser, | ||
JSONSequenceGenerator as Generator, | ||
} |
{ | ||
"name": "json-text-sequence", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Parse and generate RS-delimited JSON sequences according to draft-ietf-json-text-sequence", | ||
"main": "./lib/index.js", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"type": "module", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
"clean": "rm -rf coverage", | ||
"coverage": "nyc -r lcov npm test", | ||
"test": "ava test/*.js", | ||
"release": "npm version patch && git push --follow-tags && npm publish", | ||
"test": "c8 ava", | ||
"lint": "eslint . --ext js", | ||
@@ -39,14 +35,14 @@ "types": "tsc", | ||
"devDependencies": { | ||
"@cto.af/eslint-config": "^0.1.3", | ||
"@types/node": "^17.0.30", | ||
"ava": "^4.2.0", | ||
"eslint": "^7.32.0", | ||
"eslint-plugin-ava": "^13.2.0", | ||
"@cto.af/eslint-config": "^1.1.2", | ||
"@types/node": "^20.1.4", | ||
"ava": "^5.2.0", | ||
"c8": "7.13.0", | ||
"eslint": "^8.40.0", | ||
"eslint-plugin-ava": "^14.0.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"nyc": "^15.1.0", | ||
"typescript": "^4.6.4" | ||
"typescript": "^5.0.4" | ||
}, | ||
"engines": { | ||
"node": ">=12.20.0" | ||
"node": ">=16" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
# json-text-sequence | ||
Parse and generate JSON text sequences as defined in [RFC 7464](https://tools.ietf.org/html/rfc7464). | ||
@@ -13,42 +15,53 @@ | ||
To install: | ||
## Installation | ||
npm install json-text-sequence | ||
## API | ||
### Parsing | ||
To parse the format, pipe an input source into a parser stream: | ||
const parser = require('json-text-sequence').parser; | ||
const fs = require('fs'); | ||
```js | ||
import {Parser} from 'json-text-sequence' | ||
import fs from 'fs' | ||
const p = new parser() | ||
.on('data', obj => { | ||
console.log('JSON:', obj); | ||
}) | ||
.on('truncated', buf => { | ||
console.log('Truncated:', buf); | ||
}) | ||
.on('invalid', buf => { | ||
console.log('Invalid:', buf); | ||
}) | ||
.on('finish', () => { | ||
console.log('DONE'); | ||
}); | ||
const p = new Parser() | ||
.on('data', obj => { | ||
console.log('JSON:', obj); | ||
}) | ||
.on('truncated', buf => { | ||
console.log('Truncated:', buf); | ||
}) | ||
.on('invalid', buf => { | ||
console.log('Invalid:', buf); | ||
}) | ||
.on('finish', () => { | ||
console.log('DONE'); | ||
}); | ||
fs.createReadStream('example.log').pipe(p); | ||
fs.createReadStream('example.log').pipe(p); | ||
``` | ||
### Generation | ||
To generate the format, create a generator, pipe its output somewhere | ||
interesting, then write objects to the generator: | ||
const generator = require('json-text-sequence').generator; | ||
const fs = require('fs'); | ||
```js | ||
import {Generator} from 'json-text-sequence' | ||
import fs from 'fs' | ||
const g = new generator(); | ||
g.pipe(fs.createWriteStream('example.log')); | ||
const g = new Generator(); | ||
g.pipe(fs.createWriteStream('example.log')); | ||
g.write({ | ||
d: new Date(), | ||
count: 0 | ||
}); | ||
g.write({ | ||
d: new Date(), | ||
count: 0 | ||
}); | ||
``` | ||
--- | ||
[![Tests](https://github.com/hildjj/json-text-sequence/workflows/Tests/badge.svg)](https://github.com/hildjj/json-text-sequence/actions?query=workflow%3ATests) | ||
[![Coverage Status](https://coveralls.io/repos/hildjj/json-text-sequence/badge.png?branch=main)](https://coveralls.io/r/hildjj/json-text-sequence?branch=main) |
export const RS: "\u001E"; | ||
declare class JSONSequenceParser extends stream.Transform { | ||
export class JSONSequenceParser extends Transform { | ||
_stream: DelimitedStream; | ||
_transform(chunk: any, encoding: any, cb: any): void; | ||
_final(cb: any): void; | ||
} | ||
declare class JSONSequenceGenerator extends stream.Transform { | ||
export class JSONSequenceGenerator extends Transform { | ||
_transform(chunk: any, encoding: any, cb: any): any; | ||
} | ||
import stream = require("stream"); | ||
import { DelimitedStream } from "@sovpro/delimited-stream"; | ||
export { JSONSequenceParser as parser, JSONSequenceParser as Parser, JSONSequenceGenerator as generator, JSONSequenceGenerator as Generator }; | ||
import { Transform } from 'stream'; | ||
import { DelimitedStream } from '@sovpro/delimited-stream'; | ||
export { JSONSequenceParser as Parser, JSONSequenceGenerator as Generator }; |
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
67
Yes
8185
126