summaryrefslogtreecommitdiff
path: root/node_modules/ldjson-stream
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:50:21 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 15:50:21 +0800
commit0379526e20e1ff212df23e6326741aa9c06df204 (patch)
tree340143b0c4dc4280c88ba1591d137b53477005b3 /node_modules/ldjson-stream
parent7aba14fb7c970c6e6af82c805db2aef6d70bfe2b (diff)
added doiuse plugin for postcss
Diffstat (limited to 'node_modules/ldjson-stream')
-rw-r--r--node_modules/ldjson-stream/.npmignore1
-rw-r--r--node_modules/ldjson-stream/index.js32
-rw-r--r--node_modules/ldjson-stream/package.json25
-rw-r--r--node_modules/ldjson-stream/readme.md55
-rw-r--r--node_modules/ldjson-stream/test.js35
5 files changed, 148 insertions, 0 deletions
diff --git a/node_modules/ldjson-stream/.npmignore b/node_modules/ldjson-stream/.npmignore
new file mode 100644
index 00000000..b512c09d
--- /dev/null
+++ b/node_modules/ldjson-stream/.npmignore
@@ -0,0 +1 @@
+node_modules \ No newline at end of file
diff --git a/node_modules/ldjson-stream/index.js b/node_modules/ldjson-stream/index.js
new file mode 100644
index 00000000..d827fb4f
--- /dev/null
+++ b/node_modules/ldjson-stream/index.js
@@ -0,0 +1,32 @@
+var through = require('through2')
+var split = require('split2')
+var EOL = require('os').EOL
+
+module.exports = parse
+module.exports.serialize = serialize
+module.exports.parse = parse
+
+function parse(opts) {
+ opts = opts || {}
+ opts.strict = opts.strict !== false
+
+ function strict(row) {
+ if (row) return JSON.parse(row)
+ }
+
+ function nonStrict(row) {
+ try {
+ if (row) return JSON.parse(row)
+ } catch(e) {
+ // ignore
+ }
+ }
+
+ return opts.strict ? split(strict) : split(nonStrict)
+}
+
+function serialize() {
+ return through.obj(function(obj, enc, cb) {
+ cb(null, JSON.stringify(obj) + EOL)
+ })
+}
diff --git a/node_modules/ldjson-stream/package.json b/node_modules/ldjson-stream/package.json
new file mode 100644
index 00000000..ba64dbf0
--- /dev/null
+++ b/node_modules/ldjson-stream/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "ldjson-stream",
+ "version": "1.2.1",
+ "description": "streaming line delimited json parser + serializer",
+ "main": "index.js",
+ "scripts": {
+ "test": "tape test.js"
+ },
+ "author": "max ogden",
+ "license": "BSD",
+ "dependencies": {
+ "split2": "^0.2.1",
+ "through2": "^0.6.1"
+ },
+ "devDependencies": {
+ "tape": "^2.13.3"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/maxogden/ldjson-stream.git"
+ },
+ "bugs": {
+ "url": "https://github.com/maxogden/ldjson-stream/issues"
+ }
+}
diff --git a/node_modules/ldjson-stream/readme.md b/node_modules/ldjson-stream/readme.md
new file mode 100644
index 00000000..d6a99c55
--- /dev/null
+++ b/node_modules/ldjson-stream/readme.md
@@ -0,0 +1,55 @@
+# ldjson-stream
+
+#### streaming line delimited json parser + serializer
+
+[![NPM](https://nodei.co/npm/ldjson-stream.png)](https://nodei.co/npm/ldjson-stream/)
+
+## usage
+
+```
+var ldj = require('ldjson-stream')
+```
+
+#### ldj.parse()
+
+returns a transform stream that accepts newline delimited json and emits objects
+
+example newline delimited json:
+
+`data.txt`:
+
+```
+{"foo": "bar"}
+{"hello": "world"}
+```
+
+If you want to discard non-valid JSON messages, you can call `ldj.parse({strict: false})`
+
+usage:
+
+```js
+fs.createReadStream('data.txt')
+ .pipe(ldj.parse())
+ .on('data', function(obj) {
+ // obj is a javascript object
+ })
+```
+
+#### ldj.serialize()
+
+returns a transform stream that accepts json objects and emits newline delimited json
+
+example usage:
+
+```js
+var serialize = ldj.serialize()
+serialize.on('data', function(line) {
+ // line is a line of stringified JSON with a newline delimiter at the end
+})
+serialize.write({"foo": "bar"})
+serialize.end()
+```
+
+### license
+
+BSD
diff --git a/node_modules/ldjson-stream/test.js b/node_modules/ldjson-stream/test.js
new file mode 100644
index 00000000..9a2da0e1
--- /dev/null
+++ b/node_modules/ldjson-stream/test.js
@@ -0,0 +1,35 @@
+var test = require('tape')
+var ldj = require('./')
+var os = require('os')
+
+test('.parse', function(t) {
+ var parser = ldj.parse()
+ parser.on('data', function(obj) {
+ t.equal(obj.hello, 'world')
+ t.end()
+ })
+
+ parser.write('{"hello": "world"}\n')
+})
+
+test('.parse twice', function(t) {
+ var parser = ldj.parse()
+ parser.once('data', function(obj) {
+ t.equal(obj.hello, 'world')
+ parser.once('data', function(obj) {
+ t.equal(obj.hola, 'mundo')
+ t.end()
+ })
+ })
+
+ parser.write('{"hello": "world"}\n{"hola": "mundo"}\n')
+})
+
+test('.serialize', function(t) {
+ var serializer = ldj.serialize()
+ serializer.on('data', function(data) {
+ t.equal(data, '{"hello":"world"}' + os.EOL)
+ t.end()
+ })
+ serializer.write({hello: 'world'})
+})