§ Quick Take

import { strict as assert } from "assert";
import { detectLang } from "detect-templating-language";

// detects Nunjucks
assert.deepEqual(
  detectLang(
    `<div>{% if something %}x{% else %}y{% endif %}</div>`
  ),
  { name: "Nunjucks" }
);

// detects JSP (Java Server Pages)
assert.deepEqual(
  detectLang(
    `<div><c:set var="someList" value="\${jspProp.someList}" /></div>`
  ),
  { name: "JSP" }
);

§ Supported templating languages:

  • Nunjucks/Jinja/Liquid family
  • JSP (Java Server Pages)

§ API

detectLang(str)

In other words, it's a function which takes a string and returns a plain object.

§ API - Output

A plain object is returned, for example,

{ 
name: "Nunjucks"
}

If templating language is not detected, null is set:

{ 
name: null
}

§ Changelog

See it in the monorepo opens in a new tab, on GitHub.

§ Contributing

To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.

§ Licence

MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 regex-is-jsp 2.0.6
Regular expression for detecting JSP (Java Server Pages) code
📦 regex-is-jinja-nunjucks 2.0.6
Regular expression for detecting Jinja or Nunjucks code
📦 stristri 3.0.6
Extracts or deletes HTML, CSS, text and/or templating tags from string
📦 emlint 4.2.0
Pluggable email template code linter
📦 html-crush 4.1.0
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 string-strip-html 8.2.3
Strips HTML tags from strings. No parser, accepts mixed sources
📦 detect-is-it-html-or-xhtml 4.0.6
Answers, is the string input string more an HTML or XHTML (or neither)