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

luhn-string

v1.2.3

Published

A library to generate strings that end with a checksum 'digit'. Digits in the string are in the range 0-9B-DF-HJ-NP-TV-XZ. All uppercase.

Downloads

1,423

Readme

LUHN-STRING

A library to generate alphanumeric strings that end with a checksum "digit". Digits in the string are in the range 0-9B-DF-HJ-NP-TV-XZ. All uppercase.

Changed in v1.2.0 > provide your own character sequence using var cardLuhn = require('luhn-string')('0123456789'); where '0123456789' is the valid character sequence for the strings you want to generate. Call on the generated object as always.

Change log

1.2.0. Rather than having to send the valid caharacters sequence for every call, the main Luhn Object has been upgraded to be a factory for LuhnObjects. Check sample.js for updated samples

1.1.0. All functions allow you specify a string of valid characters in case you do not want the default of 0-9A-Z excluding vowels and Y. Callbacks can still be sent. All results are still Uppercase. Note that the characters must be in same order when you are validating. A random string generated with sequence '0123456789' will not validate correctly against sequence '9876543210'.

Advantages

  1. Strings have a checksum character at the end.
  2. Avoid Bad words in generated string by removing A,E,I,O,U,Y
  3. Random strings are cryptographically generated (dependent on node's crypto library)
  4. Provide your own character sequence

Installation

npm install luhn-string -save

Usage

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

// to generate a 16-digit checksummed string
var str = Luhn.random(16);
console.log(str);

// to generate a 16-digit checksummed string with 0123456789 as sequence
// Method 1
var res = Luhn.random(16, '0123456789');
console.log(res);
console.log(Luhn.check(res, '0123456789'));

// Method 2
var creator = new Luhn('0123456789');
res = creator.random(16);
console.log(res);
console.log(creator.check(res));


// to test a string for checksum validity
var chk = Luhn.check('30MFLRQDVCFQ9SK1');
var valid = chk.result;
var validityerror = chk.error;

// Use callbacks
Luhn.random(16, function(error, result){
  if(error){
    // do something with error...
    return;
  }
  console.log(result);
});

Luhn.check('LH989002BW3P', function(error, result){
  if(error){
    // do something with error...
    return;
  }
  console.log(result); // true or false
});

Extras

The library uses a crypto function to generate random strings. This is Exposed for your use in 2 forms:

1. cryptoRandomAsciiString(length)

returns a truly random ascii string of length length

2 cryptoRandomString(length, chars)

returns a truly random ascii string of length length, picking characters in string chars

3 addChecksum(str, callback)

checks that str contains valid characters and appends a checksum character at its end. Should be used in callback fashion. Returns null if there is an error otherwise.