Skip to content

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