Giter Club home page Giter Club logo

flourite's Introduction

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
  • 200 test cases and growing!

Detectable languages

Languages
C Dockerfile Javascript Pascal SQL
C++ Elixir Julia PHP YAML
C# Go Kotlin Python
Clojure HTML Lua Ruby
CSS Java Markdown Rust

Install

$ npm install flourite

or via a CDN (unpkg or jsdelivr)

<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.iife.js"></script>

Usage

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 });

With Typescript

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

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

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

Available Options

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

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.

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!

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

flourite's People

Contributors

aldy505 avatar elianiva avatar farhan443 avatar hosein2398 avatar ryuhojin avatar semla avatar ts95 avatar vinmaster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.