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

credit-card-digit-mimic

v0.0.2

Published

A package to mimic credit card numbers by masking digits.

Downloads

5

Readme

This README.md file provides a comprehensive guide to your `credit-card-digit-mimic` package, including installation instructions, basic usage, detailed examples, and various integration scenarios. It covers usage in different environments such as Node.js, Express.js, AWS Lambda, Next.js, and React.js, making it a valuable resource for developers looking to implement credit card number masking in their projects.

Certainly! I'll compile all the information into a single README.md file for you. Here's the complete README.md content:

# credit-card-digit-mimic

A package to mimic credit card numbers by masking digits.

## Installation

Install the package using npm:

```bash
npm install credit-card-digit-mimic

Usage

Basic Usage

const { cc_mimic_4, ccmimic_12 } = require('credit-card-digit-mimic');

// Masking the last 4 digits
cc_mimic_4("1111223311112233");

// Masking the first 12 digits
ccmimic_12("1111111111223344");

Output

  • cc_mimic_4("1111223311112233") will print 11112233111*****.
  • ccmimic_12("1111111111223344") will print ************3344.

Detailed Examples

Example 1: Masking a Valid 16-Digit Credit Card Number

cc_mimic_4("1234567812345678"); // Output: 123456781234****
ccmimic_12("1234567812345678"); // Output: ************5678

Example 2: Handling Credit Card Number Shorter than 16 Digits

cc_mimic_4("12345678"); // Output: try Again Length of Credit card is low 8
ccmimic_12("12345678"); // Output: try Again Length of Credit card is low 8

Example 3: Handling Credit Card Number Longer than 16 Digits

cc_mimic_4("123456781234567890"); // Output: try Again Length of Credit card is exceeded 18
ccmimic_12("123456781234567890"); // Output: try Again Length of Credit card is exceeded 18

Example 4: Edge Case with Exactly 16 Digits

cc_mimic_4("0000000000000000"); // Output: 000000000000****
ccmimic_12("0000000000000000"); // Output: ************0000

Example 5: Masking with Different Characters

const customMask = (ccNumber) => {
  const maskedCC = ccNumber.slice(0, 12).padEnd(16, "#");
  console.log(maskedCC);
};

customMask("1111222233334444"); // Output: 111122223333####

Example 6: Integration in an Express.js Application

const express = require('express');
const { cc_mimic_4, ccmimic_12 } = require('credit-card-digit-mimic');

const app = express();

app.get('/mask', (req, res) => {
  const { ccNumber } = req.query;
  res.send({
    maskedCC4: cc_mimic_4(ccNumber),
    maskedCC12: ccmimic_12(ccNumber)
  });
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Example 7: Using in AWS Lambda with Node.js

1. Set Up Your AWS Lambda Function

Create a new AWS Lambda function and configure it with a Node.js runtime.

2. Add Your Code

Upload your code to the Lambda function.

const { cc_mimic_4, ccmimic_12 } = require('credit-card-digit-mimic');

exports.handler = async (event) => {
  const ccNumber = event.queryStringParameters.ccNumber;

  return {
    statusCode: 200,
    body: JSON.stringify({
      maskedCC4: cc_mimic_4(ccNumber),
      maskedCC12: ccmimic_12(ccNumber)
    }),
  };
};

Example 8: Using in a Next.js Application

// pages/api/mask.js
import { cc_mimic_4, ccmimic_12 } from 'credit-card-digit-mimic';

export default function handler(req, res) {
  const { ccNumber } = req.query;

  res.status(200).json({
    maskedCC4: cc_mimic_4(ccNumber),
    maskedCC12: ccmimic_12(ccNumber)
  });
}

Example 9: Using in a React.js Component

import React, { useState } from 'react';
import { cc_mimic_4, ccmimic_12 } from 'credit-card-digit-mimic';

function MaskCreditCard() {
  const [ccNumber, setCcNumber] = useState('');
  const [maskedCC4, setMaskedCC4] = useState('');
  const [maskedCC12, setMaskedCC12] = useState('');

  const handleMask = () => {
    setMaskedCC4(cc_mimic_4(ccNumber));
    setMaskedCC12(ccmimic_12(ccNumber));
  };

  return (
    <div>
      <input
         type="text"
         value={ccNumber}
         onChange={(e) => setCcNumber(e.target.value)}
         placeholder="Enter credit card number"
       />
      <button onClick={handleMask}>Mask</button>
      <div>
        <p>Masked with last 4 digits: {maskedCC4}</p>
        <p>Masked with first 12 digits: {maskedCC12}</p>
      </div>
    </div>
  );
}

export default MaskCreditCard;

Example 10: Masking Credit Card in a CLI Application

const { cc_mimic_4, ccmimic_12 } = require('credit-card-digit-mimic');
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('Enter a credit card number: ', (ccNumber) => {
  console.log('Masked with last 4 digits: ', cc_mimic_4(ccNumber));
  console.log('Masked with first 12 digits: ', ccmimic_12(ccNumber));
  rl.close();
});

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the ISC License.

Made by

Rupesh Sharma aka "github.com/rupesh9369"