Skip to content

Commit

Permalink
Add support for Sideway/Joi (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez authored Jul 20, 2020
1 parent 25b3ae3 commit 7fa28dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
20 changes: 20 additions & 0 deletions lib/get.joi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const softRequire = (path) => {
try {
// eslint-disable-next-line import/no-dynamic-require
return require(path);
} catch (ignoreError) {
return null;
}
};

const getJoi = () => {
const joi = softRequire('joi') || softRequire('@hapi/joi');

if (!joi) {
throw new Error('joi-password-complexity requires either `joi` or `@hapi/joi` to be installed.');
}

return joi;
};

module.exports = getJoi;
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Joi = require('@hapi/joi');
const Joi = require('./get.joi.js')();

// pluralize
const p = (word, num) => (num === 1 ? word : `${word}s`);
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
"type": "git",
"url": "git+https://github.com/kamronbatman/joi-password-complexity.git"
},
"peerDependencies": {
"@hapi/joi": "^16.0.0 || ^17.0.0 || ^17.1.0"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.8.2",
"jest": "^25.1.0"
"jest": "^25.1.0",
"@hapi/joi": "^17.1.1",
"joi": "^17.1.1"
},
"engines": {
"node": ">= 10.0.0"
Expand Down

0 comments on commit 7fa28dd

Please sign in to comment.