Language Detect
Detect the programming language of any file by checking the file name, file extension, file shebang and falling back to a programming language classifier. For more language information, it should be used in conjunction with language-map.
Installation
npm install language-detect --save
Usage
var detect = require('language-detect');
Asynchronously From a File
detect(__dirname + '/test.js', function (err, language) {
console.log(err);
console.log(language);
});
Synchronously From a File
detect.sync(__dirname + '/test.js');
From The Filename and Contents
detect.contents(__dirname + '/test.js', 'var test = true;\n');
From Only a Filename
detect.filename(__dirname + '/test.js');
Check for Shebang
detect.shebang('#!/usr/bin/env node\n...');
Run Classification
Uses language-classifier which can only detect a small subset of languages.
detect.classify('.test { color: red; }')
Other Properties
- detect.aliases A map of known aliases
- detect.interpreters A map of known interpreters
- detect.extensions A map of known file extensions
- detect.filenames A map of known file names
License
MIT