detector.js 427 B

123456789101112131415161718192021
  1. 'use strict';
  2. var typeMap = {};
  3. var types = require('./types');
  4. types.forEach(function(type) {
  5. typeMap[type] = require('./types/' + type).detect;
  6. });
  7. module.exports = function(buffer, filepath) {
  8. var type, result;
  9. for (type in typeMap) {
  10. if (type in typeMap) {
  11. result = typeMap[type](buffer, filepath);
  12. if (result) {
  13. return type;
  14. }
  15. }
  16. }
  17. throw new TypeError('Unsupported type');
  18. };