npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@designbycode/luhn-algorithm

v1.0.1

Published

The Luhn Algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, and others. This documentation provides an overview of the Luhn Algorithm implementation in PHP, including exa

Downloads

14

Readme

Luhn Algorithm Plugin

npm version npm NPM npm bundle size ts GitHub stars HitCount

NPM

The Luhn Algorithm plugin is a JavaScript library that provides a set of functions to validate and generate numbers using the Luhn algorithm, also known as the Modulus 10 or Mod 10 algorithm. This algorithm is widely used to validate various identification numbers, such as credit card numbers, IMEI numbers, and others.

Installation

To use this plugin, you need to install it via pnpm, npm or yarn.

Using pnpm

pnpm add  @designbycode/luhn-algorithm

Using npm

npm install @designbycode/luhn-algorithm

Using yarn

yarn add @designbycode/luhn-algorithm

Usage

To use the Luhn Algorithm plugin, simply import the LuhnAlgorithm class and call the desired function.

import LuhnAlgorithm from '@designbycode/luhn-algorithm';

const number = "4532015112830366";
const isValid = LuhnAlgorithm.isValid(number);
console.log(isValid); // true

Functions

isValid

isValid(number: string): boolean

The isValid function takes a string number as input and returns a boolean indicating whether the number is valid according to the Luhn algorithm.

const number = "4532015112830366";
const isValid = LuhnAlgorithm.isValid(number);
console.log(isValid); // true

generate

generate(number: string): string

The generate function takes a string number as input and returns a new string with a check digit appended to the end. The check digit is calculated using the Luhn algorithm.

const number = "45320151128303";
const generatedNumber = LuhnAlgorithm.generate(number);
console.log(generatedNumber); // "4532015112830366"

getDigit

getDigit(number: string): string The getDigit function takes a string number as input and returns a string representing the check digit calculated using the Luhn algorithm.

const number = "45320151128303";
const checkDigit = LuhnAlgorithm.getDigit(number);
console.log(checkDigit); // "6"

withoutDigit

withoutDigit(number: string): string The withoutDigit function takes a string number as input and returns a new string with the last digit removed.

const number = "4532015112830366";
const withoutDigit = LuhnAlgorithm.withoutDigit(number);
console.log(withoutDigit); // "45320151128303"

validateAndSuggest

validateAndSuggest(number: string): { isValid: boolean; suggestedDigit: string } The validateAndSuggest function takes a string number as input and returns an object with two properties: isValid and suggestedDigit. The isValid property indicates whether the number is valid, according to the Luhn algorithm, and the suggestedDigit property provides a suggested check digit if the number is invalid.

const number = "45320151128303";
const result = LuhnAlgorithm.validateAndSuggest(number);
console.log(result); // { isValid: false, suggestedDigit: "6" }

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions to this plugin are welcome! If you encounter any issues, have feature requests, or want to improve the plugin, feel free to create a pull request or submit an issue in the GitHub repository.

Acknowledgments

The Luhn Algorithm plugin is inspired by the work of Hans Peter Luhn, who developed the Luhn algorithm in the 1950s.