A tiny Node.js microservice to detect the language of a code snippet
Switch branches/tags
Nothing to show
Clone or download
mxstbr Merge pull request #17 from withspectrum/depfu/update/yarn/flow-bin-0…
….88.0

Update flow-bin: 0.87.0 → 0.88.0 (major)
Latest commit fdaf09d Dec 13, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
flow-typed/npm Initial commit Oct 22, 2017
src Initial commit Oct 22, 2017
.babelrc Initial commit Oct 22, 2017
.flowconfig Initial commit Oct 22, 2017
.gitignore Initial commit Oct 22, 2017
.npmignore Initial commit Oct 22, 2017
.prettierrc Initial commit Oct 22, 2017
.travis.yml Run Flow in CI Nov 4, 2018
LICENSE.md Initial commit Oct 22, 2017
README.md Add note about language support Oct 22, 2017
package.json Update flow-bin to version 0.88.0 Dec 11, 2018
yarn.lock Update flow-bin to version 0.88.0 Dec 11, 2018

README.md

micro-code-analyser

A tiny microservice to detect the language of a code snippet.

By running this microservice you won't have to add megabytes of JavaScript to your frontend just to detect what language a user is writing code in. This is especially useful for syntax highlighting in rich text/WYSIWYG editing scenarios!

Note: Language detection is done via the lang-detector module. This means micro-code-analyser currently supports JavaScript, C, C++, Python, Java, HTML, CSS, Ruby, Go and PHP.

Deployment

Your own micro-code-analyser is one click away!

Deploy to now

You can also deploy with a single command from the terminal (assuming you have now installed):

now withspectrum/micro-code-analyser

Usage

To get the language of a code snippet POST the text to your micro-code-analyser instance. For example in JavaScript:

fetch('micro-code-analyser-asdf123.now.sh', {
  method: 'POST',
  body: 'const a = "b";',
}).then(res => {
  // The microservice will return a status of 400 for invalid
  // or undetected code snippets
  if (res.status < 200 || res.status > 400) return;

  return res.text();
}).then(language => {
  console.log(`The code was written in ${language}.`);
  // => "The code was written in JavaScript"
});

Development

git clone git@github.com:withspectrum/micro-code-analyser
cd micro-code-analyser
npm i
npm run dev

Updating

The master branch of this repository is what you will be deploying. To update to a new version with potential bugfixes, all you have to do is run the now command again and change the URL you call in your app! 👌

License

Licensed under the MIT License, Copyright ©️ 2017 Space Program Inc. See LICENSE.md for more information.