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

react-localized-input

v1.0.3

Published

A simple input library for React and Next.js

Readme

react-localized-input

A simple and customizable React input component designed to validate user input based on the selected language or script. This library helps ensure that users input valid characters according to specific languages such as Katakana, Hiragana, and more.

Features

  • Language-specific validation: Provides built-in support for various languages and scripts (e.g., Japanese Katakana, Hiragana, Alphanumeric).
  • Customizable validation logic: Allows you to define custom validation functions based on your application's requirements.
  • Easy to integrate: Simple API for integrating into your React forms and applications.

Installation

To install the library, you can use either npm or yarn.

Using npm:

npm install react-localized-input

Using yarn:

yarn add react-localized-input

Usage

Once installed, you can start using the InputComponent for your form fields that require language-specific validation. Below is an example of using the library with Japanese Katakana validation.

Example Usage:

import { InputComponent, LanguageValidationProps } from "react-localized-input";

const App = () => {
  const katakanaValidation: LanguageValidationProps = {
    isValid: (char) => /^[゠-ヿー・ -〿―—− ̄]$/.test(char),
    lang: "ja-JP", // Japanese Katakana validation
  };

  return (
    <div>
      <h1>Localized Input Example</h1>
      <InputComponent
        languageValidation={katakanaValidation}
        placeholder="Enter Katakana"
        onChange={(e) => console.log(e.target.value)}
      />
    </div>
  );
};

export default App;

Language Validation Props

The languageValidation prop accepts an object with the following properties:

  • isValid: A function that checks if a character is valid for the given language. It receives the character as an argument and should return true if the character is valid and false otherwise.

Example:

isValid: (char) => /^[a-zA-Z]$/.test(char);
  • lang: A string representing the language code (e.g., "ja-JP" for Japanese).

Customizing Validation

You can customize the isValid function to validate input according to different character sets or scripts. Some examples are provided below.

Katakana Validation

const katakanaValidation: LanguageValidationProps = {
  isValid: (char) => /^[゠-ヿー・ -〿―—− ̄]$/.test(char),
  lang: "ja-JP", // Japanese Katakana validation
};

Hiragana Validation

const hiraganaValidation: LanguageValidationProps = {
  isValid: (char) => /^[぀-ゟー゙゚]$/.test(char),
  lang: "ja-JP", // Japanese Hiragana validation
};

Alphanumeric Validation

const alphanumericValidation: LanguageValidationProps = {
  isValid: (char) => /^[a-zA-Z0-9]$/.test(char),
  lang: "en-US", // English alphanumeric validation
};

InputComponent Props

The InputComponent accepts the following props:

  • languageValidation: An object containing the validation logic for the specific language (see Language Validation Props).
  • placeholder: A string that specifies the placeholder text for the input field.
  • onChange: A function that is called when the value of the input changes. It receives the event object as an argument.

Example:

onChange={(e) => console.log(e.target.value)}
  • value (Optional): The value of the input field.
  • disabled (Optional): Boolean that disables the input field when set to true.
  • maxLength (Optional): The maximum number of characters allowed in the input field.

Example of Using the Input Component:

import { InputComponent, LanguageValidationProps } from "react-localized-input";

const App = () => {
  const katakanaValidation: LanguageValidationProps = {
    isValid: (char) => /^[゠-ヿー・ -〿―—− ̄]$/.test(char),
    lang: "ja-JP",
  };

  const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    console.log(e.target.value);
  };

  return (
    <div>
      <h1>Localized Input Example</h1>
      <InputComponent
        languageValidation={katakanaValidation}
        placeholder="Enter Katakana"
        onChange={handleInputChange}
        value=""
      />
    </div>
  );
};

export default App;

Advanced Customization

Handling Multiple Languages

You can handle multiple languages in the same application by creating different validation functions for each language. Below is an example of handling both Katakana and Hiragana:

const katakanaValidation: LanguageValidationProps = {
  isValid: (char) => /^[゠-ヿー・ -〿―—− ̄]$/.test(char),
  lang: "ja-JP", // Katakana validation
};

const hiraganaValidation: LanguageValidationProps = {
  isValid: (char) => /^[぀-ゟー゙゚]$/.test(char),
  lang: "ja-JP", // Hiragana validation
};

Custom Error Messages

You can further customize the library to display error messages when invalid characters are entered. Simply update your onChange handler to validate input and show a message.

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
  const value = e.target.value;
  if (katakanaValidation.isValid(value[value.length - 1])) {
    // Continue processing the valid input
    console.log(value);
  } else {
    console.log("Invalid input, please enter only Katakana characters");
  }
};

License

This project is licensed under the MIT License - see the LICENSE file for details.