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

@jinyyy/payments-hooks

v0.0.6

Published

A library of Custom Hooks for React to validate payment card information.

Downloads

1

Readme

Hooks Module

A library of Custom Hooks for React to validate payment card information.

installation

npm install @jinyyy/react-payments

Hooks spec

useCardNumber

Returns a formatted value with the card company(amex, diners, visa, master, union pay) rules applied through validation.

Simple Example

const SimpleComponent = () => {
  const { cardNumbers, cardNumberError, handleChangeCardNumber } = useCardNumber();

  return (
    <>
      <h1>Card Numbers</h1>
      <input value={cardNumbers.join(' ')} onChange={(e) => handleChangeCardNumber(e.target.value.replace(/ /g, ''))} />
      <div>{cardNumberError.errorMessage}</div>
    </>
  );
};

Return Value

| Return Value | Type | Description | | ---------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------- | | { cardNumbers, cardNumberError, handleChangeCardNumber } | object | Contains the card numbers (string[]), card number error state, and a handler function. |

useExpiration

Return validated Card Expiration Date based on the current month. It takes a two-digit month consisting of January through December and a two-digit year. Also can only accept numeric input.

Simple Example

const SimpleComponent = () => {
    const { expiration, expirationError, handleChangeExpiration } = useExpiration();

    return (
        <h1>Card Expiration</h1>
        <input value={expiration.month} onChange={(e) => handleChangeExpiration('month', e.target.value)} />
        <input value={expiration.year} onChange={(e) => handleChangeExpiration('year', e.target.value)} />
        <div>{expirationError.errorMessage}</div>
    )
}

Return Value

| Return Value | Type | Description | | --------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------- | | { expiration, expirationError, handleChangeExpiration } | object | Contains the expiration date, expiration error state, and a handler to change the expiration. |

useOwnerName

Return validated Card Owner Name for the payment card. It takes a name of up to 20 characters. Also can only accept English capital letters.

Simple Example

const SimpleComponent = () => {
    const { ownerName, ownerNameError, handleChangeOwnerName } = useOwnerName();

    return (
        <h1>Card Owner Name</h1>
        <input value={ownerName} onChange={(e) => handleChangeOwnerName(e.target.value)} />
        <div>{ownerNameError.errorMessage}</div>
    )
}

Return Value

| Return Value | Type | Description | | ----------------------------------------------------- | -------- | --------------------------------------------------------------- | | { ownerName, ownerNameError, handleChangeOwnerName} | object | Contains the owner's name, error state, and a handler function. |

useCVCNumber

Also can only accept numeric input.> Return validated CVC Number for the payment card. It takes a consisting of three-digit number.

Simple Example

const SimpleComponent = () => {
    const { cvcNumber, cvcError, handleChangeCVCNumber } = useCVCNumber();

    return (
      <h1>Card CVC</h1>
      <input value={cvcNumber} onChange={(e) => handleChangeCVCNumber(e.target.value)} />
      <div>{cvcError.errorMessage}</div>
    )
}

Return Value

| Return Value | Type | Description | | ------------------------------------------------ | -------- | ------------------------------------------------------------- | | { cvcNumber, cvcError, handleChangeCVCNumber } | object | Contains the CVC number, error state, and a handler function. |

useCardPassword

It takes a consisting of three-digit number.twoAlso can only accept numeric input.> Return validated Card Password for the payment card. It takes a name of up to 20 characters. Also can only accept English capital letters.

Simple Example

const SimpleComponent = () => {
    const { cardPassword, cardPasswordError, handleChangeCardPassword } = useCardPassword();

    return (
      <h1>Card Password</h1>
      <input value={cardPassword} onChange={(e) => handleChangeCardPassword(e.target.value)} />
      <div>{cardPasswordError.errorMessage}</div>
    )
}

Return Value

| Return Value | Type | Description | | --------------------------------------------------------------- | -------- | ---------------------------------------------------------------- | | { cardPassword, cardPasswordError, handleChangeCardPassword } | object | Contains the card password, error state, and a handler function. |