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

yourchoice

v2.2.4

Published

Resembles the selection behavior of popular file managers

Downloads

57

Readme

Yourchoice

Greenkeeper badge npm code style: actano Build Status codecov Dependency Status devDependency Status

YourChoice resembles the selection behavior of popular file managers. Pick items from a list using convenient functions like range selection. YourChoice covers the computation of the actual selection, no UI involved.

Installing

With npm

npm install yourchoice --save

Since yourchoice is a frontend module, you will need a module bundler like webpack or browserify.

Caution: Yourchoice uses es6/es7 features which are not supported in IE11 You can polyfill it with core-js

require('core-js/modules/es6.symbol')
require('core-js/modules/es6.array.from')
require('core-js/modules/es6.array.iterator')
require('core-js/modules/es6.object.assign')
require('core-js/modules/es7.array.includes')

Script tag

If you are the retro kind of person, you can also download the JavaScript file.

<script type="text/javascript" src="yourchoice.js"></script>

Usage

Yourchoice provides a functional interface. It is well-suited to be used in conjunction with lodash/flow or Redux. Of course, this interface can also be used in a non-functional environment. The imperative interface of yourchoice is considered deprecated.

All functions of yourchoice take an object of type State as their last argument. Some of the functions also return an updated State object. The state object is an opaque object representing the current state of yourchoice. The properties of this object are private and one should not depended upon them. In order to read properties form the state yourchoice provides accessor methods such as getSelection().

All functions exported by yourchoice are curried. That means that these functions can be partially applied with a subset of their arguments. This is particularly useful in conjunction with libraries like lodash/flow.

Example

const selectableItems = ['A', 'B', 'C', 'D', 'E']
const state = init()

newState = flow(
  setItems(selectableItems),
  replace('B'),
  rangeTo('D')
)(state)

console.log(getSelection(newState)) // ['B', 'C', 'D']

init() : State

Returns an empty state with no selection and no items that can be selected.

setItems(selectableItems, state) : State

Changes the current set of items that can be selected/deselected.

The selectableItems can be any javascript iterable. This enables yourchoice to operate on any data structure. Native data types such as Array or Map implement the iterable protocol.

This function is usually called initially before any selection is performed. This function should be called in order to update the yourchoice state when selectable items have been added or removed. For example, if some of the currently selected items are not present in the given selectableItems anymore, then these items will be automatically removed from the current selection.

replace(item, state) : State

Replaces the current selection with the given item. Also defines this item as the starting point for a subsequent rangeTo() selection. This is equivalent to a simple click by the user in a file manager.

toggle(item, state) : State

Adds or removes the given item to/from the selection. Other currently selected items are not affected. Also defines this item as the starting point for a subsequent rangeTo() selection if it is added to the selection. This is equivalent to an alt+click (cmd+click) by the user in a file manager.

rangeTo(item, state) : State

Selects a range of items usally starting from the previously toggled or replaced item and ending at the given item. This is equivalent to a shift+click by the user in a file manager.

setSelection(items, state) : State

Replaces the current selection with the given items.

remove(items, state) : State

Removes the given items from the current selection.

removeAll(state) : State

Removes all items from the current selection.

getItems(state) : Array

Returns an array containing all selectable items.

getSelection(state) : Array

Returns an array containing the currently selected items.

getChangedSelection(state) : Array

Returns an array containing those items that have been added to the selection by the directly preceding operation. E.g. calling this after a call to rangeTo() will return all the items that have been added to the selection by this operation.

getChangedDeselection(state) : Array

Returns an array containing those items that have been removed from the selection by the directly preceding operation. E.g. calling this after a call to rangeTo() will return all the items that have been removed from the selection by this operation.