mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-01 15:58:19 -04:00
Clean types.
This commit is contained in:
parent
a8c6a78a9a
commit
20cb199cbd
143 changed files with 451 additions and 757 deletions
|
@ -2,25 +2,20 @@
|
|||
modulejs.define('core/types', ['config', '_'], function (config, _) {
|
||||
|
||||
var reEndsWithSlash = /\/$/,
|
||||
reStartsWithDot = /^\./,
|
||||
regexps = {},
|
||||
|
||||
fileExts = {},
|
||||
fileNames = {},
|
||||
escapeRegExp = function (sequence) {
|
||||
|
||||
return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, "\\$&");
|
||||
// return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
},
|
||||
|
||||
parse = function (types) {
|
||||
|
||||
_.each(types, function (matches, type) {
|
||||
_.each(types, function (patterns, type) {
|
||||
|
||||
_.each(matches, function (match) {
|
||||
|
||||
match = match.toLowerCase();
|
||||
|
||||
if (reStartsWithDot.test(match)) {
|
||||
fileExts[match] = type;
|
||||
} else {
|
||||
fileNames[match] = type;
|
||||
}
|
||||
});
|
||||
var pattern = '^' + _.map(patterns, function (p) { return escapeRegExp(p).replace(/\*/g, '.*'); }).join('|') + '$';
|
||||
regexps[type] = new RegExp(pattern, 'i');
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -30,14 +25,18 @@ modulejs.define('core/types', ['config', '_'], function (config, _) {
|
|||
return 'folder';
|
||||
}
|
||||
|
||||
sequence = sequence.toLowerCase();
|
||||
|
||||
var slashidx = sequence.lastIndexOf('/'),
|
||||
name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence,
|
||||
dotidx = sequence.lastIndexOf('.'),
|
||||
ext = dotidx >= 0 ? sequence.substr(dotidx) : sequence;
|
||||
name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence;
|
||||
|
||||
return fileNames[name] || fileExts[ext] || 'unknown';
|
||||
for (var type in regexps) {
|
||||
if (regexps.hasOwnProperty(type)) {
|
||||
if (regexps[type].test(name)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'file';
|
||||
};
|
||||
|
||||
parse(_.extend({}, config.types));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue