Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flourite

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flourite

A library for detecting the programming language of a code snippet.

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Flourite - Language detector

npm npm bundle size GitHub Workflow Status Codecov LGTM Alerts

A fork of ts95/lang-detector, rewritten in Typescript with more language support.

Detects a programming language from a given string.

  • Built-in support for CommonJS and ESM format
  • Built-in Typescript typings
  • No external dependencies
  • 150 test cases and growing!

Detectable languages

Languages
CHTMLLuaRust
C++JavaPascalSQL
C#JavascriptPHPYAML
CSSJuliaPython
GoKotlinRuby

Install

$ npm install flourite

or via a CDN (unpkg or jsdelivr)

<script src="https://unpkg.com/flourite@1.1.2"></script>
<script src="https://cdn.jsdelivr.net/npm/flourite@1.1.2/dist/index.iife.js"></script>

Usage

import flourite from 'flourite';

const code = flourite('console.log("Hello World");'); // => Javascript

You could supply options to make see numbers of points for a certain language:

import flourite from 'flourite';

const code = flourite('printf("Hello World")', { statistics: true });

// code.detected = 'C'
// code.statistics = {
//   C: 5,
//   'C++': 0,
//   'C#': 0,
//   CSS: 0,
//   Go: 0,
//   HTML: 0,
//   Java: 0,
//   Javascript: 0,
//   Julia: 0,
//   Kotlin: 0,
//   Lua: -20,
//   Pascal: 0,
//   PHP: 0,
//   Python: 0,
//   Ruby: 0,
//   Rust: 0,
//   SQL: 0,
//   Unknown: 1,
//   YAML: 0
// }

Or if you want to integrate it with Shiki, you could pass:

const code = flourite('Console.WriteLine("Hello world!");', { shiki: true }); // => csharp

If you want to handle Unknown value, you could pass:

const code = flourite("SELECT 'Hello world!' text FROM dual;", { noUnknown: true });

With Typescript

import flourite from 'flourite';
import type { Options, StatisticOutput } from 'flourite';

const flouriteOptions: Options = {
  heuristic: true,
  statistics: true,
};

const code = flourite('print!({:?}, &v);', flouriteOptions) as StatisticOutput;

Available Options

KeyTypeDefaultDescription
heuristicbooleantrueChecks for codes on the top of the given input. Only checks when the lines of code is above 500.
statisticsbooleanfalseIf true, will return the statistics of all the guessed language.
shikibooleanfalseStraightforward compatibility with Shiki's language specification type
noUnknownbooleanfalseIf true, will not output Unknown on detected and statistics result

I'm here for Hacktoberfest, what can I do?

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.

Have fun!

Contributing

  • Use the Node.js version as defined on the .nvmrc file.
  • Run npm run test:tdd to initiate a test driven development environment.
  • Run npm run lint and npm run format before commit a change.

For more details and explanation on how things work, see CONTRIBUTING

License

MIT

Keywords

FAQs

Package last updated on 02 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc