shamanld

1.0.0 • Public • Published

GitHub license Build Status npm version

ShamanJS

Programming Language Detector implemented in JavaScript. Based on the repository shaman, which is written in Python.

Languages supported: ASP, Bash, C, C#, CSS, HTML, Java, JavaScript, Objective-c, PHP, Python, Ruby, SQL, Swift, and XML.

Pre-trained model is included in this library, where the size of the model is 617KB. The accuracy of the model is 78%, where the model is trained with 120K codes and tested with 40K codes.

Note that the included model consists of many raw texts, so enabling compression (e.g., gzip) on the CDN when serving the JS file greatly affects the time and cost to download the file.

See demo on RunKit.

Getting Started

Installation

In a browser:

<script src="dist/shaman.js"></script>

Using npm:

$ npm i --save shamanld

How to use

const code = `
#include <stdio.h>
int main() {
	printf("Hello world");
}`;

const r = Shaman.detect(code);
// r = [['c', 44.28, 'java', 6.3, ...]]

const detectedLanguage = r[0][0];
assert(detectedLanguage == 'c');

Readme

Keywords

none

Package Sidebar

Install

npm i shamanld

Weekly Downloads

2

Version

1.0.0

License

none

Unpacked Size

1.25 MB

Total Files

10

Last publish

Collaborators

  • prevdev