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

@neblartechnologies/descardid

v1.0.0

Published

DesCardId (of Card Identification) is a php library used for identifying credit card numbers in text.

Downloads

18

Readme

DesCardId_JS

DesCardId (of Card Identification) is an open source library written in JavaScript and PHP that can be used to identify credit card numbers in any given text with certain degree of probability.

How it works

The library follows the following process to identify credit card numbers in a given text:

  1. Identify fragments of text which have numbers in them. These are fragments without alphabets but may contain other characters for example spaces, dashes etc. The idea here is that if people write down a credit card number they would generally not include alphabets in between the number unless they are deliberately trying to bypass checks. For example, "Lorem ipsum 123 456 foo bar", would result in extraction of the fragment " 123 456 ", while "Lorem 123 ipsum 456 foo 789 bar" would result in extraction of " 123 ", " 456 ", " 789 " as separate fragments.
  2. These fragments are then stripped of all special characters, leaving behind only the number that they contain. For example, a fragment like "1234 - - 567 .. 89" would then be converted into "123456789".
  3. This number is then tested to check if it could be a credit card or not, this follows a separate sub process outlined here:
    1. Check if the number can possibly be a credit card number. This check is used to weed out numbers that are too short or too long to be credit card numbers, and check for any other basic characteristics which a credit card number must absolutely have.
    2. Calculate the probability of the number actually being a credit card number. This involves performing a check sum aka LUHN check, a validation based on length to match with popular card lengths, trying to match the number with a popular card provider and matching the number to known set of test numbers.
    3. The total probability assigned to a number is then compared with a threshold, if the probability is over the threshold then we are sure that it is a credit card number otherwise we are not.

Examples

Upon use of the main class's (CardIdentifier) inspectText function we get the following results:

Provided text foo 5555555555554444 bla bla

Resulting text foo {{5555555555554444}[ALERT]} bla bla

Interactive example

How to Use

  1. Include the production build version of the script from /build/production/DesCardId.js.

  2. Initialize an object of the CardIdentifier class as

       let identifier = new CardIdentifier();
  3. Pass the text you want to inspect to function inspectText of this object as

       let inspectedText = identifier.inspectText("foo bar");

Customization

The library has room for customization at different stages. Here are some of the common customizations that you can perform:

Changing the markers for Alert and Notice

You can change the marker that is used to identify the numbers by passing the desired text to the constructor of CardIdentifier by

    let identifier = new CardIdentifier(null, null, null, "ALERT TEXT", "NOTICE TEXT");

Changing the thresholds

You can change the threshold for setting Alerts and Notices as follows

    const thresholdAlert = 80;
    const thresholdNotice = 20;
    let identifier = new CardIdentifier(thresholdAlert, thresholdNotice);

Changing the check level

The library has multiple check levels (2 at present) which can be chosen by setting the checkLevel The check levels work as follows:

  • Level 1 This check gets number that are typed in continuously without breakage with special characters. Using this check would result in a text such as foo 123 456 bar returning two suspected fragments 123 and 456.
  • Level 2 This check interprets numbers separated by special characters as one block and only breaks the numbers when they are separated by alphabets, for example foo 123-45 bar 123 456 bar would result in the fragments 12345 and 123456

You can set the desired level of check as follows

    const checkLevel = 1;
    let identier = new CardIdentifier(null, null, checkLevel);

Changing the probability weight of different checks

You can change the weight assigned to different checks of the process as follows:

    const probabilities = {
        'LUHN':60,
        'TEST_NUMBERS':100,
        'PROVIDERS':15,
        'LENGTH':15,
    };
    let identifier = new CardIdentifier(null, null, null, null, null, null, null, probabilities);

Note that you have to provide a value for all the different checks if you want to change the probabilities.

Changing the constants used for performing checks

You can change the constants used for performing the checks. You can do the following by this:

  • Change the minimum and maximum possible card lengths
  • Change probability weight of different card lengths
  • Add/Edit Regex checks used to identify cards as well as their probability weight
  • Add new known test cards

This can be achieved as follows:

    let constants = new ValidationConstants();
    constants.MIN_POSSIBLE_LENGTH = 4;
    let identifier = new CardIdentifier(null, null, null, null, null, null, null, null, constants);

References

  • http://www.dirigodev.com/blog/ecommerce/anatomy-of-a-credit-card-number/
  • https://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number

Copyright

Published under MIT license. Copyright © 2017 Neblar Technologies