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

select-box

v1.1.0

Published

a minimal DOM select box utility

Downloads

36

Readme

select-box

unstable

img

A minimal DOM <select> utility. Pull requests / suggestions welcome.

//create a select box
var box = require('select-box')(['Monday', 'Tuesday', 'Wednesday'])

//select an item programmatically
box.select('Tuesday')

box.on('change', function(ev) {
	//get name of selected item
	console.log(box.selected())
})

//have it displayed on page
document.body.appendChild(box.element)

Usage

NPM

See demo for a complete example.

box = SelectBox([items])

Creates a new select box with the optional items to add.

items can be a string, or an array of strings.

Or, it can be a key-value pair like so:

var box = SelectBox({
    hello: 'Hello!',
    goodbye: 'Goodbye!'
});

Now logging console.log(box.element.outerHTML) results in:

<select>
    <option value="hello">Hello!</option>
    <option value="goodbye">Goodbye!</option>
</select>

box.element

The DOM element for this <select> box.

box.add(items)

Adds a single item or an array of items to this select box. An "item" is just a string (which indicates value and name), or an object:

{
	name: 'Tuesday',
	value: 'tuesday', 
	disabled: false
}

Returns this for chaining.

box.clear()

Clears the data in the box. Returns this for chaining.

box.set(data)

Clears the current data in the box and adds the specified data. Returns this for chaining.

box.selected()

Gets the selected value for this combo box.

box.selectedIndex()

Same as selected(), but returns the index of the entry in the data list.

box.select(value)

Selects the item by value in this combo box, if it exists.

Returns this for chaining.

box.data

The internal data which was passed to add, set or a constructor. This should not be modified externally, although it could be used to retrieve values and names of each entry.

box.on('change')

Receives the onchange DOM event.

License

MIT, see LICENSE.md for details.