-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add isUPC for Universal Product Codes (UPC-A) #2626
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2626 +/- ##
===========================================
- Coverage 100.00% 99.96% -0.04%
===========================================
Files 114 115 +1
Lines 2566 2587 +21
Branches 651 654 +3
===========================================
+ Hits 2566 2586 +20
- Partials 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Personally I think my remark in #2290 is still valid, but I can see you're going to add it to |
|
My feeling is it's sufficiently simple that we don't gain much by combining it with the EAN logic. I aimed to keep this small and self-contained. |
WikiRik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few remarks, but looks good apart from that
| **isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.<br/><br/>`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`.<br/><br/>`locale` determines the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.<br/>**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'. | ||
| **isDivisibleBy(str, number)** | check if the string is a number that is divisible by another. | ||
| **isEAN(str)** | check if the string is an [EAN (European Article Number)][European Article Number]. | ||
| **isUPC(str)** | check if the string is a [UPC-A][UPC-A] code with a valid checksum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this in the correct alphabetical order
| [Base64 URL Safe]: https://base64.guru/standards/base64url | ||
| [Data URI Format]: https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs | ||
| [European Article Number]: https://en.wikipedia.org/wiki/International_Article_Number | ||
| [UPC-A]: https://en.wikipedia.org/wiki/Universal_Product_Code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the README comments; no need to change this, as we don't have a consistent order in this file
| const total = (sumOddPositions * 3) + sumEvenPositions; | ||
| const remainder = total % 10; | ||
|
|
||
| return remainder === 0 ? 0 : 10 - remainder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is partially covered. We expect 100% code coverage. Can you check this out?
Add support for UPC-A codes
https://en.wikipedia.org/wiki/Universal_Product_Code
This is similar to isEAN, but for 12 digit UPC codes.
Checklist