comment-extractor
Version:
Extracts comments from source files with a not regex-based parser. Various languages supported.
49 lines • 1.71 kB
JavaScript
/*
* (c) Stephen Berquet <stephen.berquet@gmail.com>
*
* Licensed under the MIT License. See the LICENSE file in
* the project root for license information.
*/
;
var path = require("path");
var FileExtensionMatcher = (function () {
function FileExtensionMatcher() {
this.userDefinedAssociations = {};
this.defaultAssociations = {
css: 'css',
htm: 'html',
html: 'html',
js: 'javascript',
json: 'json',
ts: 'typescript',
php: 'php',
phtml: 'php',
php3: 'php',
php5: 'php',
xml: 'xml',
};
}
FileExtensionMatcher.prototype.getLanguageFromFileExtension = function (fileExtension) {
if (this.userDefinedAssociations[fileExtension]) {
return this.userDefinedAssociations[fileExtension];
}
else if (this.defaultAssociations[fileExtension]) {
return this.defaultAssociations[fileExtension];
}
return null;
};
FileExtensionMatcher.prototype.getLanguageFromFilePath = function (filePath) {
var fileExtension = path.extname(filePath);
if (!fileExtension || fileExtension.length < 2) {
return null;
}
fileExtension = fileExtension.substr(1);
return this.getLanguageFromFileExtension(fileExtension);
};
FileExtensionMatcher.prototype.addAssociation = function (fileExtension, languageName) {
this.userDefinedAssociations[fileExtension] = languageName;
};
return FileExtensionMatcher;
}());
exports.FileExtensionMatcher = FileExtensionMatcher;
//# sourceMappingURL=file-extension-matcher.js.map