diff --git a/.travis.yml b/.travis.yml index 8e18725..ff4ce38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ sudo: false language: node_js node_js: - - 6 - - 8 - 10 + - 12 + - 14 after_success: npm run coverage diff --git a/README.md b/README.md index c832132..72ed0dc 100644 --- a/README.md +++ b/README.md @@ -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) }) }) ``` diff --git a/example.js b/example.js index 624bc32..51f38be 100644 --- a/example.js +++ b/example.js @@ -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) }) }) diff --git a/index.js b/index.js index 1a267e0..4ed5c03 100644 --- a/index.js +++ b/index.js @@ -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() }) } diff --git a/package.json b/package.json index aad37aa..d323b1b 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -36,6 +36,6 @@ "array" ], "engines": { - "node": ">=6" + "node": ">=10" } } diff --git a/test.js b/test.js index bf09227..905c346 100644 --- a/test.js +++ b/test.js @@ -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) } @@ -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) @@ -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) } @@ -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) @@ -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')) } @@ -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) @@ -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')) }