§ 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 , on Sourcehut.
§ Licence
Copyright © 2010–2020 Roy Revelt and other contributors
Related packages:
📦 regex-is-jsp 1.1.1
Regular expression for detecting JSP (Java Server Pages) code
📦 regex-is-jinja-nunjucks 1.1.1
Regular expression for detecting Jinja or Nunjucks code
📦 stristri 2.0.0
Extracts or deletes HTML, CSS, text and/or templating tags from string
📦 html-crush 3.0.3
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 string-strip-html 7.0.3
Strips HTML tags from strings. No parser, accepts mixed sources
📦 detect-is-it-html-or-xhtml 3.11.0
Answers, is the string input string more an HTML or XHTML (or neither)