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

@satyam-seth/otp-field

v1.0.5

Published

A configurable OTP field built using TypeScript and SCSS

Downloads

252

Readme

OTP Field Package

A customizable and easy-to-use OTP (One-Time Password) input field component for web applications. This package allows seamless integration of an OTP input field, with support for various features such as validation, theming, and accessibility.

Table of Contents

Features

  1. Configurable box count: Define the number of input boxes for the OTP field.
  2. Input validation: Restricts input to single characters and validates them based on the configured value - type (numeric, alphabetic, alphabetic lower, alphabetic upper, alphanumeric, alphanumeric lower, alphanumeric upper) or a custom regular expression.
  3. User interaction handling: Manages user interactions like input, paste, and keyboard events for smooth navigation and value management within the input boxes.
  4. Focus management: Automatically focuses on the appropriate input box based on user actions.
  5. Clear function: Clears all input boxes and resets the internal state.
  6. Destroy function: Removes the OTP field element from the DOM.

Installation

  • Install the package via npm:

    npm i @satyam-seth/otp-field
  • Install the package via npm:

    yarn add @satyam-seth/otp-field

Usage

  1. Import the OTPField class:
import { OTPField } from 'otp-field';
  1. Define the configuration for your OTP field:
const otpFieldConfig = {
  namespace: 'otp', // Namespace for IDs (used for styling)
  boxCount: 6, // Number of input boxes
  // valueType: OTPValueType.NUMERIC, // Input type (numeric, alphabetic, alphanumeric)
  // customRegex: /your_custom_regex/, // Custom validation regex
  // onPasteBlur: true, // Blur the input box after pasting (default: true)
};
  1. Create an instance of the OTPField class with the configuration:
const otpField = new OTPField(otpFieldConfig);
  1. Build the OTP field and append it to the desired element in your DOM:
const containerElement = document.getElementById('otp-container');
otpField.build(containerElement);
  1. Access the current OTP value entered by the user:
const otpValue = otpField.value;
  1. SCSS import for styling:
@import '../../node_modules/@satyam-seth/otp-field/src/scss/field';

@include otp-field;
  • Note: You can apply CSS classes like error, success, and warning to the div.otp-field container for state-specific theming.

API Reference

  • value: Retrieves the current value of the OTP input field.
  • id: Gets the unique identifier for the OTP field.
  • isDisabled: Retrieves the disabled state of the OTP input fields.
  • element: Gets the DOM element associated with the OTP field.
  • focus(): Sets focus on the first empty OTP input box. If all boxes are filled, focus is set to the last box.
  • clear(): Clears all OTP input boxes and resets the stored field value.
  • disable(disabled: boolean): Disables or enables OTP input fields based on the provided boolean value.
  • build(parentElement: HTMLElement): Builds the OTP field and appends it to the specified parent element.
  • destroy(): Removes the OTP field element from the DOM.

Example

You can check out the example here

License

This package is licensed under the MIT License. See the LICENSE file for details.

Contributing

Feel free to open issues or submit pull requests for improvements or bug fixes!