Skip to content

Commit adafd01

Browse files
committed
chore: keep Node.js v.4 support
1 parent 8cf4d10 commit adafd01

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ addons:
99
packages:
1010
- g++-4.8
1111
node_js:
12+
- "4"
1213
- "6"
1314
- "7"
1415
install:

benchmark/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const Benchmark = require('benchmark')
66
const suite = new Benchmark.Suite()
77
const Parser = require('./../')
8+
const Buffer = require('safe-buffer').Buffer
89
const HiredisParser = require('../test/hiredis')
910

1011
function returnError (error) {}

lib/parser.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const Buffer = require('safe-buffer').Buffer
34
const StringDecoder = require('string_decoder').StringDecoder
45
const decoder = new StringDecoder()
56
const errors = require('redis-errors')
@@ -424,15 +425,18 @@ function concatBulkBuffer (parser) {
424425
* @constructor
425426
*/
426427
class JavascriptRedisParser {
427-
constructor ({ returnReply, returnError, returnFatalError, returnBuffers, stringNumbers }) {
428-
if (typeof returnError !== 'function' || typeof returnReply !== 'function') {
428+
constructor (options) {
429+
if (!options) {
430+
throw new TypeError('Options are mandatory.')
431+
}
432+
if (typeof options.returnError !== 'function' || typeof options.returnReply !== 'function') {
429433
throw new TypeError('The returnReply and returnError options have to be functions.')
430434
}
431-
this.setReturnBuffers(returnBuffers)
432-
this.setStringNumbers(stringNumbers)
433-
this.returnError = returnError
434-
this.returnFatalError = returnFatalError || returnError
435-
this.returnReply = returnReply
435+
this.setReturnBuffers(!!options.returnBuffers)
436+
this.setStringNumbers(!!options.stringNumbers)
437+
this.returnError = options.returnError
438+
this.returnFatalError = options.returnFatalError || options.returnError
439+
this.returnReply = options.returnReply
436440
this.reset()
437441
}
438442

@@ -458,7 +462,7 @@ class JavascriptRedisParser {
458462
* @param returnBuffers
459463
* @returns {undefined}
460464
*/
461-
setReturnBuffers (returnBuffers = false) {
465+
setReturnBuffers (returnBuffers) {
462466
if (typeof returnBuffers !== 'boolean') {
463467
throw new TypeError('The returnBuffers argument has to be a boolean')
464468
}
@@ -471,7 +475,7 @@ class JavascriptRedisParser {
471475
* @param stringNumbers
472476
* @returns {undefined}
473477
*/
474-
setStringNumbers (stringNumbers = false) {
478+
setStringNumbers (stringNumbers) {
475479
if (typeof stringNumbers !== 'boolean') {
476480
throw new TypeError('The stringNumbers argument has to be a boolean')
477481
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"node": ">=6"
3131
},
3232
"dependencies": {
33-
"redis-errors": "^1.0.0"
33+
"redis-errors": "^1.0.0",
34+
"safe-buffer": "^5.0.1"
3435
},
3536
"devDependencies": {
3637
"benchmark": "^2.1.0",

test/parsers.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const assert = require('assert')
77
const util = require('util')
8+
const Buffer = require('safe-buffer').Buffer
89
const JavascriptParser = require('../')
910
const HiredisParser = require('./hiredis')
1011
const errors = require('redis-errors')

0 commit comments

Comments
 (0)