
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
A fork of ts95/lang-detector, rewritten in Typescript with more language support.
Detects a programming language from a given string.
Languages | ||||
---|---|---|---|---|
C | Dockerfile | Javascript | Pascal | SQL |
C++ | Elixir | Julia | PHP | YAML |
C# | Go | Kotlin | Python | Typescript |
Clojure | HTML | Lua | Ruby | |
CSS | Java | Markdown | Rust |
$ npm install flourite
or via a CDN (unpkg or jsdelivr)
<script src="https://unpkg.com/flourite@1.3.0"></script>
<script src="https://cdn.jsdelivr.net/npm/flourite@1.3.0/dist/index.iife.js"></script>
import flourite from 'flourite';
const code = flourite('cout << "Hello world" << endl;');
// {
// language: 'C++',
// statistics: {
// C: 0,
// Clojure: 0,
// 'C++': 5,
// CSS: 0,
// 'C#': 0,
// Dockerfile: 0,
// Elixir: 0,
// Go: 0,
// HTML: 0,
// Java: 0,
// Javascript: 0,
// Julia: 2,
// Kotlin: 0,
// Lua: 2,
// Markdown: 0,
// Pascal: 0,
// PHP: 0,
// Python: 0,
// Ruby: 0,
// Rust: 0,
// SQL: 0,
// Unknown: 1,
// YAML: 0,
// },
// linesOfCode: 1
// }
Or if you want to integrate it with Shiki, you could pass:
flourite('Console.WriteLine("Hello world!");', { shiki: true }).language;
// => csharp
flourite('fn partition<T,F>(v: &mut [T], f: &F) -> usize ', { shiki: true }).language;
// => rust
If you want to handle Unknown
value, you could pass:
const code = flourite("SELECT 'Hello world!' text FROM dual;", { noUnknown: true });
import flourite from 'flourite';
import type { Options } from 'flourite';
const flouriteOptions: Options = {
heuristic: true,
};
const code = flourite('print!({:?}, &v);', flouriteOptions);
Key | Type | Default | Description |
---|---|---|---|
heuristic | boolean | true | Checks for codes on the top of the given input. Only checks when the lines of code is above 500. |
shiki | boolean | false | Straightforward compatibility with Shiki's language specification type |
noUnknown | boolean | false | If true , will not output Unknown on detected and statistics result |
If you're new to open source, we really recommend reading a few articles about contributing to open source projects:
Then you can start by reading our contribution part and guidelines.
Two things that you can do for sure: Create a new language support and improve the regular expression performance on current supported languages.
Have fun!
.nvmrc
file.npm run test:tdd
to initiate a test driven development environment.npm run lint
and npm run format
before commit a change.For more details and explanation on how things work, see CONTRIBUTING
FAQs
A library for detecting the programming language of a code snippet.
The npm package flourite receives a total of 3,725 weekly downloads. As such, flourite popularity was classified as popular.
We found that flourite 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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.