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: 2 months 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 (about 2 years ago)
- Last Synced: 2025-03-07T22:02:08.216Z (3 months ago)
- Topics: enumerator, node-module, npm, proportional
- Language: JavaScript
- Size: 23.5 MB
- Stars: 1
- Watchers: 1
- 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
[](https://www.npmjs.com/package/@thebespokepixel/n-selector "npm") [](https://libraries.io/github/thebespokepixel/n-selector "Libraries.io")
[](https://travis-ci.com/thebespokepixel/n-selector "Travis") [](https://github.com/rollup/rollup/wiki/pkg.module "Rollup")##### Development Status
[](https://travis-ci.com/thebespokepixel/n-selector "Travis") [](https://libraries.io/github/thebespokepixel/n-selector "Libraries.io")
[](https://snyk.io/test/github/thebespokepixel/n-selector "Snyk") [](https://codeclimate.com/github/thebespokepixel/n-selector/maintainability "Code-Climate") [](https://codeclimate.com/github/thebespokepixel/n-selector/test_coverage "Code-Climate Coverage")##### Documentation/Help
[](https://inch-ci.org/github/thebespokepixel/n-selector "Inch.io") [](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/