isbn3 icon indicating copy to clipboard operation
isbn3 copied to clipboard

Return error message if isbn validation failed

Open dwightkelly opened this issue 3 years ago • 3 comments

It would be useful to return an error message with details of why isbn validation failed.

dwightkelly avatar Apr 01 '22 21:04 dwightkelly

That could be nice, but would definitely be a breaking change, unless that behavior is activated by a flag.

maxlath avatar Jun 01 '22 10:06 maxlath

This could be an interesting feature. Would u consider a PR with the following logic?

  1. IF input length = 10 AND it != starts with 978|979 AND parse = null >> ERROR
  2. ELSE IF input length = 13 AND it starts with 978|979 and parse = null >> ERROR
  3. ELSE IF input length > 13 >> ERROR
  4. ELSE >> null

so error is thrown only when there is formally ISBN-like input but after the parsing there is a null 883951856 (9 digits) >> null 97888 >> null 978883951856 >> null 9788839518569 >> valid 9788839518568 >> error

Roman991 avatar Jan 12 '23 12:01 Roman991

Maybe such a feature could be a new function, such as parseStrict, or behind a flag: parse(isbn, { strict: true }). In both case, that would remove the problem of the breaking change.

Another idea: it could also (optionally?) enrich the error with the info gathered by the audit function

maxlath avatar Sep 11 '23 16:09 maxlath