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

typed-input

v1.2.1

Published

An ultra simple element that extends the native input element and makes it typed.

Downloads

8

Readme

Typed Input

Published on webcomponents.org GitHub release Build status Minified + gzipped size

Demo and API docs

An ultra simple element that extends the native input element and makes it typed.

Installation

npm i typed-input
# or
yarn add typed-input

Without npm/yarn

If you don't use npm or yarn, an IIFE (Immediately Invoked Function Expression) version of the element is also provided. The IIFE version of the element can also be used if you're still on Bower (e.g. if you're using Polymer < 3). To use it, just use the unpkg CDN:

<script src="https://unpkg.com/typed-input/typed-input.iife.min.js"></script>

Usage

Basic

After importing the ESM or the IIFE version of the element, just add is="tryped-input" to your input tag. From now on, your input.value will automagically be converted to the right type (numbers for input[type="number"], dates for input[type="date"], etc.). Remember that to get the typed value you will need to read the value property, not the value attribute. e.g. input.value will work, input.getAttribute('value') won't.

If for some reason you need to access the original, stringified value, you can use the backup property input.rawValue.

Practical example:

<script type="module" src="path/to/typed-input.js"></script>
<input is="typed-input" type="number" id="input">
<script>
  console.log(typeof input.value === 'number');
  // true
  console.log(typeof input.rawValue === 'string');
  // true
</script>

Extending the element

If you're building your own input element and you want it to be typed, you can extend HTMLTypedInputElement instead of HTMLInputElement.

Practical example:

import { HTMLTypedInputElement } from 'typed-input';

class MyCustomTypedInput extends HTMLTypedInputElement {
  // ...
}

customElements.define('my-custom-typed-input', MyCustomTypedInput, { extends: 'input' });

Using the mixin

If you are extending an element that already extends the native input, or you need to add types to an input-like element (i.e. an element that has type, value and checked properties), a typed mixin is also provided.

Practical example:

import { typed } from 'typed-input';

class MyCustomTypedInput extends typed(MyInputLikeElement) {
  // ...
}

customElements.define('my-custom-typed-input', MyCustomTypedInput, { extends: 'input' });