Skip to content

Commit

Permalink
Breaking: modernize syntax and bump standard (Level/community#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 9, 2021
1 parent ae4c767 commit ce274c8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 99 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ updates:
ignore:
- dependency-name: dependency-check
- dependency-name: nyc
- dependency-name: standard
- dependency-name: tempy
15 changes: 8 additions & 7 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var iteratorStream = require('./')
var leveldown = require('leveldown')
var path = require('path')
const iteratorStream = require('.')
const leveldown = require('leveldown')
const path = require('path')

const db = leveldown(path.join(__dirname, 'db'))

var db = leveldown(path.join(__dirname, 'db'))
db.open(function (err) {
if (err) throw err

var ops = []
for (var i = 0; i < 1000; i++) {
const ops = []
for (let i = 0; i < 1000; i++) {
ops.push({
type: 'put',
key: String(Math.random()),
Expand All @@ -18,7 +19,7 @@ db.open(function (err) {
db.batch(ops, function (err) {
if (err) throw err

var stream = iteratorStream(db.iterator())
const stream = iteratorStream(db.iterator())
stream.on('data', function (kv) {
console.log('%s -> %s', kv.key, kv.value)
})
Expand Down
29 changes: 14 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var inherits = require('inherits')
var Readable = require('readable-stream').Readable
var extend = require('xtend')
'use strict'

const inherits = require('inherits')
const { Readable } = require('readable-stream')

module.exports = ReadStream
inherits(ReadStream, Readable)

function ReadStream (iterator, options) {
if (!(this instanceof ReadStream)) return new ReadStream(iterator, options)
options = options || {}
Readable.call(this, extend(options, {
Readable.call(this, Object.assign({}, options, {
objectMode: true
}))
this._iterator = iterator
Expand All @@ -17,22 +18,20 @@ function ReadStream (iterator, options) {
}

ReadStream.prototype._read = function () {
var self = this
var options = this._options
if (this.destroyed) return

this._iterator.next(function (err, key, value) {
if (self.destroyed) return
if (err) return self.destroy(err)
this._iterator.next((err, key, value) => {
if (this.destroyed) return
if (err) return this.destroy(err)

if (key === undefined && value === undefined) {
self.push(null)
} else if (options.keys !== false && options.values === false) {
self.push(key)
} else if (options.keys === false && options.values !== false) {
self.push(value)
this.push(null)
} else if (this._options.keys !== false && this._options.values === false) {
this.push(key)
} else if (this._options.keys === false && this._options.values !== false) {
this.push(value)
} else {
self.push({ key: key, value: value })
this.push({ key, value })
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"dependencies": {
"inherits": "^2.0.4",
"readable-stream": "^3.4.0",
"xtend": "^4.0.2"
"readable-stream": "^3.4.0"
},
"devDependencies": {
"coveralls": "^3.0.2",
Expand All @@ -24,9 +23,9 @@
"leveldown": "^5.0.0",
"nyc": "^14.0.0",
"secret-event-listener": "^1.0.0",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1",
"tempy": "0.2.1",
"tempy": "^1.0.1",
"through2": "^4.0.2"
},
"hallmark": {
Expand Down
Loading

0 comments on commit ce274c8

Please sign in to comment.