Installation
1. Install the latest version with yarn:
yarn add regex-is-jinja-nunjucks
or with npm:
npm install regex-is-jinja-nunjucks
2. Import it in your code:
Quick Take
import { strict as assert } from "assert";
import { isJinjaNunjucksRegex } from "regex-is-jinja-nunjucks";
// detects Jinja/Nunjucks code
assert.equal(
isJinjaNunjucksRegex().test(
`<div>{% if data.purchases.count > 1 %}these{% else %}this{% endif %}</div>`
),
true
);
// in case if it's not nunjucks
assert.equal(isJinjaNunjucksRegex().test(`<div>tralala</div>`), false);
API — isJinjaNunjucksRegex()
The main function isJinjaNunjucksRegex()
is imported like this:
import { isJinjaNunjucksRegex } from "regex-is-jinja-nunjucks";
It’s a function which returns a RegExp object, /.../g
, which you can use everywhere, for example, in RegExp.prototype.exec()
or String.prototype.match()
.
API — version
You can import version
:
import { version } from "regex-is-jinja-nunjucks";
console.log(version);
// => "4.0.3"