selection-key
v0.0.1
Published
Convert an array of integers into a short, unique, URL-friendly key, and back again.
Downloads
4
Readme
selection-key
Convert an array of integers into a short (ish), unique, URL-friendly key, and back again.
Useful if you need a key to represent a unique selection from a set of items – make an array containing only the integer IDs of the selected items, and then get a unique reversable string representing that set.
Usage
var selectionKey = require('selection-key');
var maxId = 100;
var selectedItems = [5, 6, 20, 24, 25, 47, 48, 51, 55, 60, 61, 77, 88, 90, 91, 92, 96];
var key = selectionKey(selectedItems, maxId); // 'O02C000P40.40BY00000'
var parsed = selectionKey.parse(key, maxId); // array of original items (sorted)
Licence
MIT