get-type.js 610 B

123456789101112131415161718192021222324252627282930313233
  1. module.exports = getType
  2. function getType (st) {
  3. var types = [
  4. 'Directory',
  5. 'File',
  6. 'SymbolicLink',
  7. 'Link', // special for hardlinks from tarballs
  8. 'BlockDevice',
  9. 'CharacterDevice',
  10. 'FIFO',
  11. 'Socket'
  12. ]
  13. var type
  14. if (st.type && types.indexOf(st.type) !== -1) {
  15. st[st.type] = true
  16. return st.type
  17. }
  18. for (var i = 0, l = types.length; i < l; i++) {
  19. type = types[i]
  20. var is = st[type] || st['is' + type]
  21. if (typeof is === 'function') is = is.call(st)
  22. if (is) {
  23. st[type] = true
  24. st.type = type
  25. return type
  26. }
  27. }
  28. return null
  29. }