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]GSTIN Number Validation and PAN Validation (Multiple TIN functionality) and also refactored is taxID for options object #2153

Closed
wants to merge 11 commits into from

Conversation

Santhosh-Kumar-99
Copy link

@Santhosh-Kumar-99 Santhosh-Kumar-99 commented Jan 23, 2023

Added GSTIN Validation and PAN Validation for India TIN to isTaxID

GSTIN Format

  • 15 Digit Number
  • First two digit is State Code ( refer : State Code GSTIN]
  • Next 10 digit belongs to PAN Number Refer PAN Format
  • 13th digit is number of entity of business [1-9 A-Z]
  • 14th digit is Z by default
  • 15th digit is check digit which can be either number or alphabet [0-9 A-Z]

PAN Format Refer PAN Format

Added a new parameter locale option to the isTaxID function options object , so users could now specify the required localeOption to select the required validator, if the locale has multiple TIN.

Checklist

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

@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (3a04feb) compared to base (43803c0).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2153   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          106       106           
  Lines         2348      2362   +14     
  Branches       593       601    +8     
=========================================
+ Hits          2348      2362   +14     
Impacted Files Coverage Δ
src/lib/isTaxID.js 100.00% <100.00%> (ø)

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

rubiin
rubiin previously approved these changes Jan 23, 2023
README.md Outdated Show resolved Hide resolved
@Santhosh-Kumar-99 Santhosh-Kumar-99 requested review from WikiRik and removed request for pano9000 and WikiRik January 25, 2023 09:44
@rubiin rubiin requested review from rubiin and WikiRik and removed request for WikiRik January 25, 2023 14:47
@Santhosh-Kumar-99 Santhosh-Kumar-99 changed the title [feat]GSTIN Number Validation [feat]GSTIN Number Validation and PAN Validation Jan 26, 2023
@Santhosh-Kumar-99 Santhosh-Kumar-99 changed the title [feat]GSTIN Number Validation and PAN Validation [feat]GSTIN Number Validation and PAN Validation (Multiple TIN functionality) Jan 26, 2023
@Santhosh-Kumar-99
Copy link
Author

Hi @rubiin and @WikiRik

Added the functionality to validate locales with multiple Tax Identification Numbers, please review and provide your suggestions.

Thanks 🙂👍

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few remarks and suggestions. The added tests are nice, good work on those!

README.md Outdated Show resolved Hide resolved
src/lib/isTaxID.js Show resolved Hide resolved
src/lib/isTaxID.js Outdated Show resolved Hide resolved
src/lib/isTaxID.js Outdated Show resolved Hide resolved
src/lib/isTaxID.js Outdated Show resolved Hide resolved
src/lib/isTaxID.js Outdated Show resolved Hide resolved
src/lib/isTaxID.js Outdated Show resolved Hide resolved
@braaar
Copy link
Contributor

braaar commented Jan 26, 2023

Shouldn't we be considering transitioning to an options object here (as per #1874)? Ensuring compatibility from now on should be fairly trivial to implement and introducing more convoluted options will make backwards compatibility more difficult to implement in the future.

@Santhosh-Kumar-99
Copy link
Author

Yeah @braaar you are correct, I was not aware of #1874. Will make changes as required.
@WikiRik Can you add isTaxId to #1874 and add my name under claimed by.

Updated readme for isTaxId regarding new localeOption functionality and options object.
@Santhosh-Kumar-99 Santhosh-Kumar-99 marked this pull request as draft February 1, 2023 20:22
@Santhosh-Kumar-99 Santhosh-Kumar-99 requested review from rubiin and WikiRik and removed request for WikiRik and rubiin February 3, 2023 11:33
@Santhosh-Kumar-99 Santhosh-Kumar-99 changed the title [feat]GSTIN Number Validation and PAN Validation (Multiple TIN functionality) [feat]GSTIN Number Validation and PAN Validation (Multiple TIN functionality) and also refactored is taxID for options object Feb 3, 2023
@Santhosh-Kumar-99 Santhosh-Kumar-99 requested review from rubiin and removed request for WikiRik February 5, 2023 14:43
@Santhosh-Kumar-99 Santhosh-Kumar-99 requested review from WikiRik and removed request for rubiin February 13, 2023 07:39
Comment on lines 1230 to 1250
function validateArgs(str, locale, options) {
const localeOption = options?.localeOption;

try { assertString(str); } catch (err) { throw new Error(`${err.message} for str`); }
try { assertString(locale); } catch (err) { throw new Error(`${err.message} for locale`); }

for (const option in options) {
if (!(option in availableOptions)) throw new Error(`'${option}' is not available`);
}

if (!(locale in taxIdFormat)) throw new Error(`Invalid locale '${locale}'`);


if (locale in multipleTinLocale) {
try { assertString(localeOption); } catch (err) { throw new Error(`${err.message} for localeOption`); }
if (!(localeOption in multipleTinLocale[locale])) throw new Error(`Invalid localeOption '${localeOption}'`);
} else if (localeOption || localeOption === '') {
throw new Error(`Invalid localeOption for locale '${locale}'`);
}
}

Copy link
Contributor

@braaar braaar Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get inspiration for this from some other validator using an options object or did you come up with this yourself? To me this seems a bit heavy handed. Are we generally interested in throwing errors if the user doesn't provide valid options? I haven't seen this much argument validation in other validators. Does the multiple locale possibility in en-IN warrant this much code here?

#2086 is somewhat similar to this PR in that it uses a local option in the options object. Maybe cut things down a bit, taking inspiration from there?

Copy link
Author

@Santhosh-Kumar-99 Santhosh-Kumar-99 Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @braaar thanks for your feedback,
I came up with this approach of validating args, but took inspiration of options object from #2157 and #2075.
The current function also validates args and throws error if user specifies a wrong locale or str, so I thought it might be useful if we throw error for wrong options too. And yeah since localeOption is dependent on locale it seems a bit heavy handed, even I had the same thought too. But it is just checking if the options provided are correct, if the locale has multiple TIN and also their types.
Wouldn't it be misleading if the validation returns false when incorrect options are passed ?

Yeah #2086 is a bit similar but according to #1874 but locale will not be a part of options object as it is mandatory. #1874 (comment).

For now, en-IN is the only locale which has multiple TIN, but when I researched through the internet there are several other countries who have multiple TIN, may be this approach would help us to include other countries soon.

Example : US TIN
US has 5 different Identification numbers.

Copy link
Contributor

@braaar braaar Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This complexity is starting to make me feel like maintaining a validator for multiple tax ids for multiple countries is an enourmous undertaking. I suppose it's the only natural way forward, unless we decide to scrap the validator altogether, of course.

How many app developers are making international systems that care about tax ids and are using open source validation code? In my eyes the use case for such an all-encompassing validator is quite rare. When I work with things like social security numbers and business IDs I use a country-specific package that contains what I need and is much easier to maintain on its own, should I spot an error or want something added.

What are your thoughts on this, @WikiRik? I suppose this enters into a territory where the maintainers should chime in. They are in control of the main direction of the project and also feel the burden of maintaining code the most.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, input from the maintainers is indeed something we'll need. But the fact is that we already have isTaxID with multiple countries so this is a logical addition in my view.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa can you please help us here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I should open a separate issue about scrapping this validator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah and can we just add PAN regex alone for en-IN locale ,for now ?

src/lib/isTaxID.js Outdated Show resolved Hide resolved
Changed variable name to multipleTaxIdLocale

Co-authored-by: Brage Sekse Aarset <[email protected]>
@Santhosh-Kumar-99 Santhosh-Kumar-99 requested review from braaar and removed request for WikiRik February 15, 2023 03:07
@Santhosh-Kumar-99 Santhosh-Kumar-99 closed this by deleting the head repository Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants