Data helpers: QUERIFY, STRINGIFY, ENCRYPT, FN, CL, TRANSLATE, UNAUTHORIZED and Thelpers
QUERIFY([url], object)makes a query string:nullvalues are skipped, arrays are joined with commas, dates become ISO texts and everything is encoded. With a url it is added to it (?or&), also after a method as in'POST /api/x'.STRINGIFY(object, [compress], [fields])isJSON.stringify()with two options:compress: trueleaves out empty texts,nullandfalse, and trims the texts;fieldsis a list of the names that are kept, a function(key, value)that decides, or an object wherename: falseleaves a field out.ENCRYPT(value, [key], [type])turns a text or an object into a hexadecimal text that ends with a check of the key, andDECRYPT(text, [key], [type])gives the value back, orundefinedwhen the key or the type are not the same. It is an obfuscation for the browser, not security: anybody can read it without the key.FN('n => n * 2')compiles an expression into a function and remembers it; without=>the text is the body and the argument is calledvalue.NOOP,EMPTYARRAYandEMPTYOBJECT(frozen: they cannot be changed by mistake),MONTHSandDAYS(the names in English) andNOW(aDatethat jComponent keeps up to date).- Code lists:
CLINIT(name, function(next) {}, [expire], [init])registers a list thatfunctionloads (it callsnext(value); with a text instead of a function, an address likeGET /api/countries/).CL('a,b', callback)loads the lists that are not loaded and stores each one inDEF.cl.name(and in the state at that path);CLRELOAD(name, callback)loads them again. - Translation:
LOCALIZE(text)loads a dictionary in the format of the Total.js resource files (key : translation, one by line,//for comments) andTRANSLATE(text)replaces every@(text)with its translation (the same text when there is none). The key isTplus theHASH()of the text in base 36. UNAUTHORIZED(...names)returnsfalsewhenwindow.userhas one of the permissions (user.permissionsoruser.roles, a list or an object) or issa/su, andtrueotherwise (also when there is no user).Thelpers(the same object asTangular.helpers, andTaisTangular) holds the helpers of the templates: add one withThelpers.name = function(value, ...arguments), wherethisis the model, and use it as{{ value | name(argument) }}.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jComponent</title>
<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
<p class="out"></p>
</body>
</html> Try it in your browser
Edit the example and run it. It runs in an isolated frame in your browser; nothing is sent to our server.
Preview