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

serial-pin-generator

v3.1.2

Published

A package library that anables developers to generate pin digits and the corresponding serial numbers for their application

Downloads

19

Readme

serial-pin-generator

A simple JavaScript script that enable developers to generate pin digits and corresponding serial numbers in application that require something like scratch card or recharge card services. it is a promise base script. Although pin and serial numbers are not each expected to be more than 25 characters long, but this script can generate up to 64 character long for each (pin or serial number).

Installation

npm install serial-pin-generator

Usage

install via npm

npm i serial-pin-generator

or via yarn

yarn add serial-pin-generator

require it in your file

const pinGen = require('serial-pin-generator');

Calling the pinGen function will return a promise which will resove with an array of objects.

pinGen()
.then(values => console.log(values))
.catch(err => console.log(err));

Syntax

pinGen([options])

The function accept object as argument. The argument is optional. it is provided to configure the output of the pin digits and the serial numbers that will be generated.

Setting the optional option argument

pinGen({
    pinLength: 5,
    serialNumLength: 15,
    prefixCharacters: 'sdp',
    numberRequired: 7,
    numberRequired: 5
}).then(values =>console.log(values))
  .catch(err => console.log(err));

is equivalent to this

pinGen({
    serialNumLength : {
        length: 15,
        includePrefixLength: true
    },
    prefixCharacters: 'sdp',
    numberRequired: 7,
    pinLength: 8
})
.then(values => console.log(values))
.catch(err => console.log(err.message));

Which generates

[
  { pin: 62511243, serial_num: 'SDP9988375879270' },
  { pin: 22128956, serial_num: 'SDP9988375879271' },
  { pin: 36864087, serial_num: 'SDP9988375879272' },
  { pin: 49280942, serial_num: 'SDP9988375879273' },
  { pin: 47421936, serial_num: 'SDP9988375879274' },
  { pin: 34639053, serial_num: 'SDP9988375879275' },
  { pin: 52842289, serial_num: 'SDP9988375879276' }
]

If serialNumLength.includePrefixLength === false,

it will add prefixCharacter length to the serialNumLength.length

Example

pinGen({
    serialNumLength : {
        length: 15,
        includePrefixLength: false
    },
    prefixCharacters: 'sdp',
    numberRequired: 7,
    pinLength: 8
})
.then(values => console.log(values))
.catch(err => console.log(err.message));

Which generates

[
  { pin: 62131779, serial_num: 'SDP5434814428618890' },
  { pin: 86781427, serial_num: 'SDP5434814428618891' },
  { pin: 57071838, serial_num: 'SDP5434814428618892' },
  { pin: 42043437, serial_num: 'SDP5434814428618893' },
  { pin: 82469489, serial_num: 'SDP5434814428618894' },
  { pin: 38335381, serial_num: 'SDP5434814428618895' },
  { pin: 97639287, serial_num: 'SDP5434814428618896' }
]

Using async await

(async () => {
    try {
        const values = await pinGen({
            pinLength: 12,
            prefixCharacters: 'sdp',
            serialNumLength: 8,
            numberRequired: 3
        })
        console.log(values);
    } catch (error) {
        console.log(error);
    }
})()

Which generates

[
  { pin: 203420843675, serial_num: 'SDP40700' },
  { pin: 603474470957, serial_num: 'SDP40701' },
  { pin: 725294039567, serial_num: 'SDP40702' }
]

Configuration Options

| options keys | datatype | description | ------ | -------- | ----------- | options.pinLength | number | The number of digits the pin should have. | | options.serialNumLength | object|number | options.serialNumLength.length type number The number of characters (string length) of the serial number. options.serialNumLength.includePrefixLength type boolean if true, the serial number prefix character length will be included in the serial number total length. Otherwise the serial number total length will options.prefixCharacters length + **options.serialNumLength.length. If **options.serialNumLength is a number it will be use for **options.serialNumLength.length. | | options.prefixCharacters | string | The prefix characters of the serial number. This should be alphanumeric characters. If you did not provide this option, the serial numbers will be string of numbers only. The options.serialNumLength should be at least four characters longer than the length of the options.prefixCharacters. string | | options.numberRequired. | number | The total number of pins and corresponding serial numbers required to be generated. |

NOTE:

The options.serialNumLength should be at least four characters longer than the length of the options.prefixCharacters.

The default configuration is the equivalent of:

{
    pinLength: 12, 
    serialNumLength: {
        length: 15,
        includePrefixLength: false,
    }, 
    prefixCharacters: '', 
    numberRequired: 20
}

License

License under the ISC