detect-templating-language2.1.0

Detects various templating languages present in string

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