cueing ►►|
Cue, seek, or cycle items in JavaScript in node or the browser
npm
npm install cueing --save
Basic usage
var cueing = var letters = // cue the last index and then read from thereletters // => lettersletters // => 'c'letters // => 'a' // manually move the needleletters // seek backwardsletters // => 'c' // seeking (or cueing) will loop aroundletters // => 'b'
API
cueing(pool=[])
- Get a new
cueing
instance pool
:number|{length:number}
length or array(-like) of values- →
cueing
instance
cueing()
instances are array-like and inherit array methods
var tracks = tracks // '1.mp3,2.mp3,3.mp3'tracks instanceof cueing // truetracks instanceof Array // trueArray // false // true
cueing()
objects coerce to their needle position
var cueing = var list = +list // 0 // truelist // move the needle to a new index2 == list // true+list // 2Stringlist // '2'listlist // 'c'
cueing()
methods
.needle(index?)
- Manually move the needle to
index
index
:number|cueing
destination index- →
this
.cue(offset=0)
- Move the needle by
offset
offset
:number|cueing
+/- integer to move the needle by- →
this
.seek(offset=0)
.cue
the offset and get the value thereoffset
:number|cueing
+/- integer to move the needle by- →
*
.store()
- Store the current needle position for recalling later
- →
this
.recall(index?)
- Recall stored cue point(s)
index
:number|cueing
+/- index to read.0
reads the oldest point.-1
reads the newest.- →
cueing
instance at recalled state
.clear()
- Clear stored cue points
- →
this
.clone()
- Clone (copy) a
cueing
instance at its current state to a new instance - →
cueing
clone
Static methods
cueing.cue(pool, start=0, offset=0)
- Get the
pool
index that isoffset
away fromstart
- →
number
cueing // => 2cueing // => 2
cueing.seek(pool, start=0, offset=0)
- Get the
pool
value that isoffset
away fromstart
- →
*
cueing // => 'a'cueing // => 'b'
cueing.store(array, point)
- Push
point
ontoarray
if different from last point - →
array
reference
cueing // => [1, 5, 3]cueing // => [1, 5]cueing // => [1, 5, 1]