sdf-parser 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ const empty = {};
2
+
3
+ export default empty;
package/src/stream.js ADDED
@@ -0,0 +1,44 @@
1
+ import pipeline from 'pumpify';
2
+ import split2 from 'split2';
3
+ import through2 from 'through2';
4
+ import filter from 'through2-filter';
5
+
6
+ import { parse } from './parse';
7
+
8
+ const filterStream = filter.bind(null, { objectMode: true });
9
+ function filterCb(chunk) {
10
+ return chunk.length > 1 && chunk.trim().length > 1;
11
+ }
12
+
13
+ export function entries() {
14
+ return pipeline.obj(
15
+ split2(/\r?\n\${4}.*\r?\n/),
16
+ filterStream(filterCb),
17
+ through2({ objectMode: true }, function process(value, encoding, callback) {
18
+ const eol = value.includes('\r\n') ? '\r\n' : '\n';
19
+ this.push(`${value + eol}$$$$${eol}`);
20
+ callback();
21
+ }),
22
+ );
23
+ }
24
+
25
+ export function molecules(options) {
26
+ return pipeline.obj(
27
+ entries(),
28
+ through2({ objectMode: true }, function process(value, encoding, callback) {
29
+ try {
30
+ const parsed = parse(value, options);
31
+ if (parsed.molecules.length === 1) {
32
+ if (options && options.fullResult) {
33
+ this.push(parsed);
34
+ } else {
35
+ this.push(parsed.molecules[0]);
36
+ }
37
+ }
38
+ callback();
39
+ } catch (e) {
40
+ callback(e);
41
+ }
42
+ }),
43
+ );
44
+ }