dobo-extra 2.2.0 → 2.3.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,42 @@
1
+ import ndjson from 'ndjson'
2
+ import { Readable } from 'stream'
3
+ import fs from 'fs'
4
+
5
+ const ndjsonReadHandler = function (data, opts = {}) {
6
+ return new Promise((resolve, reject) => {
7
+ const reader = opts.readFromFile ? fs.createReadStream(data) : Readable.from(data)
8
+ const results = []
9
+ reader.pipe(ndjson.parse({ strict: opts.strict ?? true }))
10
+ .on('data', data => {
11
+ results.push(data)
12
+ })
13
+ .on('error', reject)
14
+ .on('end', () => {
15
+ resolve(results)
16
+ })
17
+ })
18
+ }
19
+
20
+ const ndjsonWriteHandler = function (data, opts = {}) {
21
+ return new Promise((resolve, reject) => {
22
+ const stream = ndjson.stringify()
23
+ const results = []
24
+ stream.on('data', line => {
25
+ results.push(line)
26
+ })
27
+ stream.on('finish', () => {
28
+ const items = results.join('\n')
29
+ if (opts.writeToFile) {
30
+ fs.writeFileSync(data, items, 'utf8')
31
+ resolve()
32
+ } else resolve(items)
33
+ })
34
+ stream.write(data)
35
+ stream.end()
36
+ })
37
+ }
38
+
39
+ export default [
40
+ { ext: '.ndjson', readHandler: ndjsonReadHandler, writeHandler: ndjsonWriteHandler },
41
+ { ext: '.jsonl', readHandler: ndjsonReadHandler, writeHandler: ndjsonWriteHandler }
42
+ ]
package/lib/export-to.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import path from 'path'
2
- import format from './ndjson-csv-xlsx.js'
2
+ import { json, ndjson, csv, xlsx } from './ndjson-csv-xlsx.js'
3
3
  import { createGzip } from 'node:zlib'
4
4
  import scramjet from 'scramjet'
5
5
  import supportedExt from './io-exts.js'
6
6
 
7
7
  const { DataStream } = scramjet
8
- const { json, ndjson, csv, xlsx } = format
9
8
 
10
9
  async function getFile (dest, ensureDir) {
11
10
  const { importPkg, getPluginDataDir } = this.app.bajo
@@ -1,11 +1,10 @@
1
1
  import path from 'path'
2
- import format from './ndjson-csv-xlsx.js'
2
+ import { json, ndjson, csv, xlsx } from './ndjson-csv-xlsx.js'
3
3
  import { createGunzip } from 'zlib'
4
4
  import supportedExt from './io-exts.js'
5
5
  import scramjet from 'scramjet'
6
6
 
7
7
  const { DataStream } = scramjet
8
- const { json, ndjson, csv, xlsx } = format
9
8
 
10
9
  async function importFrom (source, dest, { trashOld = true, batch = 1, progressFn, converterFn, useHeader = true, fileType, createOpts = {} } = {}, opts = {}) {
11
10
  const { getPluginDataDir } = this.app.bajo
@@ -1,7 +1,7 @@
1
1
  // Borrowed from: https://github.com/fanlia/ndjson-csv-xlsx/blob/main/index.js
2
2
 
3
- import ndjson from 'ndjson'
4
- import csv from 'fast-csv'
3
+ import ndj from 'ndjson'
4
+ import fastCsv from 'fast-csv'
5
5
  import xlsxparse from 'xlsx-parse-stream'
6
6
  import XLSXWriteStream from '@atomictech/xlsx-write-stream'
7
7
  import StreamArray from 'stream-json/streamers/StreamArray.js'
@@ -11,27 +11,28 @@ import chain from 'stream-chain'
11
11
 
12
12
  const XLSXStreamer = XLSXWriteStream.default
13
13
 
14
- export default {
15
- ndjson: {
16
- parse: (...args) => ndjson.parse(...args),
17
- stringify: (...args) => ndjson.stringify(...args)
18
- },
19
- csv: {
20
- parse: (...args) => csv.parse(...args),
21
- stringify: (...args) => csv.format(...args)
22
- },
23
- xlsx: {
24
- parse: (...args) => xlsxparse(...args),
25
- stringify: (...args) => new XLSXStreamer(...args)
26
- },
27
- json: {
28
- parse: (...args) => chain([
29
- StreamArray.withParser(...args),
30
- data => data.value
31
- ]),
32
- stringify: (options, ...args) => chain([
33
- new Disassembler(),
34
- new Stringer({ ...options, makeArray: true })
35
- ])
36
- }
14
+ export const ndjson = {
15
+ parse: (...args) => ndj.parse(...args),
16
+ stringify: (...args) => ndj.stringify(...args)
17
+ }
18
+
19
+ export const csv = {
20
+ parse: (...args) => fastCsv.parse(...args),
21
+ stringify: (...args) => fastCsv.format(...args)
22
+ }
23
+
24
+ export const xlsx = {
25
+ parse: (...args) => xlsxparse(...args),
26
+ stringify: (...args) => new XLSXStreamer(...args)
27
+ }
28
+
29
+ export const json = {
30
+ parse: (...args) => chain([
31
+ StreamArray.withParser(...args),
32
+ data => data.value
33
+ ]),
34
+ stringify: (options, ...args) => chain([
35
+ new Disassembler(),
36
+ new Stringer({ ...options, makeArray: true })
37
+ ])
37
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo-extra",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Bajo DB Extra Tools/Utility",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-03-22
4
+
5
+ - [2.3.0] Add ```.ndjson``` and published to be a ```config handler```
6
+
3
7
  ## 2025-12-28
4
8
 
5
9
  - [2.1.0] Ported to ```bajo@2.2.x``` & ```dobo@2.2.x``` specs