UNPKG

expression-language

Version:

Javascript implementation of symfony/expression-language

51 lines (50 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _explode = require("locutus/php/strings/explode"); var _strlen = require("locutus/php/strings/strlen"); var _strtolower = require("locutus/php/strings/strtolower"); var _strtoupper = require("locutus/php/strings/strtoupper"); var _substr = require("locutus/php/strings/substr"); var _strstr = require("locutus/php/strings/strstr"); var _stristr = require("locutus/php/strings/stristr"); var _implode = require("locutus/php/strings/implode"); var _count = require("locutus/php/array/count"); var _date = require("locutus/php/datetime/date"); var _strtotime = require("locutus/php/datetime/strtotime"); var _ArrayProvider = require("./Provider/ArrayProvider"); /** * Helpers referenced by javascript source produced by ExpressionLanguage#compile() * for the bundled StringProvider/ArrayProvider/DateProvider functions (e.g. * `strtolower`, `count`, `date`). Those functions wrap PHP-compatible * (locutus) implementations that don't exist as JavaScript globals, so * compiled output calls them as `__runtime.<name>(...)`. * * To execute compile() output that uses one of those functions, pass this * object into scope under the name `__runtime`, e.g.: * * const fn = new Function('__runtime', ...names, el.compile(expr, names)); * fn(compileRuntime, ...values); * * Expressions that only use core syntax (arithmetic, comparisons, in/not in, * .., custom self-contained functions registered via register()/addFunction()) * don't need this — it's only required when a provider function appears in * the expression being compiled. */ const compileRuntime = { strtolower: _strtolower.strtolower, strtoupper: _strtoupper.strtoupper, explode: _explode.explode, strlen: _strlen.strlen, strstr: _strstr.strstr, stristr: _stristr.stristr, substr: _substr.substr, implode: _implode.implode, count: _count.count, array_intersect: (...args) => _ArrayProvider.arrayIntersectFn.getEvaluator()(null, ...args), date: _date.date, strtotime: _strtotime.strtotime }; var _default = exports.default = compileRuntime;