Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
use ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jun 4, 2017
1 parent 2c33c41 commit 915db03
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "0.12"
- "4"
- "5"
- "6"
- "7"
- "8"
sudo: false
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2016 thunks
Copyright (c) 2015-2017 thunks

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
thunk-stream
====
# thunk-stream

Wrap a readable/writable/duplex/transform stream to a thunk.

[![NPM version][npm-image]][npm-url]
Expand All @@ -11,12 +11,12 @@ Wrap a readable/writable/duplex/transform stream to a thunk.
## Demo

```js
var thunkStream = require('thunk-stream')
var stream = require('stream')
var fs = require('fs')
const thunkStream = require('thunk-stream')
const stream = require('stream')
const fs = require('fs')

var readableStream = fs.createReadStream('index.js')
var passStream = new stream.PassThrough()
const readableStream = fs.createReadStream('index.js')
const passStream = new stream.PassThrough()

thunkStream(readableStream)(function (error) {
if (error) console.error('error', error)
Expand All @@ -39,7 +39,7 @@ npm install thunk-stream
## API

```js
var thunkStream = require('thunk-stream')
const thunkStream = require('thunk-stream')
```

### thunkStream(stream[, options])
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
//
// **License:** MIT

var thunk = require('thunks')()
var defaultEndEventTypes = ['end', 'finish', 'close']
const thunk = require('thunks')()
const defaultEndEventTypes = ['end', 'finish', 'close']

function forEach (obj, iterator) {
for (var i = 0, l = obj.length; i < l; i++) iterator(obj[i], i, obj)
for (let i = 0, l = obj.length; i < l; i++) iterator(obj[i], i, obj)
}

module.exports = function thunkStream (stream, options) {
options = options || {}

var resultThunk = thunk.call(this, function (callback) {
var clear = false
var flags = Object.create(null)
var endEventTypes = []
var endEventType = options.endEventType
const resultThunk = thunk.call(this, function (callback) {
const flags = Object.create(null)
const endEventTypes = []
const endEventType = options.endEventType
let clear = false

function onend () {
removeListener()
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"authors": [
"Yan Qing <[email protected]>"
],
"version": "1.1.8",
"version": "1.2.0",
"main": "index.js",
"repository": {
"type": "git",
"url": "[email protected]:thunks/thunk-stream.git"
},
"homepage": "https://github.com/thunks/thunk-stream",
"engines": {
"node": ">= 4"
},
"keywords": [
"thunk",
"thunks",
Expand All @@ -24,11 +27,11 @@
"wait"
],
"dependencies": {
"thunks": "^4.7.5"
"thunks": "^4.8.0"
},
"devDependencies": {
"standard": "^8.3.0",
"tman": "^1.6.0"
"standard": "^10.0.2",
"tman": "^1.6.9"
},
"scripts": {
"test": "standard && tman"
Expand Down
42 changes: 21 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'
/* global describe, it */

var assert = require('assert')
var thunkStream = require('../index.js')
var stream = require('stream')
var fs = require('fs')
const assert = require('assert')
const thunkStream = require('../index.js')
const stream = require('stream')
const fs = require('fs')
const tman = require('tman')

describe('thunk-stream', function () {
it('thunkStream(readableStream) success', function (done) {
var readableStream = fs.createReadStream('index.js')
var passStream = new stream.PassThrough()
tman.suite('thunk-stream', function () {
tman.it('thunkStream(readableStream) success', function (done) {
let readableStream = fs.createReadStream('index.js')
let passStream = new stream.PassThrough()

var readableStreamEnded = false
let readableStreamEnded = false

thunkStream(readableStream)(function (error) {
assert.strictEqual(error, null)
Expand All @@ -28,9 +28,9 @@ describe('thunk-stream', function () {
readableStream.pipe(passStream)
})

it('thunkStream(readableStream) error', function (done) {
var readableStream = fs.createReadStream('none.js')
var passStream = new stream.PassThrough()
tman.it('thunkStream(readableStream) error', function (done) {
let readableStream = fs.createReadStream('none.js')
let passStream = new stream.PassThrough()

thunkStream(readableStream)(function (error) {
assert.strictEqual(error instanceof Error, true)
Expand All @@ -44,10 +44,10 @@ describe('thunk-stream', function () {
readableStream.pipe(passStream)
})

it('thunkStream(writableStream) success', function (done) {
var readableStream = fs.createReadStream('index.js')
var writableStream = new stream.Writable()
var readableStreamEnded = false
tman.it('thunkStream(writableStream) success', function (done) {
let readableStream = fs.createReadStream('index.js')
let writableStream = new stream.Writable()
let readableStreamEnded = false

writableStream._write = function (chunk, encoding, cb) {
cb(null, chunk)
Expand All @@ -68,9 +68,9 @@ describe('thunk-stream', function () {
readableStream.pipe(writableStream)
})

it('thunkStream(writableStream).clearListeners()', function (done) {
var readableStream = fs.createReadStream('index.js')
var writableStream = new stream.Writable()
tman.it('thunkStream(writableStream).clearListeners()', function (done) {
let readableStream = fs.createReadStream('index.js')
let writableStream = new stream.Writable()

writableStream._write = function (chunk, encoding, cb) {
cb(null, chunk)
Expand All @@ -81,7 +81,7 @@ describe('thunk-stream', function () {
assert.strictEqual(readableStream.closed, true)
})

var thunk = thunkStream(writableStream)
let thunk = thunkStream(writableStream)
// clearListeners is add after thunk called.
assert.strictEqual(thunk.clearListeners, undefined)
thunk(function (_) {
Expand Down

0 comments on commit 915db03

Please sign in to comment.