From 7992af4f72d6762982d85471ef422059f0cbd566 Mon Sep 17 00:00:00 2001 From: saintedlama Date: Sat, 4 Jan 2020 20:39:55 +0100 Subject: [PATCH] chore: simplify code --- index.js | 24 ++++++++++++------------ lib/errors.js | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 103d8f1..f366fa2 100644 --- a/index.js +++ b/index.js @@ -13,18 +13,18 @@ module.exports = function(schema, options) { options.encoding = options.encoding || 'hex'; options.digestAlgorithm = options.digestAlgorithm || 'sha256'; // To get a list of supported hashes use crypto.getHashes() - options.passwordValidator = - options.passwordValidator || - function(password, cb) { - cb(null); - }; - options.passwordValidatorAsync = - options.passwordValidatorAsync || - function(password) { - return new Promise((resolve, reject) => { - options.passwordValidator(password, err => (err ? reject(err) : resolve())); - }); - }; + function defaultPasswordValidator(password, cb) { + cb(null); + } + + function defaultPasswordValidatorAsync(password) { + return new Promise((resolve, reject) => { + options.passwordValidator(password, err => (err ? reject(err) : resolve())); + }); + } + + options.passwordValidator = options.passwordValidator || defaultPasswordValidator; + options.passwordValidatorAsync = options.passwordValidatorAsync || defaultPasswordValidatorAsync; // Populate field names with defaults if not set options.usernameField = options.usernameField || 'username'; diff --git a/lib/errors.js b/lib/errors.js index 1251ce5..2b2dd7f 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -3,7 +3,7 @@ const generaterr = require('generaterr'); const AuthenticationError = generaterr('AuthenticationError'); module.exports = { - AuthenticationError: AuthenticationError, + AuthenticationError, IncorrectUsernameError: generaterr('IncorrectUsernameError', null, { inherits: AuthenticationError }), IncorrectPasswordError: generaterr('IncorrectPasswordError', null, { inherits: AuthenticationError }), MissingUsernameError: generaterr('MissingUsernameError', null, { inherits: AuthenticationError }),