npm

@strong-roots-capital/stream-days
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

stream-days Build status npm version codecov

Create a Readable stream of Date objects separated by one day

Install

npm install @strong-roots-capital/stream-days

Use

import streamDays from '@strong-roots-capital/stream-days'
import { Writable } from 'readable-stream'
import * as moment from 'moment'

let dates: Date[] = []

const sink = new Writable({
    objectMode: true,
    write(date: Date, _: string, callback: any) {
        dates.push(date)
        callback()
    }
})

const start = moment.utc().toDate()
const end = moment.utc().add(2, 'days').toDate()
streamDays(start, end).pipe(sink)

sink.on('finish', () => console.log(dates))
//=> [ 2019-02-22T22:42:00.812Z, 2019-02-23T22:42:00.812Z, 2019-02-24T22:42:00.812Z ]

Package Sidebar

Install

npm i @strong-roots-capital/stream-days

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

6.75 kB

Total Files

4

Last publish

Collaborators

  • amchelle
  • hamroctopus