Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support sideway joi #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
AbdelrahmanHafez marked this conversation as resolved.
Show resolved Hide resolved
"joi": "^17.1.1"
},
"engines": {
"node": ">= 10.0.0"
Expand Down