Cue, seek, or cycle items in JavaScript in node or the browser
npm install cueing --save
var cueing = require('cueing')
var letters = cueing(['a', 'b', 'c'])
// cue the last index and then read from there
letters.cue(-1) // => letters
letters.seek(0) // => 'c'
letters.seek(1) // => 'a'
// manually move the needle
letters.needle(0)
// seek backwards
letters.seek(-1) // => 'c'
// seeking (or cueing) will loop around
letters.seek(-4) // => 'b'- Get a new
cueinginstance pool:number|{length:number}length or array(-like) of values- →
cueinginstance
var tracks = cueing(['1.mp3', '2.mp3', '3.mp3'])
tracks.join() // '1.mp3,2.mp3,3.mp3'
tracks instanceof cueing // true
tracks instanceof Array // true
Array.isArray(tracks) // false
cueing(3).every(function(v, i, range) {
// Cueing objects are made dense for use with array iterators
return undefined === v && i in range && range instanceof cueing
}) // truevar cueing = require('cueing')
var list = cueing(['a', 'b', 'c'])
+list // 0
isFinite(list) // true
list.needle(2) // move the needle to a new index
2 == list // true
+list // 2
String(list) // '2'
list[list] // 'c'- Manually move the needle to
index index:number|cueingdestination index- →
this
- Move the needle by
offset offset:number|cueing+/- integer to move the needle by- →
this
.cuethe offset and get the value thereoffset:number|cueing+/- integer to move the needle by- →
*
- Store the current needle position for recalling later
- →
this
- Recall stored cue point(s)
index:number|cueing+/- index to read.0reads the oldest point.-1reads the newest.- →
cueinginstance at recalled state
- Clear stored cue points
- →
this
- Clone (copy) a
cueinginstance at its current state to a new instance - →
cueingclone
- Get the
poolindex that isoffsetaway fromstart - →
number
cueing.cue(['a', 'b', 'c'], -1) // => 2
cueing.cue(['a', 'b', 'c'], 1, -2) // => 2- Get the
poolvalue that isoffsetaway fromstart - →
*
cueing.seek(['a', 'b', 'c'], 1, -1) // => 'a'
cueing.seek(['a', 'b', 'c'], 0, 5) // => 'b'- Push
pointontoarrayif different from last point - →
arrayreference
cueing.store([1, 5], 3) // => [1, 5, 3]
cueing.store([1, 5], 5) // => [1, 5]
cueing.store([1, 5], 1) // => [1, 5, 1]