Giter Club home page Giter Club logo

luhn-generator's Introduction

Luhn Generator

A generator of numbers that passes the validation of Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm

npm install luhn-generator --save

Usage

  • ECMAScript Harmony
    import luhn from '../dist/luhn';
    luhn.generate(1, { pad: 12 }); // 000000000018
  • CommonJS
    $ node
    > const luhn = require('../dist/luhn');
    > luhn.generate(1, { pad: 12 }); // 000000000018
  • AMD
    <!-- amd.html -->
    <html>
      <body>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
        <script>
          window.requirejs(['dist/luhn.min'], function(luhn) {
            console.log(luhn.generate(1, { pad: 12 })); // 000000000018
          });
        </script>
      </body>
    </html>
  • Script Tag
    <!-- script-tag.html -->
    <html>
      <body>
        <script src="./dist/luhn.min.js"></script>
        <script>
          console.log(luhn.generate(1, { pad: 12 })); // 000000000018
        </script>
      </body>
    </html>

Generate Luhn "check digit" for number 1:

luhn.checksum(1); // 8
luhn.checksum(12); // 5

Generate number that will pass Luhn algorithm validation:

luhn.generate(1); // 18
luhn.generate(12); // 125
luhn.generate(1, { pad: 5 }); // 00018

Generate random number that will pass Luhn algorithm validation:

luhn.random(12); // 6436204626980
luhn.random(50); // 54833184596638864915195736286128781213916608803535
luhn.random(12, { pad: 50 }); // 00000000000000000000000000000000000004591785326079

Validate number with Luhn algorithm:

luhn.validate(1); // false
luhn.validate(18); // true
luhn.validate(125); // true

To Do

  • Add page with examples
  • Add card number generation

luhn-generator's People

Contributors

dependabot[bot] avatar harunorimurata avatar rromanovsky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.