Code coverage report for lib/word.js

Statements: 21.95% (9 / 41)      Branches: 0% (0 / 22)      Functions: 0% (0 / 4)      Lines: 23.68% (9 / 38)      Ignored: none     

All files » lib/ » word.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  1   1 1 1 1   1                             1                             1                               1        
//var word = /[^\s.\(\){}\[\]]+/g
var word = /\w+/g
 
exports.prev = prev
exports.next = next
exports.current = current
exports.wordEnd = wordEnd
 
function prev(string, i, r) {
  r = r || word
  r.lastIndex = 0
  r.global = true
 
  var _m = null, m = null
  do { 
    _m = m
    m = r.exec(string)
  } while (m && m.index < i);
 
  if(!m || m.index >= i) return _m
  return m
}
 
function next (string, i, r) {
  r = r || word
  r.lastIndex = i
  r.global = true
 
  var _m = null, m = null
  do {
    m = r.exec(string)
    if(!m) return _m
    _m = m
  } while (m && m.index > i);
 
  return r.exec(string)
}
 
function current (string, i, r) {
  r = r || word
  r.lastIndex = i
  r.global = true
  var m
  do {
    m = r.exec(string)
    if(!m) return null
    //take the first match ends after this position.
    //console.error(m, i, '<', m.index + m[0].length)
    if(i < m.index + m[0].length)
      return m
  } while (m);
 
}
 
function wordEnd (string, i, r) {
  var m = current(string, i, r)
  return m && m.index + m[0].length
}