11'use strict'
22
3+ const Buffer = require ( 'safe-buffer' ) . Buffer
34const StringDecoder = require ( 'string_decoder' ) . StringDecoder
45const decoder = new StringDecoder ( )
56const errors = require ( 'redis-errors' )
@@ -424,15 +425,18 @@ function concatBulkBuffer (parser) {
424425 * @constructor
425426 */
426427class 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 }
0 commit comments