0.0.3-b • Published 3 years ago

fancy-card-formatter v0.0.3-b

Weekly downloads
9
License
ISC
Repository
github
Last release
3 years ago

Fancy Card Formatter 💳

Fancy payment card formatter written in TypeScript. Includes a React hook.

Why this package?

While a number of credit card formatters already exist, many force their own styling and other design choices. In contrast, this package is a simple formatter for your HTML inputs, free for you to style and extend as you please.

Usage

TypeScript

import FancyCardFormatter from 'fancy-card-formatter';

const formatter = new FancyCardFormatter();
formatter.setValue('1234567890123456');
formatter.getValue(); // 1234 5678 9012 3456

Setting an initial value

const formatter = new FancyCardFormatter('1234567890123456');

React

You can use this package with any UI framework of your choice or even with plain old inputs.

import { FC, ChangeEvent } from 'react';
import { Form, Input } from 'antd';
import useFancyCardFormatter from 'fancy-card-formatter/react';

const CardInput: FC = () => {
  const [formattedCardNumber, formatCardNumber] = useFancyCardFormatter();

  const onChange = (event: ChangeEvent<HTMLInputElement>) => {
    formatCardNumber(event.target.value);
  };

  return (
    <Form>
      <Input value={formattedCardNumber} onChange={onChange} />
    </Form>
  );
};

export default CardInput;
0.0.3-b

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago