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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shjeon0730/mask-hook

v0.1.4

Published

EIN/SSN masking React hook – works with React and React Native

Readme

@shjeon0730/mask-hook

When handling masking, it usually start with very small logic, and it would work. But the more the complexity is added to support multiple different format of masking, the logic easily go to inconsistent and unstable mutations. This hook includes smooth handling logic to handle masking patterns supporting Any pattern.

@shjeon0730/mask-hook is a React hook for general-purpose numeric formatting and masking — works seamlessly on web and mobile (React Native / Expo).

Cross-platform: one hook, zero platform-specific code. Drop it into a React web app or a React Native / Expo project and it behaves identically.

Designed for controlled input flows where you need:

  • Masked and visible display modes (toggle eye icon pattern)
  • Stable digit parsing while typing and deleting
  • Focus-based re-initialization for tab navigation scenarios
  • Custom patterns for any digit length (not limited to SSN/EIN)
  • Even though partial value is given, this hook will make it pretty following the given format.

Demo

mask-hook demo

Installation

npm install @shjeon0730/mask-hook

Peer dependency: react >= 16.8.0

Quick Start

React (web)

import { useEffect, useState } from 'react';
import { SsnFormats, useMask } from '@shjeon0730/mask-hook';

export function SsnField() {
  const [storedValue, setStoredValue] = useState('');

  const {
    displayedValue,
    isNumberVisible,
    canEyeIconVisible,
    setIsNumberVisible,
    onChangeText,
    handleInputFocused,
    handleInputBlurred,
    initialize,
  } = useMask({
    maskInfo: SsnFormats,
    defaultMaskedValue: '6789',
    unmaskedValue: storedValue,
    onValueChanged: setStoredValue,
  });

  useEffect(initialize, [initialize]);

  return (
    <>
      <input
        value={displayedValue}
        onChange={(e) => onChangeText(e.target.value)}
        onFocus={handleInputFocused}
        onBlur={handleInputBlurred}
        placeholder="___-__-____"
      />
      <button
        type="button"
        onClick={() => setIsNumberVisible(!isNumberVisible)}
        disabled={!canEyeIconVisible}
      >
        {isNumberVisible ? 'Hide' : 'Show'} digits
      </button>
    </>
  );
}

React Native

import { useEffect } from 'react';
import { TextInput, TouchableOpacity, Text } from 'react-native';
import { SsnFormats, useMask } from '@shjeon0730/mask-hook';

export function SsnField({ value, onChange }) {
  const {
    displayedValue,
    isNumberVisible,
    canEyeIconVisible,
    setIsNumberVisible,
    onChangeText,
    handleInputFocused,
    handleInputBlurred,
    initialize,
  } = useMask({
    maskInfo: SsnFormats,
    defaultMaskedValue: '6789',
    unmaskedValue: value,
    onValueChanged: onChange,
  });

  // if unsure re-mounting(i.e. react-navigation screens), use useFocusEffect(initialize)
  useEffect(initialize, [initialize]);

  return (
    <>
      <TextInput
        value={displayedValue}
        onChangeText={onChangeText}
        onFocus={handleInputFocused}
        onBlur={handleInputBlurred}
        placeholder="___-__-____"
      />
      <TouchableOpacity
        onPress={() => setIsNumberVisible(!isNumberVisible)}
        disabled={!canEyeIconVisible}
      >
        <Text>{isNumberVisible ? 'Hide' : 'Show'} digits</Text>
      </TouchableOpacity>
    </>
  );
}

Tab Navigation (Expo Router / React Navigation)

When using navigation, screens often stay mounted. Call initialize each time the screen gets focus so the field resets to its default presentation.

Expo Router:

import { useFocusEffect } from 'expo-router';

useFocusEffect(initialize);

React Navigation:

import { useFocusEffect } from '@react-navigation/native';

useFocusEffect(initialize);

API

useMask(params)

Parameters

| Name | Type | Required | Description | |------|------|----------|-------------| | maskInfo | MaskInfo | ✓ | Formatting rules. Use SsnFormats, EinFormats, or a custom object. | | defaultMaskedValue | string | ✓ | Seed value shown when the field is in its initial (untouched) state. | | unmaskedValue | string | ✓ | Current external value (digits only, or formatted — both accepted). | | onChange | (value: string) => void | | Called on user edits with the formatted visible value. | | onBlur | () => void | | Called on blur after the user has modified the input. | | onValueChanged | (value: string) => void | | Called on user edits; useful for syncing parent state. |

Return value

| Name | Type | Description | |------|------|-------------| | displayedValue | string | Current string to render in the input (masked or visible). | | isDirty | boolean | true after any user-driven edit. | | isNumberVisible | boolean | Current visibility mode (true = digits shown). | | canEyeIconVisible | boolean | Whether the visibility toggle should be enabled. | | setIsNumberVisible | (value: boolean) => void | Toggles masked / visible mode. | | onChangeText | (value: string) => void | Input change handler — pass to onChange / onChangeText. | | handleInputFocused | () => void | Focus handler — clears the seeded default when appropriate. | | handleInputBlurred | () => void | Blur handler — restores the seeded default when appropriate. | | initialize | () => void | Re-seeds and normalizes state; call on mount and on screen focus. |

Built-in formats

The package includes SSN and EIN presets for convenience, but you can provide your own MaskInfo for any numeric format.

| Export | maskedFormat | visibleFormat | |--------|---------------|-----------------| | SsnFormats | •••–••–9999 | 999–99–9999 | | EinFormats | ••–•••9999 | 99–9999999 |

Custom format

You can supply any MaskInfo object:

import type { MaskInfo } from '@shjeon0730/mask-hook';

const MyFormat: MaskInfo = {
  maskedFormat: '••••9999',   // • = masked digit, 9 = visible digit
  visibleFormat: '99999999',  // 9 = visible digit
};

Note: the number part can be any number. ***-**-0000 is also a valid format

Types

import type { MaskInfo, UseMaskParams } from '@shjeon0730/mask-hook';

type MaskInfo = {
  maskedFormat: string;
  visibleFormat: string;
};

type UseMaskParams = {
  maskInfo: MaskInfo;
  defaultMaskedValue: string;
  unmaskedValue: string;
  onChange?: (changedValueUnmasked: string) => void;
  onBlur?: () => void;
  onValueChanged?: (formattedValue: string) => void;
  onEyeClickedToUpdateRealValue?: () => void;
};

License

MIT