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

soha-hooks

v0.0.5

Published

Custom hook used in credit card payment input field

Downloads

6

Readme

Hooks Module

useInput

사용자가 입력한 값을 상태 관리한다.

  • 입력 값은 object이다.
  • handleInputChange는 event를 인자로 받아 값을 업데이트 한다.
  • updateByNameAndValue는 name과 value를 인자로 받아 값을 업데이트 한다.

각 form에 대한 Hook

useCardBrand

신용카드 카드번호 입력에 따라 카드 브랜드와 카드번호 입력 최댓값을 찾는 커스텀 훅

  • props로 cardNumber를 받아 각 카드 브랜드를 조건에 맞춰 찾는다.
  • 카드 브랜드가 존재하지 않을 경우 cardBrand는 null이고 maxLength는 16(DefaultMaxCardNumber)이다.
  • 카드 브랜드 종류: Visa, MasterCard, AMEX, Diners, UnionPay

useCardNumber

신용카드 카드번호에 대한 커스텀 훅

  • 카드번호는 입력한 값에 따라 카드 브랜드를 찾아, 해당 카드 브랜드에 맞는 입력 최댓값의 숫자만 들어올 수 있다.
  • ex) 카드 브랜드가 AMEX일 경우, 입력 최댓값은 15이다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

useCardHolder

신용카드 소유자 이름에 대한 커스텀 훅

  • 입력한 카드 소유자 이름은 영어만 들어올 수 있다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

useExpiryDate

신용카드 유효기간에 대한 커스텀 훅 입력한 유효기간이 currentDate 이전일 경우, 에러가 발생한다.

  • 입력 값으로 1~12의 숫자만 들어올 수 있다.
  • 입력 값으로 1 또는 01 모두 유효하다.
  • 1만 입력 시 01로 바꿔준다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

년도

  • 입력 값으로 2자리 숫자만 들어올 수 있다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

useCVC

신용카드 CVC에 대한 커스텀 훅

  • 입력 값으로 3자리 숫자만 들어올 수 있다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

useCardType

신용카드 카드사에 대한 커스텀 훅

  • 미리 정의된 카드사만 선택 할 수 있다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

usePassword

신용카드 비밀번호에 대한 커스텀 훅

  • 입력 값으로 2자리 숫자만 들어올 수 있다.
  • 유효한 값이 아닐 경우 에러가 발생한다.

사용예시

function Example() {
  const {
    inputValue,
    validationResult,
    cardBrand,
    handleCardNumberChange,
    handleCardNumberBlur,
    handleCardNumberEnter,
    handleCardNumberFocus,
  } = useCardNumber({ cardNumber: "" });

  console.log(validationResult);

  return (
    <>
      <h1>Hooks Modules</h1>
      <p>{cardBrand}</p>
      <input
        type="text"
        name="cardNumber"
        value={inputValue.cardNumber}
        onChange={(e) => handleCardNumberChange(e)}
        onBlur={(e) => handleCardNumberBlur(e)}
        onKeyDown={(e) => handleCardNumberEnter(e)}
        onFocus={(e) => handleCardNumberFocus(e)}
      />
    </p>
  );
}

export default Example;