Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

More accurate package.json name regex #1232

@shravan2x

Description

@shravan2x

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.

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions