More accurate package.json name regex #1232
Description
As of VS2017, the package.json name
field is required to match the regex ^[^A-Z]+$
and have a length not more than 214 characters.
I was unable to find the regex in this repo, so please redirect me if such an issue should be posted elsewhere.
I propose that this regex be changed to
^(?=.{1,214}$)(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$
This regex follows the guidelines at https://docs.npmjs.com/files/package.json better. I have added some simple unit tests for it over at https://regex101.com/r/QgADad/3/tests.
Please let me know if you would like me to clarify the regex in any way. It is much more complex than the existing one, but also more accurate.
Ref:
https://stackoverflow.com/questions/695438/safe-characters-for-friendly-url
https://stackoverflow.com/questions/11197549/regular-expression-limit-string-size
EDIT 1: Improved regex
EDIT 2: Added more tests