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

feat(isUPC): add validation for UPC code which is Universal Product Code widely used worldwide for … #2290

Closed
wants to merge 7 commits into from

Conversation

rahulnikam2002
Copy link

@rahulnikam2002 rahulnikam2002 commented Sep 26, 2023

What i have done?

  • Added a validation for UPC code.
  • Tested on with valid and invalid inputs

Why i have done?

  • UPC codes are essential for modern retail operations and are used in inventory control and price comparison.
  • helps to maintain accurate pricing information and streamline inventory management.

References

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@WikiRik
Copy link
Member

WikiRik commented Sep 26, 2023

I'm not so sure if this is an useful addition to the project. The check is simple, just if its 12 digits. I also did not see any other requests for this to be added. But I'm open to hear what others/maintainers think

@rahulnikam2002
Copy link
Author

rahulnikam2002 commented Sep 27, 2023

okay @WikiRik, will try to add more useful features!

I'm not so sure if this is an useful addition to the project. The check is simple, just if its 12 digits. I also did not see any other requests for this to be added. But I'm open to hear what others/maintainers think

@laserguru
Copy link

laserguru commented Jun 19, 2024

@rahulnikam2002 @WikiRik
Bumping this because I need this feature and the feature pretty much was already there

Turns out two things happen:

EAN codes are a superset of UPC. But a 12 digit UPC, by itself, is not a valid EAN-13.
But add a zero in front, and it is! (And that's the specification, not a hack)
UPCs as such are only assigned in the USA and Canada, and EANs elsewhere.
At the moment, I simply changed my code to prepend the zero if the code is 12 digits long:
isEAN(code.length === 12 ? "0" + code : code)
Checked with a bunch of items with UPCs and it validates correctly.

Will follow up with a pull request once I make the changes to the validator.js source. Now, should this be part of isEAN or a separate isUPC?

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.

3 participants