
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
code-block-language-detector
Advanced tools
A lightweight Node.js package to detect the programming language of a given code snippet. Built on top of highlight.js, it supports a wide range of programming languages.
Install the package via npm:
npm install code-block-language-detector
Detect the programming language of a given code snippet:
const detectLanguage = require("code-block-language-detector");
const code = `const x = 42; console.log(x);`;
const language = detectLanguage(code);
console.log(language); // Output: 'javascript'
const detectLanguage = require("code-block-language-detector");
const code = `SELECT * FROM users WHERE age > 21;`;
const language = detectLanguage(code, ["sql", "javascript", "python"]);
console.log(language); // Output: 'sql'
If the provided code snippet is invalid or detection fails, the function returns "unknown":
const code = `+++---===`;
const language = detectLanguage(code);
console.log(language); // Output: 'unknown'
The following languages are currently supported:
FAQs
Detects the programming language of code snippets
We found that code-block-language-detector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.