@rhinostone/swig-core 2.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/filters.js ADDED
@@ -0,0 +1,43 @@
1
+ var utils = require('./utils');
2
+
3
+ /**
4
+ * Filter infrastructure shared across @rhinostone/swig-family frontends.
5
+ *
6
+ * Phase 1 carve — `iterateFilter` and the `.safe` flag convention live
7
+ * here so every flavor's filter catalog (native Swig, Twig, Jinja2,
8
+ * Django) picks up identical recursion + autoescape-bypass semantics.
9
+ * Filter catalogs themselves stay per-flavor. See
10
+ * .claude/architecture/multi-flavor-ir.md.
11
+ */
12
+
13
+ /**
14
+ * Recursively run a filter across an object/array and apply it to all
15
+ * of the object/array's values. Used by the built-in filter catalog so
16
+ * that e.g. `{{ arr|upper }}` upper-cases every string element.
17
+ *
18
+ * Call sites invoke this with `this` bound to the filter function via
19
+ * `iterateFilter.apply(exports.myFilter, arguments)`. Returning
20
+ * `undefined` signals "input is scalar — caller should handle it".
21
+ *
22
+ * @param {*} input
23
+ * @return {*}
24
+ */
25
+ exports.iterateFilter = function iterateFilter(input) {
26
+ var self = this,
27
+ out = {};
28
+
29
+ if (utils.isArray(input)) {
30
+ return utils.map(input, function (value) {
31
+ return self.apply(null, arguments);
32
+ });
33
+ }
34
+
35
+ if (typeof input === 'object') {
36
+ utils.each(input, function (value, key) {
37
+ out[key] = self.apply(null, arguments);
38
+ });
39
+ return out;
40
+ }
41
+
42
+ return;
43
+ };
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @rhinostone/swig-core — shared IR, backend, and runtime for the swig
3
+ * family of template engines.
4
+ *
5
+ * Phase 1 scaffold. Subsequent commits move security guards, loader
6
+ * contract, filter infra, cache, and the JS-codegen backend in from
7
+ * @rhinostone/swig. See .claude/architecture/multi-flavor-ir.md for
8
+ * the full design.
9
+ */
10
+
11
+ exports.utils = require('./utils');
12
+ exports.security = require('./security');
13
+ exports.ir = require('./ir');
14
+ exports.tokentypes = require('./tokentypes');
15
+ exports.tokenparser = require('./tokenparser');
16
+ exports.loaders = require('./loaders');
17
+ exports.filters = require('./filters');
18
+ exports.dateformatter = require('./dateformatter');
19
+ exports.backend = require('./backend');
20
+ exports.cache = require('./cache');
21
+ exports.engine = require('./engine');