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

Add options object to allow finer-grained validation #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richdouglasevans
Copy link
Owner

Closes #47

// valid; hyphen is optional by default
issn("03554325")
// invalid; hyphen is mandatory when strict is enabled
issn("03554325", { strict: true });

Comment on lines +8 to +16
function validate(issn, options) {
var opts = options ? options : { strict: false };

var issnPattern = opts.strict === true
? '^(\\d{4})-(\\d{3})([\\dX])$' // hyphen is required
: '^(\\d{4})-?(\\d{3})([\\dX])$'; // hyphen is optional
var isIssn = new RegExp(issnPattern);

var matches = text(issn).match(isIssn);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the validation logic to support stricter validation.

"jasmine-node": "3.0.0",
"lodash": "^4.17.21"
},
"dependencies": {
"get-stdin": "7.0.0",
"minimist": "^1.2.6"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped from minimist to yargs only 'cos there was a bug in testing the CLI with the new stricter validation option.

@@ -1,6 +1,6 @@
{
"name": "issn",
"version": "1.0.6",
"version": "2.0.0",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version bump because the function signature is changing: the options argument is optional but it's still a change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Flag for rejecting values without dash
1 participant