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

allowtype

v1.2.6

Published

Allow type specific thing in input box or textarea

Downloads

37

Readme

allowType

npm npm bundle size (version) GitHub release (by tag) jsDelivr hits (npm) npm GitHub issues GitHub closed issues

A quick function to allow type into input

allowType(selector, option, length, toCase, setState)

New syntax

Now arguments can be passed as config object

allowType(selector, config)
  • config { option, length, toCase, setState }

  • selector (Event|Selector|Node)

  • option

    • alpha - (alphabets only no space)
    • alphaspace (alphabets with space)
    • alphanum (alphanumeric without space)
    • alphanumspace (alphanumeric with space)
    • slug (alphanumeric slug)
    • number (numbers only)
    • mobile (10 digit Indian mobile number)
    • decimal (decimal number with decimals digit length)
    • pincode (Indian pin code)
    • pan (Indian pan card number)
    • ifsc (IFSC - Indian Financial System Code)
  • length (define return length)

  • toCase

    • upper (Uppercase)
    • lower (Lowercase)
    • title (Titlecase)
    • word (Wordcase)
  • setState (Update react state or use as callback)

Deployment

To use allowType include allowtype.js just above closing body tag into html

  <script src="allowtype.js"></script>

OR use jsDeliver CDN

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/allowtype.min.js"></script>

OR use unpkg CDN

  <script src="https://unpkg.com/[email protected]/allowtype.js"></script>

Usage

Inline Uses:

Allow alpha with length 10 characters

<input type="text" oninput="allowType(event, 'alpha', 10)">

Allow alphanumeric only

<input type="text" oninput="allowType(event, 'alphanum', 10)">

Allow slug with dash (-)

<input type="text" oninput="allowType(event, 'slug')">

Allow numbers only

<input type="text" oninput="allowType(event, 'number')">

Allow decimals with two decimal places

<input type="text" oninput="allowType(event, 'decimal', 2)">

Allow alpha with no length limit and convert to uppercase

<input type="text" oninput="allowType(event, 'alpha', false, 'upper')">

Allow Indian pincode

<input type="text" oninput="allowType(event, 'pincode')">

Allow Indian PAN card number

<input type="text" oninput="allowType(event, 'pan')">

Allow IFSC (Indian Financial System) Code

<input type="text" oninput="allowType(event, 'ifsc')">

Using EventListener

<input type="text" id="number-input">
<script>
  document.querySelector('#number-input')
  .addEventListener('input', function(e) {
    allowType(this, 'number');
  })
</script>

Using React

npm i allowtype
import allowtype from 'allowtype';

function NumberOnlyInput() {
  function handleOnInput(event) {
    allowtype(event, 'number');
  }

  return (<>
    <input type="text" onInput={handleOnInput} />
  </>);
}

export default NumberOnlyInput;

useState hook to manage value state

import allowtype from 'allowtype';
import { useState } from "react";

function NumberOnlyInput() {
  const [ value, setValue ] = useState('');

  return (<>
    <input type="text" value={value} onInput={
      (event) => allowtype(event, { // New syntax, old is also available
        option: 'number',
        setState: setValue
      })
    } />
  </>);
}

export default NumberOnlyInput;

License

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

Author