-
Notifications
You must be signed in to change notification settings - Fork 13
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] Detect zero padded numbers as string #36
base: master
Are you sure you want to change the base?
Conversation
heshan0131
commented
May 23, 2023
- Zero padded numbers as string
- Zero itself is an integar
Signed-off-by: Shan He <[email protected]>
@@ -26,11 +26,15 @@ var RegexList = { | |||
isNumber: /^(\+|\-)?\$?[\d,]*\.?\d+((e|E)(\+|\-)\d+)?%?$/, | |||
|
|||
// accepts: 12, +123, -12,234 | |||
isInt: /^(\+|\-)?[\d,]+$/, | |||
// no accept: 01, 001 | |||
isInt: /^(?!0)(\+|\-)?[\d,]+$/, |
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.
the only senario this doesn't handle is the actual 0
@@ -60,7 +60,7 @@ VALIDATOR_MAP[DATA_TYPES.TIME] = Utils.buildRegexCheck('isTime'); | |||
// 1, 2, 3, +40, 15,121 | |||
const intRegexCheck = Utils.buildRegexCheck('isInt'); | |||
function isInt(value) { | |||
if (intRegexCheck(value)) { | |||
if (intRegexCheck(value) || value == '0') { |
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.
if (intRegexCheck(value) || value == '0') { | |
if (intRegexCheck(value) || value === '0') { |
Do we know that value
is a string? If not, should we also check for value === 0
?
@@ -77,8 +77,12 @@ function isFloat(value) { | |||
VALIDATOR_MAP[DATA_TYPES.FLOAT] = isFloat; | |||
|
|||
// 1, 2.2, 3.456789e+0 | |||
const zeroPaddedNumCheck = Utils.buildRegexCheck('isZeroPaddedNumber'); |
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.
Nit: Comment above should now move down?
Nit 2: It looks like this just avoid number parsing - should we explicitly output string in this case, rather than having it fall through the number check?
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.
yea, but that's not how computeColMeta
currently designed. with the current implementation
type = allValidators.find(buildValidatorFinder(data, columnName));
The only way to have it return string
is to return falsy on the number check, because string is at the bottom of the validator queue