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(isLuhnValid): Expose isLuhnValid independently from isCreditCard #1974

Merged
merged 2 commits into from
Jul 17, 2022
Merged

feat(isLuhnValid): Expose isLuhnValid independently from isCreditCard #1974

merged 2 commits into from
Jul 17, 2022

Conversation

ST-DDT
Copy link
Contributor

@ST-DDT ST-DDT commented May 22, 2022

Currently the luhn checking algorithm is only used inside isCreditCard, but the luhn algorithm is also used in/for other "numbers", so it would be nice if the isLuhnValid could be exposed independently.

is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israeli ID Numbers, South African ID Numbers, Swedish National identification numbers, Swedish Corporate Identity Numbers (OrgNr), Greek Social Security Numbers (ΑΜΚΑ), SIM card numbers and survey codes appearing on McDonald's, Taco Bell, and Tractor Supply Co. receipts.

Source: https://en.wikipedia.org/wiki/Luhn_algorithm

The code is copied from the existing isCreditCard check.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable) - Tests from isCreditCard apply, if any exist.

@codecov
Copy link

codecov bot commented May 22, 2022

Codecov Report

Merging #1974 (4098467) into master (cfcf911) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #1974   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          103       104    +1     
  Lines         2097      2104    +7     
  Branches       473       473           
=========================================
+ Hits          2097      2104    +7     
Impacted Files Coverage Δ
src/index.js 100.00% <100.00%> (ø)
src/lib/isCreditCard.js 100.00% <100.00%> (ø)
src/lib/isLuhnValid.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cfcf911...4098467. Read the comment docs.

@WikiRik
Copy link
Member

WikiRik commented May 22, 2022

isCreditCard is testing different aspects as well. Can you add special tests for isLuhnValid?

@ST-DDT
Copy link
Contributor Author

ST-DDT commented May 23, 2022

isCreditCard is testing different aspects as well. Can you add special tests for isLuhnValid?

Done

@rubiin rubiin merged commit c57ff39 into validatorjs:master Jul 17, 2022
@ST-DDT ST-DDT deleted the expose/luhnCheck branch July 18, 2022 02:25
@profnandaa
Copy link
Member

Suggesting a rename to isLuhnNumber instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants