-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Added isFreightContainerID validator #2144
Conversation
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #2144 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 105 106 +1
Lines 2324 2348 +24
Branches 586 593 +7
=========================================
+ Hits 2324 2348 +24
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
src/lib/isContainerID.js
Outdated
|
||
// https://en.wikipedia.org/wiki/ISO_6346 | ||
const isContainerIdReg = new RegExp('^[A-Z]{3}U[0-9]{7}$'); | ||
const isDigit = new RegExp('^[0-9]{1}'); |
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.
I feel like this could be rewritten to ^[0-9]$
, since you are checking against each string character using its index, and that will always be just one character
Also maybe just a matter of taste in general, but this project seems to be generally prefering the use of regular expression literals. as opposed to a constructor function, like you used here.
So for the sake of style consistency, I would probably also suggest the following change:
new RegExp('^[0-9]{1}')
-> const isDigit = /^[0-9]$/
(same applies to the isContainerIdReg regexp in line 4)
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.
Hi Panagiotis,
Thank you very much for pointing it out! I have updated the corresponding lines.
src/lib/isContainerID.js
Outdated
|
||
export default function isContainerID(str) { | ||
assertString(str); | ||
str = str.trim(); |
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.
I have the same concerns about this, as I have mentioned in your other PR:
#2143
what do you think?
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.
README.md
Outdated
@@ -102,6 +102,7 @@ Validator | Description | |||
**isBoolean(str [, options])** | check if a string is a boolean.<br/>`options` is an object which defaults to `{ loose: false }`. If loose is is set to false, the validator will strictly match ['true', 'false', '0', '1']. If loose is set to true, the validator will also match 'yes', 'no', and will match a valid boolean string of any case. (eg: ['true', 'True', 'TRUE']). | |||
**isBtcAddress(str)** | check if the string is a valid BTC address. | |||
**isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`. | |||
**isContainerID(str)** | check if the string is an ISO6346 shipping container identification. |
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.
I think the name might be a bit too unspecific, as "container ID" feels a bit too generic, e.g. just google it, brought up several hits, like e.g. "docker container ID", "Windows Drivers Container ID", etc.
So I would probably say it makes sense to rename this?
Options could be maybe:
- isShippingContainerID
- isISO6346ContainerID (that one does look ugly to be honest :-D)
- ?
What do you think?
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.
We already have some ISO standards so a simple isISO6346
could also suffice
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.
I have changed it to isISO6346
, for consistency with other validators.
thank you for the PR :-) |
Haha thank you Panagiotis for reviewing my PR once again. |
This was also interesting to me, learned something new! Thanks for the PR! |
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.
LGTM, thanks! 🎉
QQ, do you want to add |
Hi Nandaa, Do you mean adding a new file with the name of |
hi guys, one tiny thing I'd like to still see adressed is my comment above regarding the use of |
@songyuew -- not really a new file, just within the same file, exporting the |
@profnandaa @pano9000 Alias added and sanitization removed, plz kindly review, thanks! |
My bad, I don't know how we missed this one, should have gone into the previous release. I'll queue it up for the next one. |
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.
LGTM. If you can fix the m/c, I'll merge it straight away.
Added isContainerID validator
Check whether a string is an ISO6346 shipping container identification.
https://en.wikipedia.org/wiki/ISO_6346
Please review my PR, thanks!
Checklist