All files / src/util util.coffee

88.89% Statements 16/18
75% Branches 6/8
92.31% Functions 12/13
94.12% Lines 16/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 511x   1x             1x 2x   1x     1x           1x             1x 1x   11796x 11796x 11796x   326x 11470x     1x       1x              
module.exports.removeNulls = (things) -> things.filter (x) -> x?
 
module.exports.numerical_sort = (things, direction="asc") ->
  things.sort (a,b)->
    if direction is "asc"
      a - b
    else
      b - a
 
module.exports.isNull = (value) ->
  return value==null
  
module.exports.typeIsArray  = typeIsArray  = Array.isArray || ( value ) ->
  return {}.toString.call( value ) is '[object Array]'
 
module.exports.allTrue = (things) ->
  if typeIsArray things
    things.every (x) -> x
  else
    things
 
module.exports.anyTrue = (things) ->
  if typeIsArray things
    things.some (x) -> x
  else
    things
 
#The export below is to make it easier if js Date is overwritten with CQL Date
module.exports.jsDate = Date
module.exports.normalizeMillisecondsFieldInString = normalizeMillisecondsFieldInString = (string, msString) ->
  # TODO: verify we are only removing numeral digits
  msString = normalizeMillisecondsField(msString)
  [beforeMs, msAndAfter] = string.split('.')
  timezoneSeparator = getTimezoneSeparatorFromString(msAndAfter)
 
  timezoneField = msAndAfter?.split(timezoneSeparator)[1] if !!timezoneSeparator
  timezoneField = '' if !timezoneField?
  string = beforeMs + '.' + msString + timezoneSeparator + timezoneField
 
module.exports.normalizeMillisecondsField = normalizeMillisecondsField = (msString) ->
  # fix up milliseconds by padding zeros and/or truncating (5 --> 500, 50 --> 500, 54321 --> 543, etc.)
  msString = (msString + "00").substring(0, 3)
 
module.exports.getTimezoneSeparatorFromString = getTimezoneSeparatorFromString = (string) ->
  if string?.match(/-/)?.length == 1
    timezoneSeparator = '-'
  else if string?.match(/\+/)?.length == 1
    timezoneSeparator = '+'
  else
    timezoneSeparator = ''