Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thebespokepixel/n-selector
Smart multi-gang enumerator with global, namespaced event emission for node.js.
https://github.com/thebespokepixel/n-selector
enumerator node-module npm proportional
Last synced: 23 days ago
JSON representation
Smart multi-gang enumerator with global, namespaced event emission for node.js.
- Host: GitHub
- URL: https://github.com/thebespokepixel/n-selector
- Owner: thebespokepixel
- License: mit
- Created: 2016-09-18T12:45:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-14T17:52:12.000Z (almost 2 years ago)
- Last Synced: 2024-11-20T04:04:50.275Z (about 1 month ago)
- Topics: enumerator, node-module, npm, proportional
- Language: JavaScript
- Size: 23.5 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# @thebespokepixel/n-selector
> Smart multi-gang enumerator with global, namespaced event emission for node.js.
##### Publishing Status
[![npm](https://img.shields.io/npm/v/@thebespokepixel/n-selector?logo=npm "npm")](https://www.npmjs.com/package/@thebespokepixel/n-selector "npm") [![Libraries.io](https://img.shields.io/librariesio/release/npm/@thebespokepixel/n-selector/latest?\&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij4KICA8cGF0aCBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01Ljk5OTMxNDIyLDE1LjI3NyBMNiwyMyBDNiwyMy41NTIyODQ3IDUuNTUyMjg0NzUsMjQgNSwyNCBMMiwyNCBDMS40NDc3MTUyNSwyNCAxLDIzLjU1MjI4NDcgMSwyMyBMMC45OTkzMTQyMjIsMTkuMTg0IEw1Ljk5OTMxNDIyLDE1LjI3NyBaIE0xNC40OTkzMTQyLDguNjM2IEwxNC41LDIzIEMxNC41LDIzLjU1MjI4NDcgMTQuMDUyMjg0NywyNCAxMy41LDI0IEwxMC41LDI0IEM5Ljk0NzcxNTI1LDI0IDkuNSwyMy41NTIyODQ3IDkuNSwyMyBMOS40OTkzMTQyMiwxMi41NDMgTDE0LjQ5OTMxNDIsOC42MzYgWiBNMTcuOTk5MzE0Miw4LjMzNCBMMjIuOTk5MzE0MiwxMi4xMDIgTDIzLDIzIEMyMywyMy41NTIyODQ3IDIyLjU1MjI4NDcsMjQgMjIsMjQgTDE5LDI0IEMxOC40NDc3MTUzLDI0IDE4LDIzLjU1MjI4NDcgMTgsMjMgTDE3Ljk5OTMxNDIsOC4zMzQgWiBNNSwwIEM1LjU1MjI4NDc1LDAgNiwwLjQ0NzcxNTI1IDYsMSBMNS45OTkzMTQyMiwxMS40NzEgTDAuOTk5MzE0MjIyLDE1LjM3OCBMMSwxIEMxLDAuNDQ3NzE1MjUgMS40NDc3MTUyNSwwIDIsMCBMNSwwIFogTTEzLjUsMCBDMTQuMDUyMjg0NywwIDE0LjUsMC40NDc3MTUyNSAxNC41LDEgTDE0LjQ5OTMxNDIsNC44MzEgTDkuNDk5MzE0MjIsOC43MzcgTDkuNSwxIEM5LjUsMC40NDc3MTUyNSA5Ljk0NzcxNTI1LDAgMTAuNSwwIEwxMy41LDAgWiBNMjIsMCBDMjIuNTUyMjg0NywwIDIzLDAuNDQ3NzE1MjUgMjMsMSBMMjIuOTk5MzE0Miw4LjM0NyBMMTcuOTk5MzE0Miw0LjU3OSBMMTgsMSBDMTgsMC40NDc3MTUyNSAxOC40NDc3MTUzLDAgMTksMCBMMjIsMCBaIi8%2BCjwvc3ZnPgo%3D "Libraries.io")](https://libraries.io/github/thebespokepixel/n-selector "Libraries.io")
[![Travis](https://img.shields.io/travis/com/thebespokepixel/n-selector/master?logo=travis "Travis")](https://travis-ci.com/thebespokepixel/n-selector "Travis") [![Rollup](https://img.shields.io/badge/es6-type%3A%20module%20%E2%9C%94-64CA39?\&logo=data%3Aim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zc3NiBDNy4xOTk3Mzg0OCwxLjkwMzY3Nzc2IDYuODIwMDA2NTQsMi40MjY5NzAyMyAzLjkyMDIzNTM3LDcuNjE5OTY0OTcgQzIuMzg3Nzk5MzQsMTAuMzY1NDA2NyAyLjAxMDgzMTkzLDExLjU3MzUwNzkgMi4wMDYyOTA2OSwxMi4xNjk4MTgyIEMyLDEyLjk5NTg0OTUgMi4wMDYyOTA2OSwxMi45OTU4NDk1IDIuODQ2NzQ2MDMsMTIuOTk1ODQ5NSBaIi8%2BCiAgPC9nPgo8L3N2Zz4K "Rollup")](https://github.com/rollup/rollup/wiki/pkg.module "Rollup")##### Development Status
[![Travis](https://img.shields.io/travis/com/thebespokepixel/n-selector/develop?logo=travis "Travis")](https://travis-ci.com/thebespokepixel/n-selector "Travis") [![Libraries.io](https://img.shields.io/librariesio/github/TheBespokePixel/n-selector?\&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij4KICA8cGF0aCBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01Ljk5OTMxNDIyLDE1LjI3NyBMNiwyMyBDNiwyMy41NTIyODQ3IDUuNTUyMjg0NzUsMjQgNSwyNCBMMiwyNCBDMS40NDc3MTUyNSwyNCAxLDIzLjU1MjI4NDcgMSwyMyBMMC45OTkzMTQyMjIsMTkuMTg0IEw1Ljk5OTMxNDIyLDE1LjI3NyBaIE0xNC40OTkzMTQyLDguNjM2IEwxNC41LDIzIEMxNC41LDIzLjU1MjI4NDcgMTQuMDUyMjg0NywyNCAxMy41LDI0IEwxMC41LDI0IEM5Ljk0NzcxNTI1LDI0IDkuNSwyMy41NTIyODQ3IDkuNSwyMyBMOS40OTkzMTQyMiwxMi41NDMgTDE0LjQ5OTMxNDIsOC42MzYgWiBNMTcuOTk5MzE0Miw4LjMzNCBMMjIuOTk5MzE0MiwxMi4xMDIgTDIzLDIzIEMyMywyMy41NTIyODQ3IDIyLjU1MjI4NDcsMjQgMjIsMjQgTDE5LDI0IEMxOC40NDc3MTUzLDI0IDE4LDIzLjU1MjI4NDcgMTgsMjMgTDE3Ljk5OTMxNDIsOC4zMzQgWiBNNSwwIEM1LjU1MjI4NDc1LDAgNiwwLjQ0NzcxNTI1IDYsMSBMNS45OTkzMTQyMiwxMS40NzEgTDAuOTk5MzE0MjIyLDE1LjM3OCBMMSwxIEMxLDAuNDQ3NzE1MjUgMS40NDc3MTUyNSwwIDIsMCBMNSwwIFogTTEzLjUsMCBDMTQuMDUyMjg0NywwIDE0LjUsMC40NDc3MTUyNSAxNC41LDEgTDE0LjQ5OTMxNDIsNC44MzEgTDkuNDk5MzE0MjIsOC43MzcgTDkuNSwxIEM5LjUsMC40NDc3MTUyNSA5Ljk0NzcxNTI1LDAgMTAuNSwwIEwxMy41LDAgWiBNMjIsMCBDMjIuNTUyMjg0NywwIDIzLDAuNDQ3NzE1MjUgMjMsMSBMMjIuOTk5MzE0Miw4LjM0NyBMMTcuOTk5MzE0Miw0LjU3OSBMMTgsMSBDMTgsMC40NDc3MTUyNSAxOC40NDc3MTUzLDAgMTksMCBMMjIsMCBaIi8%2BCjwvc3ZnPgo%3D "Libraries.io")](https://libraries.io/github/thebespokepixel/n-selector "Libraries.io")
[![Snyk](https://snyk.io/test/github/thebespokepixel/n-selector/badge.svg "Snyk")](https://snyk.io/test/github/thebespokepixel/n-selector "Snyk") [![Code-Climate](https://api.codeclimate.com/v1/badges/396fea93d86cd697a911/maintainability "Code-Climate")](https://codeclimate.com/github/thebespokepixel/n-selector/maintainability "Code-Climate") [![Code-Climate Coverage](https://api.codeclimate.com/v1/badges/396fea93d86cd697a911/test_coverage "Code-Climate Coverage")](https://codeclimate.com/github/thebespokepixel/n-selector/test_coverage "Code-Climate Coverage")##### Documentation/Help
[![Inch.io](https://inch-ci.org/github/thebespokepixel/n-selector.svg?branch=master\&style=shields "Inch.io")](https://inch-ci.org/github/thebespokepixel/n-selector "Inch.io") [![Twitter](https://img.shields.io/twitter/follow/thebespokepixel?style=social "Twitter")](https://twitter.com/thebespokepixel "Twitter")
## Usage
Think of n-selector as an endlessly extendable multi-way n-gang switch.
Firstly, it allows the selection of a position by the position of an option in a primary index and then returns a value or an array of all the options that fall under that position.
Secondly, it allows selection by a simple scalar value (0.0 to 1.0) and can return a value or an array of the options at that position.
```
0.00 ... 0.25 ... 0.50 ... 0.75 ... 1.00
|--------|--------|--------|--------|
Primary | One | Two | Three |
Gang +1 | Red | Green | Blue |
Gang +2 | One | Two |select('one') - returns ['One', 'Red', 'One']
select(2) - returns ['Two', 'Green', 'One']
position(0.75) - returns ['Three', 'Blue', 'Two']
```#### Installation
```shell
npm install --save @thebespokepixel/n-selector
```#### Examples
```javascript
import {createSelector} from '@thebespokepixel/n-selector'const matrix = createSelector(['one', 'two', 'three'], 0)
matrix.select(0) - returns 'one'
matrix.position(0.5) - returns 'two'
```## Documentation
Full documentation can be found at [https://thebespokepixel.github.io/n-selector/][1][1]: https://thebespokepixel.github.io/n-selector/