1.0.0 • Published 4 years ago

shamanld v1.0.0

Weekly downloads
12
License
-
Repository
-
Last release
4 years ago

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