npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flourite

v1.3.0

Published

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

Downloads

3,614

Readme

Flourite - Language detector

npm npm bundle size GitHub Workflow Status Codecov

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 | Typescript | | 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