-
-
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
isAlpha enhancement #1286
isAlpha enhancement #1286
Conversation
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 so far looks good to me, thanks for getting this quick.
Just one thing you forgot, could you update the README too.
@profnandaa thanks for the review, but I see one problem with the above implementation. since we are allowing the user to pass strings, there are chances that the user might pass some invalid regex characters and the code might break. we may also experience regex weird behavior, one of the examples is try adding so my proposal for strings is to go with the below code
with little tweaks, this code should work but at least it's safe and I hope it gives you the rough idea on what it's doing validator.js/es/lib/isAlpha.js Lines 12 to 13 in 5ff4998
|
ping @profnandaa |
@mum-never-proud -- I see, nice catch. What if we limited the |
@profnandaa but again we are narrowing down the use cases, some may raise an issue saying he needs to ignore a back tick or @ it's better to support all the characters in order to avoid reworking for additions your thoughts? |
pong @profnandaa |
@mum-never-proud - makes sense. How about if just support a string with a list of characters to ignore; but not regex for now? |
@profnandaa but anyhow we will be using regex to check right? |
pong @profnandaa |
@mum-never-proud -- sure, still use regex to check, but don't take regex option from users. |
@profnandaa i think we can allow both string and regex, i guess the key solution here will be to escape the regex for string which seemed to work let me know your thoughts ps: let me know if you are fin with the approach, so that i can do one final optimization of not modifying the params directly, a bad practice |
@mum-never-proud -- I'm okay with this, thanks. |
@profnandaa done, |
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 You can update the README too?
cool, thanks! mind providing text? kinda stuck here options is optional, valid option is anything better than this? |
I could re-jig it to be similar to the rest, something like:
|
@profnandaa done! |
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.
Thanks! LGTM 🎉
ping @tux-tn -- can review please before @mum-never-proud fixes the merge conflicts... |
assertString(_str); | ||
|
||
let str = _str; | ||
const { ignore } = options; |
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 am with the opinion that ignore
characters should be optional.
This actually fails if a user does not pass ignore values (It is not guaranteed that a user needs to have some values ignored).
Also, if I pass options as args: [{ ignore: /[\s/-]/g }]
, it will fail or I do pass an args: ['en-US', { }]
it also fails.
I am open to discussion on way forward.
Cc. @profnandaa
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.
hmm technically i don't see a possibility of failing for any of the above args, may be i can add those
validator.js/src/lib/isAlpha.js
Lines 8 to 10 in a919d99
const { ignore } = options; | |
if (ignore) { |
the above line says that ignore is optional which means, args: ['en-US', { }]
should pass
as far as about this [{ ignore: /[\s/-]/g }]
we are already asserting first argument to be string
let me know if it makes sense @profnandaa @ezkemboi
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, just check my comment @mum-never-proud and resolve conflicts.
@@ -1,8 +1,22 @@ | |||
import assertString from './util/assertString'; | |||
import { alpha } from './alpha'; | |||
|
|||
export default function isAlpha(str, locale = 'en-US') { | |||
assertString(str); | |||
export default function isAlpha(_str, locale = 'en-US', options = {}) { |
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 am just curious why change str
to _str
and later do
let str = _str
I thought we could pass str
as before and do:
assertString(str);
But, all in all, it looks good to me.
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.
@ezkemboi ah it's not good practice to directly change the arguments, just following best practices, will resolve the conflict in sometime
@mum-never-proud -- good to see you back, been a minute :) Ping me once you've resolved the conflicts. |
heyy, man I totally forgot about this yes I will do today buddy |
@mum-never-proud, still waiting for you to resolve conflicts to get this one landing!!! |
Hey just a give me a couple of days as my Mac is corrupted I hope to get it resolved by today or worst by tmr and resolve the conflict thanks
Get Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: Ezrqn Kemboi <[email protected]>
Sent: Thursday, November 5, 2020 7:53:45 AM
To: validatorjs/validator.js <[email protected]>
Cc: mum-never-proud <[email protected]>; Mention <[email protected]>
Subject: Re: [validatorjs/validator.js] isAlpha enhancement (#1286)
@mum-never-proud<https://github.com/mum-never-proud>, still waiting for you to resolve conflicts to get this one landing!!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1286 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AN47NHLW46BTI22575UDP6TSOIEDDANCNFSM4MOX7OSA>.
|
folks finally laptop is back today i will merge it @profnandaa @ezkemboi |
I think we can release a new version after the pr @profnandaa |
Codecov Report
@@ Coverage Diff @@
## master #1286 +/- ##
=======================================
Coverage 99.92% 99.92%
=======================================
Files 96 96
Lines 1277 1285 +8
=======================================
+ Hits 1276 1284 +8
Misses 1 1
Continue to review full report at Codecov.
|
i guess a lot has changed since I created this PR, let me know if there is something I am missing? @profnandaa @ezkemboi |
I reviewed and the pr looks okay from my side |
@profnandaa this is good to land. |
Hey, I'm getting an error in typescript (but it is working and validates)
A
Am I missing something? |
Yes, ignore is not an [array], should be a "string" or /regex/
Are the docs saying otherwise?
./na
On Sun, Dec 13, 2020 at 10:58 PM Patrik Gerdin ***@***.***> wrote:
Hey, I'm getting an error in typescript (but it is working and validates)
body('field').isAlpha('en-US', {ignore: ' '})
(property) IsAlphaOptions.ignore?: string[] | undefined
Type 'string' is not assignable to type 'string[] | undefined'.ts(2322)
A string[] does not work
body('field').isAlpha('en-US', {ignore: [' ']})
Error: ignore should be instance of a String or RegExp
Am I missing something?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1286 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB7ZELH6AVKVHMH33M56EDSUUMHZANCNFSM4MOX7OSA>
.
--
Sent from a tiny device while on the move.
|
Was looking at the docs here https://github.com/validatorjs/validator.js#validators, hard to see what is the key(s) there. In options.d.ts
Should be just a Nice that it works now otherwise. |
resolve #1282