Skip to content

Commit

Permalink
Breaking: modernize syntax and bump standard
Browse files Browse the repository at this point in the history
Drops support of node 6, node 8 and old browsers.

Ref Level/community#98
  • Loading branch information
vweevers committed Apr 8, 2021
1 parent c989e2a commit dd37269
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ sudo: false
language: node_js

node_js:
- 6
- 8
- 10
- 12
- 14

after_success: npm run coverage

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
## Usage

```js
var concat = require('level-concat-iterator')
var level = require('level')

level('DB', function (err, db) {
db.put('foo', 'bar', function (err) {
concat(db.iterator(), function (err, data) {
console.log(data)
})
const concat = require('level-concat-iterator')
const level = require('level')

const db = level('./db')

db.put('foo', 'bar', function (err) {
if (err) throw err

concat(db.iterator(), function (err, data) {
if (err) throw err

console.log(data)
})
})
```
Expand Down
17 changes: 9 additions & 8 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var level = require('level')
var concat = require('.')
const level = require('level')
const concat = require('.')

level('DB', function (err, db) {
const db = level('./db')

db.put('foo', 'bar', function (err) {
if (err) throw err
db.put('foo', 'bar', function (err) {

concat(db.iterator(), function (err, data) {
if (err) throw err
concat(db.iterator(), function (err, data) {
if (err) throw err
console.log(data)
})

console.log(data)
})
})
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict'

module.exports = function (iterator, cb) {
var data = []
var next = function () {
const data = []
const next = function () {
iterator.next(function (err, key, value) {
if (err || (key === undefined && value === undefined)) {
return iterator.end(function (err2) {
cb(err || err2, data)
})
}
data.push({ key: key, value: value })
data.push({ key, value })
next()
})
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"hallmark": "^3.1.0",
"level-community": "^3.0.0",
"nyc": "^14.0.0",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand All @@ -36,6 +36,6 @@
"array"
],
"engines": {
"node": ">=6"
"node": ">=10"
}
}
42 changes: 22 additions & 20 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
var test = require('tape')
var collect = require('.')
'use strict'

const test = require('tape')
const collect = require('.')

test('calls back with error if iterator.next errors', function (t) {
t.plan(3)

var iterator = {
next: function (cb) {
const iterator = {
next (cb) {
t.pass('iterator.next called')
process.nextTick(cb, new Error('iterator.next'))
},
end: function (cb) {
end (cb) {
t.pass('iterator.end called')
process.nextTick(cb)
}
Expand All @@ -23,14 +25,14 @@ test('calls back with error if iterator.next errors', function (t) {
test('happy path calls back with an array', function (t) {
t.plan(6)

var i = 0
var data = [
let i = 0
const data = [
{ key: 'key1', value: 'value1' },
{ key: 'key2', value: 'value2' }
]

var iterator = {
next: function (cb) {
const iterator = {
next (cb) {
t.pass('iterator.next called')
if (i < data.length) {
process.nextTick(cb, null, data[i].key, data[i].value)
Expand All @@ -39,7 +41,7 @@ test('happy path calls back with an array', function (t) {
process.nextTick(cb)
}
},
end: function (cb) {
end (cb) {
t.pass('iterator.end called')
process.nextTick(cb)
}
Expand All @@ -54,14 +56,14 @@ test('happy path calls back with an array', function (t) {
test('calls back with error and data if iterator.end errors', function (t) {
t.plan(6)

var i = 0
var data = [
let i = 0
const data = [
{ key: 'key1', value: 'value1' },
{ key: 'key2', value: 'value2' }
]

var iterator = {
next: function (cb) {
const iterator = {
next (cb) {
t.pass('iterator.next called')
if (i < data.length) {
process.nextTick(cb, null, data[i].key, data[i].value)
Expand All @@ -70,7 +72,7 @@ test('calls back with error and data if iterator.end errors', function (t) {
process.nextTick(cb)
}
},
end: function (cb) {
end (cb) {
t.pass('iterator.end called')
process.nextTick(cb, new Error('iterator.end'))
}
Expand All @@ -85,14 +87,14 @@ test('calls back with error and data if iterator.end errors', function (t) {
test('calls back with error and partial data if iterator.end errors', function (t) {
t.plan(5)

var i = 0
var data = [
let i = 0
const data = [
{ key: 'key1', value: 'value1' },
{ key: 'key2', value: 'value2' }
]

var iterator = {
next: function (cb) {
const iterator = {
next (cb) {
t.pass('iterator.next called')
if (i === 0) {
process.nextTick(cb, null, data[i].key, data[i].value)
Expand All @@ -101,7 +103,7 @@ test('calls back with error and partial data if iterator.end errors', function (
process.nextTick(cb)
}
},
end: function (cb) {
end (cb) {
t.pass('iterator.end called')
process.nextTick(cb, new Error('foo'))
}
Expand Down

0 comments on commit dd37269

Please sign in to comment.