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

svelte-auth-code-input

v1.0.2

Published

> This package is a Svelte port of Luis Guerrero's React Auth Code Input (https://github.com/drac94/react-auth-code-input).

Downloads

15

Readme

This package is a Svelte port of Luis Guerrero's React Auth Code Input (https://github.com/drac94/react-auth-code-input).

image

Svelte Auth Code Input

One-time password (OTP) Svelte component, zero dependencies, fully tested.

NPM JavaScript Style Guide Software License npm npm GitHub actions state

Demo

Demo

Install

npm install --save svelte-auth-code-input

or

pnpm add svelte-auth-code-input

or

yarn add svelte-auth-code-input

Version 1+

Basic Usage

<script lang="ts">
    import AuthCodeInput from 'svelte-auth-code-input';

    let result = $state<string>('');
    const handleOnChange = (res: string) => {
        result = res;
    };
</script>

<AuthCodeInput
onchange={handleOnChange}
/>

Bound Input

<script lang="ts">
    import AuthCodeInput from 'svelte-auth-code-input';

    let result = $state<string>('');
</script>

<AuthCodeInput
  bind:value={result}
/>

Mode

By default, you can type numbers and letters in the inputs as the allowedCharacters prop is defaulted to alphanumeric but you can also choose between allowing only letters or only numbers by setting the prop to alpha or numeric respectively.

<script lang="ts">
    import AuthCodeInput from 'svelte-auth-code-input';

    let result = $state<string>('');
    const handleOnChange = (res: string) => {
        result = res;
    };
</script>

<AuthCodeInput allowedCharacters='numeric'
onchange={handleOnChange}
/>

Focus

By default the first input is focused when the component is mounted, you can opt out of this by setting the autoFocus prop to false, and then you can handle the focus manually by passing a reference.

<script lang="ts">
    import AuthCodeInput from 'svelte-auth-code-input';

    let AuthInputRef = $state<AuthCodeInput>();
    let result = $state<string>('');
    const handleOnChange = (res: string) => {
        result = res;
    };
</script>

<AuthCodeInput
autoFocus={false}
onchange={handleOnChange}
bind:this={AuthInputRef}
/>
<button onClick={() => AuthInputRef?.focus()}>Focus</button>

Clear

You can clear all the inputs by passing a reference and then calling the clear method.

<script lang="ts">
    import AuthCodeInput from 'svelte-auth-code-input';

    let AuthInputRef = $state<AuthCodeInput>();
    let result = $state<string>('');
    const handleOnChange = (res: string) => {
        result = res;
    };
</script>

<AuthCodeInput
autoFocus={false}
onchange={handleOnChange}
bind:this={AuthInputRef}
/>
<button onClick={() => AuthInputRef?.clear()}>Clear</button>

SMS Autofill

This component supports autofill from SMS' received, tested on Safari and Chrome in iOS.

Props

| Prop | Type | Description | Default Value | Observations | | :------------------- | :---------------------- | :---------------------------------------------------------- | :------------- | :----------------------------------------------- | | allowedCharacters | String | Type of allowed characters for your code. | alphanumeric | Valid values: alpha, alphanumeric, numeric | | ariaLabel | String | Accessibility. | | | | autoFocus | Boolean | Whether the first input is focused on mount or not.. | true | | | length | Number | The number of inputs to display. | 6 | | | containerClass | String | The styles to be applied to the container. | | | | inputClass | String | The styles to be applied to each input. | | | | onchange | Function(value: String) | Callback function called every time an input value changes. | | Required | | isPassword | Boolean | Whether to display the inputs as passwords or not. | false | | | disabled | Boolean | Makes all the inputs disabled if true. | false | | | placeholder | String | Displays a placeholder in all the inputs. | | | | value | String | Bindable value (one way; component -> parent) | | | | name | String | Copies the result to a hidden input with this name for use in forms. | | |

Changelog

1.0.0

Added this README

License

Licensed under the MIT License, Copyright © 2024-present Jin Chan jinbe.

See LICENSE for more information.