all files / lib/ get-type.js

100% Statements 17/17
100% Branches 10/10
100% Functions 1/1
100% Lines 16/16
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   25×                   25×   25× 14× 14×     11× 64× 64× 64× 64×          
module.exports = getType
 
function getType (st) {
  var types = [
    'Directory',
    'File',
    'SymbolicLink',
    'Link', // special for hardlinks from tarballs
    'BlockDevice',
    'CharacterDevice',
    'FIFO',
    'Socket'
  ]
  var type
 
  if (st.type && types.indexOf(st.type) !== -1) {
    st[st.type] = true
    return st.type
  }
 
  for (var i = 0, l = types.length; i < l; i++) {
    type = types[i]
    var is = st[type] || st['is' + type]
    if (typeof is === 'function') is = is.call(st)
    if (is) {
      st[type] = true
      st.type = type
      return type
    }
  }
 
  return null
}