# Data helpers: QUERIFY, STRINGIFY, ENCRYPT, FN, CL, TRANSLATE, UNAUTHORIZED and Thelpers

> Build query strings, write JSON without what you do not want, encode a value with a key, compile an expression, load lists of values, translate texts, check permissions and add helpers to the templates.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: dffd31596690d343866ae9498b493c7db67dcd3147728ef8175a0bd4c2523204
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

- `QUERIFY([url], object)` makes a query string: `null` values 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])` is `JSON.stringify()` with two options: `compress: true` leaves out empty texts, `null` and `false`, and trims the texts; `fields` is a list of the names that are kept, a function `(key, value)` that decides, or an object where `name: false` leaves 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, and `DECRYPT(text, [key], [type])` gives the value back, or `undefined` when 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 called `value`.
- `NOOP`, `EMPTYARRAY` and `EMPTYOBJECT` (frozen: they cannot be changed by mistake), `MONTHS` and `DAYS` (the names in English) and `NOW` (a `Date` that jComponent keeps up to date).
- **Code lists:** `CLINIT(name, function(next) {}, [expire], [init])` registers a list that `function` loads (it calls `next(value)`; with a text instead of a function, an address like `GET /api/countries/`). `CL('a,b', callback)` loads the lists that are not loaded and stores each one in `DEF.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) and `TRANSLATE(text)` replaces every `@(text)` with its translation (the same text when there is none). The key is `T` plus the `HASH()` of the text in base 36.
- `UNAUTHORIZED(...names)` returns `false` when `window.user` has one of the permissions (`user.permissions` or `user.roles`, a list or an object) or is `sa` / `su`, and `true` otherwise (also when there is no user).
- `Thelpers` (the same object as `Tangular.helpers`, and `Ta` is `Tangular`) holds the helpers of the templates: add one with `Thelpers.name = function(value, ...arguments)`, where `this` is the model, and use it as `{{ value | name(argument) }}`.

```html public/index.html
<!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>
```
