# lang-detector

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

Latest version **1.0.6** (published 2015-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install lang-detector
pnpm add lang-detector
yarn add lang-detector
bun add lang-detector
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2015-04-03 |
| First published | 2015-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Author | Toni Sučić |
| Maintainers | ts95 |
| Keywords | programming, language, detection, detector, code, classify, classifier, identify, identifier |

## Links

- npm: https://www.npmjs.com/package/lang-detector
- Repository: https://github.com/ts95/lang-detector
- Issues: https://github.com/ts95/lang-detector/issues
- npm.io page: https://npm.io/package/lang-detector

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) ^1.8.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2015-04-03
- 1.0.5 — 2015-04-02
- 1.0.4 — 2015-04-01
- 1.0.3 — 2015-04-01
- 1.0.2 — 2015-04-01
- 1.0.1 — 2015-04-01
- 1.0.0 — 2015-03-31
- 0.2.0 — 2015-03-31
- 0.1.9 — 2015-03-30
- 0.1.8 — 2015-03-30
- 0.1.7 — 2015-03-30
- 0.1.6 — 2015-03-30
- 0.1.5 — 2015-03-30
- 0.1.4 — 2015-03-30
- 0.1.3 — 2015-03-29
- … 9 more at https://npm.io/package/lang-detector/versions

## README

lang-detector
=====
[![NPM](https://nodei.co/npm/lang-detector.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/lang-detector/)

A fast and small library for detecting the programming language of a code snippet. 
Can be used for strings of code spanning multiple thousand lines.

This library should only be used if you don't have anything else to go by to determine the language of the code, like a file extension.

## Detectable languages
* JavaScript
* C
* C++
* Python
* Java
* HTML
* CSS
* Ruby
* Go
* PHP

## Install
```Shell
npm install lang-detector --save
```

## Usage
```JavaScript
/**
 * function detectLang(snippet, options) { ... }
 *
 * @snippet {String} The code snippet.
 * @options {Object} (Optional) {
 *   heuristic: {Boolean} Enable heuristic optimisation for better performance. `true` by default.
 *   statistics: {Boolean} Return statistics. `false` by default.
 * }
 * @return {String} (Name of the detected language) or {Object} (Statistics).
 */
var detectLang = require('lang-detector');

detectLang('List<String> things = new ArrayList<>();')
    // =>    'Java'
detectLang('console.log("Hello world");')
    // =>    'JavaScript'
detectLang('Hello world.', { statistics: true })
    /* =>   {
                "detected": "Unknown",
                "statistics": {
                    "JavaScript": 0,
                    "C": 0,
                    "C++": 0,
                    "Python": 0,
                     ...
                    "Unknown": 1
                }
            } 
     */
```

## Unit tests
Run `npm test` in the root of the directory to run the tests.

## License
<a href="https://tldrlegal.com/license/mit-license" target="_blank">MIT</a> © <a href="https://github.com/ts95/" target="_blank">Toni Sučić</a>

---
_Source: https://npm.io/package/lang-detector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
