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

svelte-segmented-input

v1.6.7

Published

A simple component for number-only segmented input. Ideal for 2FA codes.

Readme

svelte-segmented-input svelte-segmented-input

A simple component for number-only segmented input. Ideal for 2FA codes. Minified and gzipped the package is ~9kb, and can be used with svelte's client-side component API in non-svelte projects.

NOTE: Deprecated

HOW TO USE:

1. Svelte

<script>
    import SvelteSegmentedInput from 'svelte-segmented-input'

    let value

    let callback = (e) => console.log(e)
</script>

<SvelteSegmentedInput bind:value="{value}" length="{6}" style="{{borderColor: 'black', inputWidth: '50%'}}" on:valueEntered="{callback}" />

value is the current value of the input as a string with spaces in non-populated fields. Setting rhe variable value will change the input value to the given input if it's a number or can be coerced to a number.

length is the number of fields. accepts number or an array of numbers. when an array is passed, it will create the segments such as for an array [3, 3, 4] the input will look like this: [] [] [] - [] [] [] - [] [] [] [].

style is an object which holds sets custom CSS properties to control the styling of the component.

on:valueEntered is an event that fires every time a full value is entered. event.detail.value is the value that was entered.

2. Vanilla JS (with module bundler)

import SegmentedInput from 'svelte-segmented-input'

const component = new SegmentedInput({
	target: document.querySelector('#app'), // where to attach the component in the DOM
	props: {
		length: 6, // length of the input; can be an array to specify segments
		value: 123, // initial value
	},
})

// event listener. removeEvent() will remove the event listener
const removeEvent = component.$on('valueEntered', (e) => console.log(e.detail.value))

// log the current value of the component
console.log(component.value)

Setting value in the props object will not trigger the valueEntered event, however setting it using component.value will

STYLING:

input

  • font-size: var(--fontSize, 2rem);
  • border-radius: var(--borderRadius, 0.4rem);
  • border: var(--borderWidth, 2px) solid var(--borderColor, #e5e5e5);
  • padding: var(--padding, 0.25rem 1rem);
  • color: var(--textColor, black);
  • background-color: var(--bgInput, transparent);

input:focus

  • border: var(--borderWidth, 2px) solid var(--borderColorActive, #5f91f0);

input-wrapper

  • width: var(--inputWidth, 100%);
  • background-color: var(--bgWrapper, transparent);
  • gap: var(--gap); // if gap is not set or is set to 'auto', it's treated as setting justify content: space-between; instead

Alternatively, you can target each item with a descendant selector, as all elements are inside a div with id #input-wrapper.

KNOWN ISSUES:

  1. This solution isn't accessible, as it relies on multiple input elements and breaks a lot of browsers behaviours (i. e. ctrl+f to search). This is a milestone I'm trying to reach with v2.0
  2. On mobile phones it is possible to input + and - characters. I have no idea how it happens.
  3. Binding the length property will break when length is smaller than the number of fields that are populated. Please, don't bind the length property.