0.0.35 • Published 11 months ago

@datastream/csv v0.0.35

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@datastream/csv

Commonly used stream patterns for Web Streams API and NodeJS Streams.

  • Dependencies
  • Support
  • Install
  • Streams
    • Format
    • Parse

Dependencies

  • csv-rex: CSV parsing and formatting.

Support

NodeJSChromeEdgeFirefoxSafari
Format9.4677910210
Parse9.4677910210

Install

npm install @datastream/csv

Streams

Format

  • Input: object or array
  • Output: string

Options

From the csv-rex documentation:

Examples

Basic
import { pipeline } from '@datastream/core'
import { csvFormatStream } from '@datastream/csv'
// or
import csvFormatStream from '@datastream/csv/format'

const csvFormatStreamOptions = {}
const streams = [
  // Readable stream ...
  csvFormatStream(csvFormatStreamOptions),
  // Writable stream ...
]

await pipeline(...streams)
NodeJS: format and save to file
import { createWriteStream } from 'node:fs'
import { pipeline, createReadableStream, createTransformStream } from '@datastream/core'
import { csvParseStream } from '@datastream/csv'

const streams = [
	createReadableStream([{...},...]),
	createTransformStream(() => {...}),
	csvFormatStream({ header:[...] }),
	createWriteStream('/tmp/output.csv'),
]

await pipeline(...streams)

Parse

  • Input: string
  • Output: object or array

Options

See csv-rex for options

Examples

Basic
import { pipeline } from '@datastream/core'
import { csvParseStream } from '@datastream/csv'
// or
import csvParseStream from '@datastream/csv/parse'

const csvParseStreamOptions = {}
const streams = [
  // Readable stream ...
  csvParseStream(csvParseStreamOptions),
  // Writable stream ...
]

await pipeline(streams)
NodeJS: Read file and parse
import { createReadStream } from 'node:fs'
import { pipeline, createTransformStream, createWritableStream } from '@datastream/core'
import { csvParseStream } from '@datastream/csv'

const streams = [
	createReadStream('/tmp/input.csv'),
	csvParseStream({...}),
	createTransformStream(() => {...}),
	createWritableStream()
]

await pipeline(streams)
Browser: Read <input type="file"> and parse in a WebWorker

Examples

NodeJS

0.0.30

1 year ago

0.0.31

12 months ago

0.0.32

12 months ago

0.0.33

12 months ago

0.0.34

12 months ago

0.0.35

11 months ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago