Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
lang-detector
Advanced tools
A library for detecting the programming language of a code snippet.
A fast and small library for detecting the programming language of a code snippet. Can be used for strings of code spanning multiple thousand lines.
This library should only be used if you don't have anything else to go by to determine the language of the code, like a file extension.
npm install lang-detector --save
/**
* function detectLang(snippet, options) { ... }
*
* @snippet {String} The code snippet.
* @options {Object} (Optional) {
* heuristic: {Boolean} Enable heuristic optimisation for better performance. `true` by default.
* statistics: {Boolean} Return statistics. `false` by default.
* }
* @return {String} (Name of the detected language) or {Object} (Statistics).
*/
var detectLang = require('lang-detector');
detectLang('List<String> things = new ArrayList<>();')
// => 'Java'
detectLang('console.log("Hello world");')
// => 'JavaScript'
detectLang('Hello world.', { statistics: true })
/* => {
"detected": "Unknown",
"statistics": {
"JavaScript": 0,
"C": 0,
"C++": 0,
"Python": 0,
...
"Unknown": 1
}
}
*/
Run npm test
in the root of the directory to run the tests.
FAQs
A library for detecting the programming language of a code snippet.
The npm package lang-detector receives a total of 454 weekly downloads. As such, lang-detector popularity was classified as not popular.
We found that lang-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.