GithubHelp home page GithubHelp logo

socheatsok78 / luhn-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edumdum/luhn

0.0 2.0 0.0 144 KB

Validation and control key generation against Luhn formula in javascript.

License: MIT License

JavaScript 100.00%

luhn-js's Introduction

npm version Build Status GitHub license

luhn

Validation and control key generation for credit cards (and more) using Luhn algorithm.

Usage

In node.js

var Luhn = require('luhn-js');

Luhn.isValid('44542738505150162'); // false
Luhn.isValid('44540661970241257'); // true

Luhn.generate('4454066197024125'); // 44540661970241257

Luhn.getRemainder('44543353847144279'); // 8

API

isValid(value) -> Boolean

Check requirements.
Returns if the Luhn check digit is valid.

Required

  • Value must be not Null
  • Value must be of type String
  • Value must respect format ^[0-9]{2,}$

generate(value) -> String

Check requirements.
Returns the Luhn check digit appended to the value.

Required

  • Value must be not Null
  • Value must be of type String
  • Value must respect format ^[0-9]{1,}$

getRemainder(value) -> Number

Does NOT check requirements.
Returns the Luhn remainder.

Note: getRemainder(value) === 0 is equivalent to isValid(value). You may want to use this method instead of isValid if you ensure argument requirements on your side.

Required

  • Value must be not Null
  • Value must be of type String

luhn-js's People

Contributors

edumdum avatar

Watchers

 avatar  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.