Socket
Socket
Sign inDemoInstall

jet-engine

Package Overview
Dependencies
331
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

dist/index.js.map

12

__tests__/index.test.js

@@ -1,5 +0,15 @@

import { render, register } from '../src';
import { compress, loader, render, register } from '../src';
import { registerPlugin } from '../src/library';
describe('Jet Engine', () => {
describe('compress', function () {
it('should remove comments', function () {
expect(compress('{*a short comment*}Hello')).toEqual('Hello');
});
it('should load a template', function () {
expect(loader('This is a {* short *}test')).toEqual('module.exports = "This is a test";');
});
});
it('should handle {%TEXT} directive', () => {

@@ -6,0 +16,0 @@ const out = render(

453

dist/index.js

@@ -1,451 +0,2 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setFlag = setFlag;
exports.getFlag = getFlag;
exports.appendOut = appendOut;
exports.pushOutput = pushOutput;
exports.popOutput = popOutput;
exports.pushSpecial = pushSpecial;
exports.setSpecial = setSpecial;
exports.getSpecial = getSpecial;
exports.popSpecial = popSpecial;
exports.pushTemplate = pushTemplate;
exports.popTemplate = popTemplate;
exports.getTemplate = getTemplate;
exports.incPtr = incPtr;
exports.getPtr = getPtr;
exports.setPtr = setPtr;
exports.pushStack = pushStack;
exports.popStack = popStack;
exports.getAttributes = getAttributes;
exports.parseDirective = parseDirective;
exports.get = get;
exports.processUntil = processUntil;
exports.readUntil = readUntil;
exports.skipUntil = skipUntil;
exports.runUntil = runUntil;
exports.compress = compress;
exports.compile = compile;
exports.isSelfClosing = isSelfClosing;
exports.endTag = endTag;
exports.render = render;
exports.register = register;
exports.isRegistered = isRegistered;
exports.cleanup = cleanup;
var _library = require('./library');
require('./plugins');
var stack = [];
var registry = {};
var outputStack = [];
var templateStack = [];
var ptrStack = [];
var specialStack = [];
var flags = {};
var template = void 0;
function setFlag(flag, value) {
flags[flag] = value;
}
function getFlag(flag) {
return flags[flag];
}
function appendOut(s) {
outputStack[outputStack.length - 1] += s;
}
function pushOutput(s) {
outputStack.push(s);
}
function popOutput() {
return outputStack.pop();
}
function pushSpecial(o) {
specialStack.push(o);
}
function setSpecial(key, value) {
specialStack[specialStack.length - 1][key] = value;
}
function getSpecial(key) {
return specialStack[specialStack.length - 1][key];
}
function popSpecial() {
return specialStack.pop();
}
function pushTemplate(templ) {
templateStack.push(templ);
ptrStack.push(0);
template = templ;
}
function popTemplate() {
ptrStack.pop();
var lastTemplate = templateStack.pop();
if (templateStack.length > 0) {
template = templateStack[templateStack.length - 1];
}
return lastTemplate;
}
function getTemplate() {
// return templateStack[templateStack.length - 1];
return template;
}
function incPtr() {
var ptr = ptrStack[ptrStack.length - 1];
ptrStack[ptrStack.length - 1] = ptr + 1;
return ptr;
}
function getPtr() {
return ptrStack[ptrStack.length - 1];
}
function setPtr(ptr) {
ptrStack[ptrStack.length - 1] = ptr;
}
function pushStack(context) {
stack.push(context);
}
function popStack() {
return stack.pop();
}
function getAttributes(attr) {
var attributes = {};
var keys = Object.keys(attr);
var len = keys.length;
for (var i = 0; i < len; i++) {
var key = keys[i];
attributes[key] = get(attr[key]);
}
return attributes;
}
function parseDirective(chunkValue) {
var value = chunkValue;
if (value.slice(-1) === '/') {
value = value.slice(0, -1).trim();
}
var parts = [];
var attributes = {};
var isSpace = false;
var quote = null;
var part = '';
for (var i = 0; i < value.length; i++) {
var c = value.charAt(i);
if (c === '"' || c === "'") {
if (c === quote) {
quote = null;
} else if (!quote) {
quote = c;
}
}
if (c === ' ' && !quote) {
isSpace = true;
} else {
if (isSpace) {
parts.push(part);
part = '';
}
isSpace = false;
}
if (!isSpace) {
part += c;
}
}
parts.push(part);
for (var _i = 1; _i < parts.length; _i++) {
part = parts[_i];
var idx = part.indexOf('=');
attributes[part.slice(0, idx)] = part.slice(idx + 1);
}
return {
id: parts[0],
attributes: attributes
};
}
function closeQuote(id, quote, endQuote) {
var level = 0;
for (var i = 0; i < id.length; i++) {
var c = id.charAt(i);
switch (c) {
case quote:
level++;
break;
case endQuote:
level--;
if (level === 0) {
return i;
}
break;
default:
break;
}
}
return -1;
}
function getValue(id, o) {
if (o === undefined) {
return o;
}
var c = id.charAt(0);
switch (c) {
case '':
return o;
case "'":
case '"':
{
var endQuote = id.indexOf(c, 1);
if (endQuote === -1) {
throw new Error('Mismatched quote (' + c + ')');
}
return getValue(id.slice(endQuote + 1), id.slice(1, endQuote));
}
case '.':
return getValue(id.slice(1), o);
case '[':
{
var iClose = closeQuote(id, '[', ']');
if (iClose === -1) {
throw new Error('Mismatched brackets');
}
return getValue(id.slice(iClose + 1), o[get(id.slice(1, iClose))]);
}
default:
{
var iDot = id.indexOf('.');
var iOpen = id.indexOf('[');
if (iDot === -1 && iOpen === -1) {
return o[id];
}
if (iDot >= 0 && (iOpen === -1 || iOpen > iDot)) {
return getValue(id.slice(iDot), o[id.slice(0, iDot)]);
}
return getValue(id.slice(iOpen), o[id.slice(0, iOpen)]);
}
}
}
function get(id) {
if (!Number.isNaN(parseFloat(id))) {
return parseFloat(id);
}
if (id === '.') {
return stack[stack.length - 1];
}
if (id.charAt(0) === '$') {
return getSpecial(id);
}
for (var i = stack.length - 1; i >= 0; i--) {
var o = stack[i];
var value = getValue(id, o);
if (value !== undefined) {
return value;
}
if (id[0] === '.') {
return '';
}
}
return '';
}
function nextChunk() {
var ptr = incPtr();
var chunk = getTemplate()[ptr];
return chunk;
}
function handleValue(chunk) {
appendOut(get(chunk.value.slice(1, -1)));
}
function handleDirective(chunk) {
var key = chunk.id ? chunk.id[0] : '';
if ((0, _library.getPlugin)(key)) {
(0, _library.getPlugin)(key)(chunk);
} else {
handleValue(chunk);
}
}
function handleLiteral(chunk) {
appendOut(chunk.value);
}
function handleChunk() {
var chunk = nextChunk();
if (chunk.value.charAt(0) === '{') {
handleDirective(chunk);
} else {
handleLiteral(chunk);
}
return chunk;
}
function processUntil(directives, process) {
var list = Array.isArray(directives) ? directives : [directives];
var result = { returnVal: [] };
do {
result = process(result); // { chunk, returnVal }
} while (list.indexOf(result.chunk.value) === -1 && result.chunk.value !== '');
if (list.indexOf(result.chunk.value) === -1) {
throw new Error('Mismatched tag: ' + list[0]);
}
return result.returnVal;
}
function readUntil(directives) {
return processUntil(directives, function (result) {
result.chunk = nextChunk();
result.returnVal.push(result.chunk);
return result;
});
}
function skipUntil(directives) {
return processUntil(directives, function (result) {
result.chunk = nextChunk();
result.returnVal = result.chunk.value;
return result;
});
}
function runUntil(directives) {
return processUntil(directives, function (result) {
result.chunk = handleChunk();
result.returnVal = result.chunk.value;
return result;
});
}
function compress(s) {
var isText = s.slice(0, 7) === '{%TEXT}';
var isHTML = s.slice(0, 7) === '{%HTML}';
if (!isHTML && s.charAt(0) !== '<') {
return isText ? s.slice(7) : s;
}
return (isHTML ? s.slice(7) : s).replace(/\n\s*/g, ' ').replace(/\s*</g, '<').replace(/>\s*/g, '>').trim();
}
function compile(t) {
// if its an Array, assume it's already compiled;
if (Array.isArray(t)) {
return t;
}
var templ = compress(t);
function getFragment() {
var idx = templ.indexOf('{');
var value = void 0;
if (idx === 0) {
var idx2 = templ.indexOf('}');
value = templ.slice(0, idx2 + 1);
templ = templ.slice(idx2 + 1);
} else if (idx === -1) {
value = templ;
templ = '';
} else {
value = templ.slice(0, idx);
templ = templ.slice(idx);
}
return value;
}
var result = [];
var fragment = void 0;
var dir = void 0;
var chunk = void 0;
do {
fragment = getFragment();
if (fragment.charAt(0) === '{' && (0, _library.getPlugin)(fragment.charAt(1))) {
dir = parseDirective(fragment.slice(1, -1));
chunk = {
value: fragment,
id: dir.id,
key: dir.id.slice(1),
attributes: dir.attributes
};
} else {
chunk = { value: fragment };
}
result.push(chunk);
} while (fragment !== '');
return result;
}
function isSelfClosing(chunk) {
return chunk.value.slice(-2) === '/}';
}
function endTag(id) {
return '{/' + id + '}';
}
function render(t, data) {
var templ = registry[t] ? registry[t] : compile(t);
pushOutput('');
pushTemplate(templ);
pushStack(data);
try {
runUntil('');
} catch (err) {
cleanup();
throw err;
}
popStack();
popTemplate();
if (outputStack.length === 1) {
(0, _library.postProcess)();
}
return popOutput();
}
function register(name, t) {
registry[name] = compile(t);
}
function isRegistered(name) {
return !!registry[name];
}
function cleanup() {
stack.length = 0;
outputStack.length = 0;
templateStack.length = 0;
ptrStack.length = 0;
specialStack.length = 0;
flags = {};
}
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerPlugin=function(e,t){r[e]=t},t.getPlugin=function(e){return r[e]},t.registerPostProcessor=function(e){i.push(e)},t.postProcess=function(){i.forEach(function(e){return e()})};var r={},i=[]},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.setFlag=function(e,t){o[e]=t},t.getFlag=function(e){return o[e]},t.appendOut=g,t.pushOutput=f,t.popOutput=h,t.pushSpecial=function(e){c.push(e)},t.setSpecial=function(e,t){c[c.length-1][e]=t},t.getSpecial=d,t.popSpecial=function(){return c.pop()},t.pushTemplate=v,t.popTemplate=k,t.getTemplate=U,t.incPtr=b,t.getPtr=function(){return a[a.length-1]},t.setPtr=function(e){a[a.length-1]=e},t.pushStack=O,t.popStack=P,t.getAttributes=function(e){for(var t={},n=Object.keys(e),r=n.length,i=0;i<r;i++){var u=n[i];t[u]=x(e[u])}return t},t.parseDirective=y,t.get=x,t.processUntil=M,t.readUntil=function(e){return M(e,function(e){return e.chunk=A(),e.returnVal.push(e.chunk),e})},t.skipUntil=function(e){return M(e,function(e){return e.chunk=A(),e.returnVal=e.chunk.value,e})},t.runUntil=F,t.compress=$,t.loader=function(e){return"module.exports = "+JSON.stringify($(e))+";"},t.compile=_,t.isSelfClosing=function(e){return"/}"===e.value.slice(-2)},t.endTag=function(e){return"{/"+e+"}"},t.render=function(e,t){var n=u[e]?u[e]:_(e);f(""),v(n),O(t);try{F("")}catch(e){throw R(),e}P(),k(),1===s.length&&(0,r.postProcess)();return h()},t.register=function(e,t){u[e]=_(t)},t.isRegistered=function(e){return!!u[e]},t.cleanup=R;var r=n(0);n(21);var i=[],u={},s=[],l=[],a=[],c=[],o={},p=void 0;function g(e){s[s.length-1]+=e}function f(e){s.push(e)}function h(){return s.pop()}function d(e){return c[c.length-1][e]}function v(e){l.push(e),a.push(0),p=e}function k(){a.pop();var e=l.pop();return l.length>0&&(p=l[l.length-1]),e}function U(){return p}function b(){var e=a[a.length-1];return a[a.length-1]=e+1,e}function O(e){i.push(e)}function P(){return i.pop()}function y(e){var t=e;"/"===t.slice(-1)&&(t=t.slice(0,-1).trim());for(var n=[],r={},i=!1,u=null,s="",l=0;l<t.length;l++){var a=t.charAt(l);'"'!==a&&"'"!==a||(a===u?u=null:u||(u=a))," "!==a||u?(i&&(n.push(s),s=""),i=!1):i=!0,i||(s+=a)}n.push(s);for(var c=1;c<n.length;c++){var o=(s=n[c]).indexOf("=");r[s.slice(0,o)]=s.slice(o+1)}return{id:n[0],attributes:r}}function S(e,t){if(void 0===t)return t;var n=e.charAt(0);switch(n){case"":return t;case"'":case'"':var r=e.indexOf(n,1);if(-1===r)throw new Error("Mismatched quote ("+n+")");return S(e.slice(r+1),e.slice(1,r));case".":return S(e.slice(1),t);case"[":var i=function(e,t,n){for(var r=0,i=0;i<e.length;i++)switch(e.charAt(i)){case t:r++;break;case n:if(0==--r)return i}return-1}(e,"[","]");if(-1===i)throw new Error("Mismatched brackets");return S(e.slice(i+1),t[x(e.slice(1,i))]);default:var u=e.indexOf("."),s=e.indexOf("[");return-1===u&&-1===s?t[e]:u>=0&&(-1===s||s>u)?S(e.slice(u),t[e.slice(0,u)]):S(e.slice(s),t[e.slice(0,s)])}}function x(e){if(!Number.isNaN(parseFloat(e)))return parseFloat(e);if("."===e)return i[i.length-1];if("$"===e.charAt(0))return d(e);for(var t=i.length-1;t>=0;t--){var n=S(e,i[t]);if(void 0!==n)return n;if("."===e[0])return""}return""}function A(){var e=b();return U()[e]}function w(e){var t=e.id?e.id[0]:"";(0,r.getPlugin)(t)?(0,r.getPlugin)(t)(e):function(e){g(x(e.value.slice(1,-1)))}(e)}function m(){var e=A();return"{"===e.value.charAt(0)?w(e):function(e){g(e.value)}(e),e}function M(e,t){var n=Array.isArray(e)?e:[e],r={returnVal:[]};do{r=t(r)}while(-1===n.indexOf(r.chunk.value)&&""!==r.chunk.value);if(-1===n.indexOf(r.chunk.value))throw new Error("Mismatched tag: "+n[0]);return r.returnVal}function F(e){return M(e,function(e){return e.chunk=m(),e.returnVal=e.chunk.value,e})}function $(e){var t="{%TEXT}"===e.slice(0,7),n="{%HTML}"===e.slice(0,7);return n||"<"===e.charAt(0)?(n?e.slice(7):e).replace(/\n\s*/g," ").replace(/\s*</g,"<").replace(/>\s*/g,">").replace(/{\*.*?\*}/g,"").trim():(t?e.slice(7):e).replace(/{\*.*?\*}/g,"")}function _(e){if(Array.isArray(e))return e;var t=$(e);function n(){var e=t.indexOf("{"),n=void 0;if(0===e){var r=t.indexOf("}");n=t.slice(0,r+1),t=t.slice(r+1)}else-1===e?(n=t,t=""):(n=t.slice(0,e),t=t.slice(e));return n}var i=[],u=void 0,s=void 0,l=void 0;do{l="{"===(u=n()).charAt(0)&&(0,r.getPlugin)(u.charAt(1))?{value:u,id:(s=y(u.slice(1,-1))).id,key:s.id.slice(1),attributes:s.attributes}:{value:u},i.push(l)}while(""!==u);return i}function R(){i.length=0,s.length=0,l.length=0,a.length=0,c.length=0,o={}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.setRef=s,t.getRef=function(e){return u[e]};var r=n(0),i=n(1),u={};function s(e,t){u[e]=t}(0,r.registerPlugin)("+",function(e){var t=e.key;(0,i.pushOutput)(""),(0,i.isSelfClosing)(e)||(0,i.runUntil)((0,i.endTag)(t)),s(t,(0,i.popOutput)()),(0,i.isRegistered)(t)&&s(t,(0,i.render)(t,{})),(0,i.appendOut)("{+"+t+"}")}),(0,r.registerPostProcessor)(function(){var e=(0,i.popOutput)();Object.keys(u).forEach(function(t){var n="{\\+"+t+"}";e=e.replace(new RegExp(n,"g"),u[t])}),(0,i.pushOutput)(e)})},function(e,t,n){"use strict";var r=n(0),i=n(1),u=n(2);(0,r.registerPlugin)("<",function(e){var t=e.key,n=(0,i.getAttributes)(e.attributes),r=(0,i.readUntil)("{/"+t+"}");r.pop(),r.push({value:""}),(0,i.register)(t,r),(0,i.getFlag)("s")?(0===(0,i.get)("$idx")&&(0,u.setRef)(t,""),(0,u.setRef)(t,""+(0,u.getRef)(t)+(0,i.render)(t,n))):(0,u.setRef)(t,(0,i.render)(t,n))})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@math",function(e){(0,i.pushStack)(e);var t=(0,i.get)((0,i.get)("key")),n=parseFloat(t),r=(0,i.get)((0,i.get)("method")),u=parseFloat((0,i.get)((0,i.get)("operand")));switch(r){case"add":(0,i.appendOut)(""+(n+u));break;case"subtract":(0,i.appendOut)(""+(n-u));break;case"multiply":(0,i.appendOut)(""+n*u);break;case"divide":(0,i.appendOut)(""+n/u);break;case"mod":(0,i.appendOut)(""+n%u);break;case"ceil":(0,i.appendOut)(""+Math.ceil(n));break;case"floor":(0,i.appendOut)(""+Math.floor(n));break;case"round":(0,i.appendOut)(""+Math.round(n));break;case"toint":(0,i.appendOut)(""+parseInt(t,10));break;case"abs":(0,i.appendOut)(""+Math.abs(n))}(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("~",function(e){switch(e.key){case"n":(0,i.appendOut)("\n");break;case"r":(0,i.appendOut)("\r");break;case"s":(0,i.appendOut)(" ");break;case"lb":(0,i.appendOut)("{");break;case"rb":(0,i.appendOut)("}");break;case"lt":(0,i.appendOut)("<");break;case"gt":(0,i.appendOut)(">");break;case"a":(0,i.appendOut)("'");break;case"q":(0,i.appendOut)('"')}})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@ne",function(e){(0,i.pushStack)(e);var t=(0,i.get)((0,i.get)("key")),n=(0,i.get)((0,i.get)("value")),r=(0,i.endTag)("ne");t!==n?"{:else}"===(0,i.runUntil)([r,"{:else}"])&&(0,i.skipUntil)(r):"{:else}"===(0,i.skipUntil)([r,"{:else}"])&&(0,i.runUntil)(r),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@lte",function(e){(0,i.pushStack)(e),(0,i.get)((0,i.get)("key"))<=(0,i.get)((0,i.get)("value"))?"{:else}"===(0,i.runUntil)(["{/lte}","{:else}"])&&(0,i.skipUntil)("{/lte}"):"{:else}"===(0,i.skipUntil)(["{/lte}","{:else}"])&&(0,i.runUntil)("{/lte}"),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@lt",function(e){(0,i.pushStack)(e),(0,i.get)((0,i.get)("key"))<(0,i.get)((0,i.get)("value"))?"{:else}"===(0,i.runUntil)(["{/lt}","{:else}"])&&(0,i.skipUntil)("{/lt}"):"{:else}"===(0,i.skipUntil)(["{/lt}","{:else}"])&&(0,i.runUntil)("{/lt}"),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@gte",function(e){(0,i.pushStack)(e),(0,i.get)((0,i.get)("key"))>=(0,i.get)((0,i.get)("value"))?"{:else}"===(0,i.runUntil)(["{/gte}","{:else}"])&&(0,i.skipUntil)("{/gte}"):"{:else}"===(0,i.skipUntil)(["{/gte}","{:else}"])&&(0,i.runUntil)("{/gte}"),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@gt",function(e){(0,i.pushStack)(e),(0,i.get)((0,i.get)("key"))>(0,i.get)((0,i.get)("value"))?"{:else}"===(0,i.runUntil)(["{/gt}","{:else}"])&&(0,i.skipUntil)("{/gt}"):"{:else}"===(0,i.skipUntil)(["{/gt}","{:else}"])&&(0,i.runUntil)("{/gt}"),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@sep",function(){(0,i.get)("$idx")!==(0,i.get)("$len")-1?"{:else}"===(0,i.runUntil)(["{/sep}","{:else}"])&&(0,i.skipUntil)("{/sep}"):"{:else}"===(0,i.skipUntil)(["{/sep}","{:else}"])&&(0,i.runUntil)("{/sep}")})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@last",function(){(0,i.get)("$idx")===(0,i.get)("$len")-1?"{:else}"===(0,i.runUntil)(["{/last}","{:else}"])&&(0,i.skipUntil)("{/last}"):"{:else}"===(0,i.skipUntil)(["{/last}","{:else}"])&&(0,i.runUntil)("{/last}")})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@first",function(){0===(0,i.get)("$idx")?"{:else}"===(0,i.runUntil)(["{/first}","{:else}"])&&(0,i.skipUntil)("{/first}"):"{:else}"===(0,i.skipUntil)(["{/first}","{:else}"])&&(0,i.runUntil)("{/first}")})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)(">",function(e){var t=(0,i.getAttributes)(e.attributes),n=t.with?t.with:t;(0,i.appendOut)((0,i.render)(e.key,n))})},function(e,t,n){"use strict";(0,n(0).registerPlugin)("/",function(){})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("@eq",function(e){(0,i.pushStack)(e),(0,i.get)((0,i.get)("key"))===(0,i.get)((0,i.get)("value"))?"{:else}"===(0,i.runUntil)(["{/eq}","{:else}"])&&(0,i.skipUntil)("{/eq}"):"{:else}"===(0,i.skipUntil)(["{/eq}","{:else}"])&&(0,i.runUntil)("{/eq}"),(0,i.popStack)()})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("#",function(e){var t=e.key,n=(0,i.getAttributes)(e.attributes),r=(0,i.get)(t),u=(0,i.getPtr)(),s="{/"+t+"}";if(""===r||!1===r||null===r||void 0===r||Array.isArray(r)&&0===r.length)"{:else}"===(0,i.skipUntil)([s,"{:else}"])&&(0,i.runUntil)(s);else{Array.isArray(r)||(r=[r]);var l=(0,i.getFlag)("s")||0;(0,i.setFlag)("s",l+1),(0,i.pushSpecial)({$len:r.length,$idx:0}),(0,i.pushStack)(n);for(var a=0,c=r.length;a<c;a++)(0,i.setSpecial)("$idx",a),(0,i.pushStack)(r[a]),"{:else}"===(0,i.runUntil)([s,"{:else}"])&&(0,i.skipUntil)(s),(0,i.popStack)(),a<r.length-1&&(0,i.setPtr)(u);(0,i.popStack)(),(0,i.popSpecial)(),(0,i.setFlag)("s",l)}})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("!",function(e){var t=e.key,n="{/"+t+"}";(0,i.get)(t)?"{:else}"===(0,i.skipUntil)([n,"{:else}"])&&(0,i.runUntil)(n):"{:else}"===(0,i.runUntil)([n,"{:else}"])&&(0,i.skipUntil)(n)})},function(e,t,n){"use strict";var r=n(0),i=n(1);(0,r.registerPlugin)("?",function(e){var t=e.key,n=(0,i.get)(t),r="{/"+t+"}";""===n||!1===n||null===n||void 0===n||Array.isArray(n)&&0===n.length?"{:else}"===(0,i.skipUntil)([r,"{:else}"])&&(0,i.runUntil)(r):"{:else}"===(0,i.runUntil)([r,"{:else}"])&&(0,i.skipUntil)(r)})},function(e,t,n){"use strict";var r=n(0);(0,r.registerPlugin)("@",function(e){try{(0,r.getPlugin)(e.id)(e.attributes)}catch(t){throw new Error("Unable to execute helper "+e.id)}})},function(e,t,n){"use strict";n(20),n(19),n(18),n(17),n(16),n(15),n(14),n(13),n(12),n(11),n(10),n(9),n(8),n(7),n(6),n(5),n(4),n(3),n(2)}]);
//# sourceMappingURL=index.js.map
{
"name": "jet-engine",
"version": "1.0.2",
"version": "1.0.3",
"description": "Jet engine",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"test": "jest --verbose",
"lint": "eslint ./ --ignore-path .gitignore --ext .js",
"build:dist": "babel src --out-dir dist",
"build:babel": "babel src --out-dir dist",
"build:dist": "webpack -p",
"clean": "rimraf dist",

@@ -44,5 +45,10 @@ "build": "npm run clean && npm run build:dist"

"jest": "^22.4.3",
"rimraf": "^2.6.2"
"rimraf": "^2.6.2",
"webpack-cli": "^2.0.14"
},
"dependencies": {}
"dependencies": {
"babel-loader": "^7.1.4",
"path": "^0.12.7",
"webpack": "^4.5.0"
}
}

@@ -6,3 +6,3 @@ #jet-engine

jet-engine is a template engine with syntax very similar to dustjs-linked in. It was written because I needed a template engine that was more compact and less complicated to use than dustjs, but I liked dustjs syntax, compared to other template engines like handlebars. In the few cases in which I wanted templates to behave differently, I implemented my preferred way. I also had no requirement for asynchronous template handing, so I left that out.
jet-engine is a template engine with syntax very similar to dustjs-linked in. It was written because we were trying to produce the smallest bundle possible for a recent project. I liked dustjs syntax, compared to other template engines, and thought this would be a fun side project. I'm very pleased with the result. Each function is written in a separate source file, and it is easy to add additional features. In the few cases in which I wanted templates to behave differently than dustjs, I implemented my preferred approach. We also had no requirement for asynchronous template handing, so I left that out.

@@ -19,18 +19,20 @@ # Usage

All the familiar keywords are implemented,
Nearly all of the familiar keywords are implemented:
```
{value}
{#section}
{?test}
{!not} // also supports {^not} syntax for compatability
{@eq ...} // and other helpers
{>partials}
{<inline-partials}
{+blocks}
{~gt} // and other special characters
{!test} // my preferred negation test
{* comment *} // my preferred comment
{@eq ...} // and many other helpers
{>subroutine} // I prefer this terminology
{<definition} // ditto
{+block}
{~gt} // and several other other special characters
```
# Partials
# Subroutines
Register a partial like this
Register a subroutine like this

@@ -45,2 +47,21 @@ ```

# Many more examples and additional documentation to follow
# Context
The data context is exactly as you would expect form a sophisticated engine.
An initial context is set when the render() function is first invoked. Addition conexts are pushed and popped from context stack by the following commands:
```
{#names} // value of "names" is pushed onto the context stack
{>subroutine name="Jim"} // { name: "Jim" } is pushed onto the context stack
{@eq key="size" value=17} // { key: "size", value: 17 } is pushed onto the stack (explained in Helpers section below)
```
Data references are resolved from the top of the context stack downward, with the following exceptions:
```
{.} refers to the entire context currently on the top of the stack
{.value} references "value" only if it exists on the top of the stack. Searching will not continue downwards in the stack.
```
If a reference cannot be found on the context stack, an empty string `''` is returned.
*provide examples*
## Document each keyword funciton

@@ -311,3 +311,3 @@ import { getPlugin, postProcess } from './library';

if (!isHTML && s.charAt(0) !== '<') {
return isText ? s.slice(7) : s;
return (isText ? s.slice(7) : s).replace(/{\*.*?\*}/g, '');
}

@@ -319,5 +319,10 @@

.replace(/>\s*/g, '>')
.replace(/{\*.*?\*}/g, '')
.trim();
}
export function loader(content) {
return `module.exports = ${JSON.stringify(compress(content))};`;
}
export function compile(t) {

@@ -324,0 +329,0 @@ // if its an Array, assume it's already compiled;

@@ -23,2 +23,1 @@ import { registerPlugin } from './library';

registerPlugin('!', not);
registerPlugin('^', not); // for dustjs syntax compatability
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc