---
title: Utility
project: Total.js V4
version: 0.0.99
section: reference
language: sk
license: MIT
url: https://totaljs.es/docs/sk/total-js-v4/0-0-99/reference/utilities/
updated: 2026-11-16T15:41:15.818Z
---

# Utility

> Funkcie U (utils.js) a globálni pomocníci a objekty frameworku.

Total.js definuje pomocníkov v globálnom rozsahu a v objekte `U` (`Utils`), takže ich môže používať každý súbor aplikácie bez `require()`. Návod [Utility](../../guides/utilities/) vysvetľuje, ako ich používať, s príkladmi; táto stránka je presná referencia.

## API

### U

Type: `property`

Knižnica utilít frameworku (`utils.js`).

Returns: `Object`

`U`, `Utils` a `utils` sú ten istý objekt. Je globálny, takže ho používaš v kontroléroch, schémach, moduloch a pluginoch bez `require()`.

Example: Použitie pomocníka
```js
var ext = U.getExtension('photo.JPG'); // 'jpg'
```

### Total

Type: `property` · Since: `0.0.96`

Globálny alias inštancie frameworku `F`.

Returns: `Framework`

`Total`, `F` a `framework` odkazujú na ten istý objekt.

Example: Ten istý objekt
```js
console.log(Total === F); // true
```

### NOW

Type: `property`

`Date`, ktorý framework pravidelne obnovuje.

Returns: `Date`

Čítanie `NOW` je lacnejšie ako `new Date()`. Framework ho znova nastavuje vo svojich interných intervaloch (približne každú minútu) a pri niektorých volaniach, napríklad `LOGGER()`. Použi ho tam, kde stačí presnosť na minútu; pre presný čas použi `new Date()`. `F.datetime` číta a zapisuje tú istú hodnotu.

Example: Časová značka záznamu
```js
var model = { id: UID(), dtcreated: NOW };
```

### EMPTYOBJECT

Type: `property`

Zmrazený prázdny objekt.

Returns: `Object`

Použi ho ako predvolenú hodnotu, ktorá sa nikdy nemení. Je zmrazený, takže priradenia doň nemajú žiadny efekt.

Example: Predvolené voľby
```js
function send(options) {
	options = options || EMPTYOBJECT;
	return options.timeout || 5000;
}
```

### EMPTYARRAY

Type: `property`

Zmrazené prázdne pole.

Returns: `Array`

Použi ho ako predvolenú hodnotu, ktorá sa nikdy nemení. Je zmrazené, takže `push()` vyhodí chybu.

Example: Predvolený zoznam
```js
var items = response.items || EMPTYARRAY;
```

### NOOP()

Type: `method`

Prázdna funkcia.

Returns: `undefined`

Odovzdaj ju tam, kde sa vyžaduje callback a výsledok nepotrebuješ.

Example: Ignorovanie callbacku
```js
Fs.unlink(PATH.temp('export.csv'), NOOP);
```

### MAIN

Type: `property`

Prázdny globálny objekt pre tvoje vlastné zdieľané dáta.

Returns: `Object`

Framework vytvorí `MAIN = {}` a nepoužíva ho. Ukladaj doň hodnoty pre celú aplikáciu, napríklad dáta načítané pri štarte.

Example: Zdieľané nastavenia
```js
// definitions/init.js
MAIN.settings = { currency: 'EUR' };

// any other file
var currency = MAIN.settings.currency;
```

### REPO

Type: `property`

Prázdny globálny objekt pre tvoj vlastný repozitár hodnôt.

Returns: `Object`

Framework vytvorí `REPO = {}` a nepoužíva ho. Je to druhý menný priestor ako `MAIN`.

Example: Cache zoznamu
```js
REPO.countries = ['SK', 'CZ', 'AT'];
```

### FUNC

Type: `property`

Prázdny globálny objekt pre tvoje vlastné zdieľané funkcie.

Returns: `Object`

Framework vytvorí `FUNC = {}`. Vlož doň pomocníkov, ktorých volá viac súborov aplikácie.

Example: Zdieľaná funkcia
```js
// definitions/func.js
FUNC.price = function(value) {
	return value.format(2) + ' EUR';
};

// a controller or a schema
var text = FUNC.price(12.5);
```

### TEMP

Type: `property`

Globálny objekt pre dočasné dáta, ktorý framework maže.

Returns: `Object`

Framework nahrádza `TEMP` novým prázdnym objektom pri svojom pravidelnom čistení (každých `CONF.default_interval_clear_cache` minút, predvolene 10). Nenechávaj tam nič, čo budeš neskôr potrebovať.

Example: Krátkodobá hodnota
```js
if (!TEMP.stats)
	TEMP.stats = compute();
```

### MODS

Type: `property`

Všetky načítané moduly podľa ich názvu.

Returns: `Object`

Ten istý objekt ako `F.modules`. Kľúčom je názov súboru v `/modules/` (alebo `id`, ktoré modul exportuje).

Example: Výpis modulov
```js
Object.keys(MODS).forEach(function(name) {
	console.log(name);
});
```

### MODULE(name)

Type: `method`

Vráti načítaný modul.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov modulu. |

Returns: `Object` Modul, alebo `null`.

Číta `F.modules[name]`. Výsledkom je `exports` súboru modulu, alebo `null`, keď modul s týmto názvom nie je načítaný.

Example: Volanie modulu
```js
// modules/mailer.js
exports.send = function(email) { /* ... */ };

// anywhere
MODULE('mailer').send('info@example.com');
```

### LOGGER(name, value1, [value2], [...])

Type: `method`

Pripojí riadok do log súboru v adresári `/logs/`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov log súboru bez `.log`. |
| `value` | `Object` | yes |  | Jedna alebo viac hodnôt na zápis. |

Returns: `undefined`

Riadok je `yyyy-MM-dd HH:mm:ss | values` v súbore `{name}.log`. Hodnoty sú oddelené medzerou; objekty sa formátujú cez `util.inspect()`. Adresár sa vytvorí, keď neexistuje, a zápisy idú cez `U.queue()` s najviac 5 zápismi naraz.

Example: Zalogovanie platby
```js
LOGGER('payments', 'order', order.id, 'paid', order.price);
// logs/payments.log:
// 2021-03-01 10:22:05 | order 1a2b3c paid 39.9
```

### PROMISIFY(fn, [a], [b], [c])

Type: `method` · Since: `0.0.97`

Zavolá funkciu v štýle callbacku a vráti Promise.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | yes |  | Funkcia, ktorá ako posledný argument berie callback. |
| `a` | `Object` | no |  | Prvý argument. |
| `b` | `Object` | no |  | Druhý argument. |
| `c` | `Object` | no |  | Tretí argument. |

Returns: `Promise`

`fn` sa zavolá so zadanými argumentmi a callbackom `function(err, response)` ako posledným argumentom. Promise sa zamietne s `err` alebo vyrieši s `response`. Podporujú sa až tri argumenty; argumenty, ktoré sú `undefined`, sa neodovzdávajú.

Example: Čítanie súboru
```js
var Fs = require('fs');
var content = await PROMISIFY(Fs.readFile, PATH.root('readme.md'), 'utf8');
```

Example: Vlastná funkcia
```js
function load(id, callback) {
	callback(null, { id: id });
}

var item = await PROMISIFY(load, '123');
```

### WAIT(validator, callback, [timeout], [interval])

Type: `method`

Čaká, kým nie je podmienka splnená.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `validator` | `Function` | yes |  | Vráti `true`, keď čakanie skončilo. |
| `callback` | `Function` | yes |  | `function(err, success)`. |
| `timeout` | `Number` | no | `5000` | Maximálny čas v ms. |
| `interval` | `Number` | no | `500` | Čas medzi kontrolami v ms. |

Returns: `undefined`

`validator()` sa skontroluje hneď a potom každých `interval` ms. Keď vráti `true`, zavolá sa `callback(null, true)`. Keď skôr uplynie `timeout` ms, zavolá sa `callback(Error('Timeout'), false)`.

Example: Čakanie na spojenie
```js
WAIT(function() {
	return MAIN.db != null;
}, function(err) {
	if (err)
		console.log('Database is not ready');
	else
		console.log('Ready');
}, 10000);
```

### UID([type], [date])

Type: `method`

Vytvorí krátky unikátny identifikátor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no |  | Názov nezávislého počítadla. |
| `date` | `Date` | no | `NOW` | Čas zakódovaný v ID. |

Returns: `String`

ID je reťazec založený na čase, napríklad `24j0y001xn51d`, ktorý sa triedi podľa času vytvorenia. Je unikátny v rámci bežiacej inštancie (framework pridáva náhodný kľúč inštancie). `type` udržiava samostatné počítadlo pre každý typ, takže ID rôznych kolekcií nezdieľajú sekvenciu. `date` vytvorí ID pre iný čas. `CONF.default_uid` vyberá verziu: `r` dá náhodné ID (`UIDR()`), `f` variant v sústave 62; predvolená je verzia `d`.

Example: Nový záznam
```js
var model = {};
model.id = UID();
model.dtcreated = NOW;
```

Example: Počítadlo pre typ
```js
var orderid = UID('orders');
var invoiceid = UID('invoices');
```

### UID16([type], [date])

Type: `method`

Vytvorí unikátny identifikátor s časovou časťou v sústave 16.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no |  | Názov nezávislého počítadla. |
| `date` | `Date` | no | `NOW` | Čas zakódovaný v ID. |

Returns: `String`

Funguje ako `UID()`, ale čas kóduje hexadecimálne, takže ID je o niečo dlhšie (verzia `c`). Ignoruje `CONF.default_uid`.

Example: ID založené na hex
```js
var id = UID16(); // e.g. '367b52002xn60c'
```

### GUID([length])

Type: `method`

Vytvorí GUID alebo náhodný reťazec zadanej dĺžky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `length` | `Number` | no |  | Dĺžka náhodného reťazca. |

Returns: `String`

Bez `length` vráti reťazec v tvare UUID `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` zostavený z aktuálneho času a náhodných čísel. S `length` vráti náhodné malé písmená a číslice tejto dĺžky. Dostupné aj ako `U.GUID()`.

Example: Tvar UUID
```js
var id = GUID(); // '1a1defc8-efc8-2c86-8d36-938350b51dfd'
```

Example: Náhodný token
```js
var token = GUID(30);
```

### CLONE(obj, [skip], [skipFunctions])

Type: `method`

Vytvorí hlbokú kópiu objektu alebo poľa.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | Objekt alebo pole na skopírovanie. |
| `skip` | `Object` | no |  | Kľúče na vynechanie, ako `{ key: true }`. |
| `skipFunctions` | `Boolean` | no | `false` | Vynechá funkcie. |

Returns: `Object` Nový objekt.

Vnorené objekty a polia sa kopírujú; hodnoty `Date` a `Error` sa ponechajú ako referencie a Buffery sa kopírujú. `skip` je objekt kľúčov, ktoré sa vynechajú (`{ password: 1 }`) na prvej úrovni objektov. Dostupné aj ako `U.clone()`.

Example: Kópia bez kľúča
```js
var copy = CLONE(user, { password: 1 });
copy.name = 'Peter'; // user.name is unchanged
```

### COPY(source, [target])

Type: `method`

Skopíruje všetky vlastnosti zo `source` do `target`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | `Object` | yes |  | Objekt na čítanie. |
| `target` | `Object` | no |  | Objekt na zápis. |

Returns: `Object` Cieľ.

Každý kľúč zo `source` sa naklonuje do `target`, aj kľúče, ktoré `target` nemá. Bez `target` vráti novú kópiu `source`. Je to `U.copy(source, target, true)`.

Example: Zlúčenie
```js
var target = { a: 0 };
COPY({ a: 1, z: 9 }, target);
// target: { a: 1, z: 9 }
```

### HASH(value, [type])

Type: `method`

Vytvorí hash reťazca.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Text. |
| `type` | `String` | no |  | Hashovací algoritmus. |

Returns: `Number|String`

Bez `type` vráti rýchly číselný hash (32-bitový bez znamienka). `type` môže byť `md5`, `sha1`, `sha256`, `sha512`, `crc32` alebo `crc32unsigned`. Volá `value.hash()`.

Example: Číselný a MD5
```js
HASH('abc');        // 96354
HASH('abc', 'md5'); // '900150983cd24fb0d6963f7d28e17f72'
```

### QUERIFY([url], obj)

Type: `method`

Pridá objekt k URL ako query string.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | no |  | URL. |
| `obj` | `Object` | yes |  | Hodnoty query stringu. |

Returns: `String`

Hodnoty `null` alebo `undefined` sa vynechajú; dátumy sa zmenia na ISO reťazce a polia sa spoja čiarkami. Kľúče a hodnoty sa zakódujú. URL môže začínať metódou (`GET /api/`); query sa pridá k ceste. Bez URL vráti iba `?key=value`.

Example: Zostavenie URL
```js
QUERIFY('GET /api/products/', { page: 2, q: 'a b' });
// 'GET /api/products/?page=2&q=a%20b'

QUERIFY({ page: 1 }); // '?page=1'
```

### DIFFARR(prop, db, form)

Type: `method`

Porovná dve polia objektov podľa kľúča.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `prop` | `String` | yes |  | Názov kľúča, napríklad `id`. |
| `db` | `Object[]` | yes |  | Uložené položky. |
| `form` | `Object[]` | yes |  | Nové položky. |

Returns: `Object` `{ add: [], upd: [], rem: [] }`

Vráti `{ add, upd, rem }`: `add` obsahuje položky z `form`, ktoré nie sú v `db`, `upd` obsahuje páry `{ db, form }`, ktoré existujú v oboch, a `rem` obsahuje hodnoty kľúčov položiek z `db`, ktoré vo `form` chýbajú. Použi ho na uloženie zoznamu, ktorý používateľ upravil.

Example: Synchronizácia zoznamu
```js
var diff = DIFFARR('id', [{ id: 1 }, { id: 2 }], [{ id: 2, name: 'B' }, { id: 3 }]);
// diff.add: [{ id: 3 }]
// diff.upd: [{ db: { id: 2 }, form: { id: 2, name: 'B' } }]
// diff.rem: [1]
```

### PATH.root([filename])

Type: `method`

Vráti cestu v koreňovom adresári aplikácie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Relatívna cesta. |

Returns: `String`

Výsledok vždy používa `/` ako oddeľovač.

Example: Súbor v koreni
```js
var filename = PATH.root('data/countries.json');
```

### PATH.temp([filename])

Type: `method`

Vráti cestu v dočasnom adresári a adresár vytvorí.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String`

Adresár je `CONF.directory_temp`. `PATH.tmp()` a `PATH.temporary()` sú aliasy.

Example: Dočasný súbor
```js
var filename = PATH.temp('export-' + UID() + '.csv');
```

### PATH.databases([filename])

Type: `method`

Vráti cestu v adresári databáz a adresár vytvorí.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String`

Adresár je `CONF.directory_databases`.

Example: Dátový súbor
```js
var filename = PATH.databases('settings.json');
```

### PATH.logs([filename])

Type: `method`

Vráti cestu v adresári logov a adresár vytvorí.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String`

Adresár je `CONF.directory_logs`. Zapisuje tam `LOGGER()`.

Example: Čítanie logu
```js
require('fs').readFile(PATH.logs('payments.log'), 'utf8', function(err, text) {
	console.log(text);
});
```

### PATH.mkdir(path, [cache])

Type: `method`

Vytvorí adresár so všetkými chýbajúcimi nadradenými adresármi.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Absolútna cesta. |
| `cache` | `Boolean` | no | `false` | Preskočí cesty vytvorené predtým. |

Returns: `undefined`

Funguje synchrónne. S `cache` nastaveným na `true` sa cesta, ktorá už bola vytvorená, znova nekontroluje, kým framework nevymaže svoju cache.

Example: Adresár pre nahrané súbory
```js
var dir = PATH.databases('uploads/2021/');
PATH.mkdir(dir, true);
```

### U.random([max], [min])

Type: `method`

Vráti náhodné celé číslo medzi `min` a `max`, vrátane oboch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `max` | `Number` | no | `100000` | Najvyššia hodnota. |
| `min` | `Number` | no | `0` | Najnižšia hodnota. |

Returns: `Number`

Example: Hracia kocka
```js
var dice = U.random(6, 1);
```

### U.random_text(length)

Type: `method`

Vráti náhodný reťazec písmen a číslic.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `length` | `Number` | yes |  | Počet znakov. |

Returns: `String`

Znaky sú `0-9`, `A-Z` a `a-z`.

Example: Kód
```js
var code = U.random_text(8); // e.g. '1qrWGUa7'
```

### U.random_string(length)

Type: `method`

Vráti náhodný reťazec písmen.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `length` | `Number` | yes |  | Počet znakov. |

Returns: `String`

Znaky sú `A-Z` a `a-z`, bez číslic.

Example: Iba písmená
```js
var name = U.random_string(6);
```

### U.random_number(length)

Type: `method`

Vráti reťazec náhodných číslic.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `length` | `Number` | yes |  | Počet číslic. |

Returns: `String`

Prvá číslica nikdy nie je `0`, takže `+value` má rovnaký počet číslic. Výsledkom je reťazec.

Example: PIN
```js
var pin = U.random_number(6); // e.g. '986081'
```

### U.encrypt_uid(value, [key])

Type: `method`

Podpíše ID, aby ho klient nemohol zmeniť.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Number` | yes |  | ID. |
| `key` | `String` | no | `CONF.secret` | Tajný kľúč. |

Returns: `String`

Výsledok obsahuje ID a kontrolný súčet ID a kľúča, napríklad `n3ck9tg6x123`. Hodnota nie je skrytá; je chránená proti zmenám. Na spätné prečítanie použi `U.decrypt_uid()`.

Example: Odkaz s podpísaným ID
```js
var link = '/download/' + U.encrypt_uid(file.id) + '/';
```

### U.decrypt_uid(value, [key])

Type: `method`

Prečíta ID podpísané cez `U.encrypt_uid()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Podpísané ID. |
| `key` | `String` | no | `CONF.secret` | Tajný kľúč použitý na podpis. |

Returns: `String|Number` ID, alebo `null`.

Vráti pôvodné ID (číslo, keď bolo podpísané číslo), alebo `null`, keď kontrolný súčet nesedí.

Example: Overenie ID z URL
```js
var id = U.decrypt_uid(this.params.id);
if (id == null) {
	this.throw404();
	return;
}
```

### U.copy(source, [target])

Type: `method`

Skopíruje hodnoty zo `source` do kľúčov, ktoré `target` už má.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | `Object` | yes |  | Objekt na čítanie. |
| `target` | `Object` | no |  | Objekt na zápis. |

Returns: `Object` Cieľ.

Zapíšu sa iba kľúče, ktoré existujú v `target` (s inou hodnotou ako `undefined`); hodnoty sa klonujú. Bez `target` vráti novú kópiu `source`. Na skopírovanie všetkých kľúčov použi `COPY()`.

Example: Aktualizácia známych polí
```js
var item = { name: '', price: 0 };
U.copy({ name: 'Book', price: 9, hack: true }, item);
// item: { name: 'Book', price: 9 }
```

### U.extend(target, source, [rewrite])

Type: `method`

Pridá vlastnosti zo `source` do `target`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `target` | `Object` | yes |  | Objekt na zápis. |
| `source` | `Object` | yes |  | Objekt na čítanie. |
| `rewrite` | `Boolean` | no | `true` | Prepíše existujúce hodnoty. |

Returns: `Object` Cieľ.

Hodnoty sa klonujú. S `rewrite` nastaveným na `false` sa kľúče, ktoré už majú hodnotu v `target`, ponechajú, takže `source` funguje ako sada predvolených hodnôt.

Example: Predvolené hodnoty
```js
var options = { timeout: 1000 };
U.extend(options, { timeout: 5000, retry: 3 }, false);
// options: { timeout: 1000, retry: 3 }
```

### U.reduce(source, props, [reverse])

Type: `method`

Ponechá iba niektoré vlastnosti objektu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | `Object|Object[]` | yes |  | Objekt alebo pole objektov. |
| `props` | `String[]|Object` | yes |  | Kľúče na ponechanie. |
| `reverse` | `Boolean` | no | `false` | Namiesto toho odstráni uvedené kľúče. |

Returns: `Object|Object[]`

`props` je pole kľúčov alebo objekt, ktorého kľúče sa použijú. S `reverse` nastaveným na `true` sa uvedené kľúče naopak odstránia. Pole ako `source` zredukuje každú položku. Výsledkom je nový objekt.

Example: Verejné polia
```js
var output = U.reduce(user, ['id', 'name']);
var safe = U.reduce(user, ['password'], true);
```

### U.get(obj, path)

Type: `method`

Prečíta hodnotu podľa cesty ako `address.city`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | Objekt. |
| `path` | `String` | yes |  | Cesta s bodkami. |

Returns: `Object` Hodnota.

Vráti `undefined`, keď časť cesty neexistuje. Indexy sa píšu ako `items[0].name`. Cesty, ktoré obsahujú znaky podobné kódu (medzery, zátvorky volaní, `__proto__` a podobne), vrátia `undefined`.

Example: Vnorená hodnota
```js
U.get({ address: { city: 'Bratislava' } }, 'address.city'); // 'Bratislava'
U.get({}, 'address.city'); // undefined
```

### U.set(obj, path, value)

Type: `method`

Zapíše hodnotu podľa cesty ako `address.city`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | Objekt. |
| `path` | `String` | yes |  | Cesta s bodkami. |
| `value` | `Object` | yes |  | Hodnota. |

Returns: `Object` Hodnota.

Chýbajúce objekty na ceste sa vytvoria. Cesta, ktorá končí `[]`, vloží hodnotu do poľa. Cesty, ktoré obsahujú znaky podobné kódu, sa ignorujú.

Example: Zostavenie objektu
```js
var obj = {};
U.set(obj, 'address.city', 'Bratislava');
U.set(obj, 'tags[]', 'new');
// { address: { city: 'Bratislava' }, tags: ['new'] }
```

### U.trim(obj, [clean])

Type: `method`

Oreže všetky reťazcové hodnoty objektu alebo poľa.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object|Array|String` | yes |  | Hodnota na orezanie. |
| `clean` | `Boolean` | no | `false` | Nahradí prázdne reťazce hodnotou `undefined`. |

Returns: `Object` Tá istá hodnota.

Orežú sa aj vnorené objekty a polia; objekt sa mení na mieste. S `clean` nastaveným na `true` sa prázdne reťazce zmenia na `undefined`.

Example: Vyčistenie formulára
```js
U.trim({ name: ' Peter ', note: '  ' }, true);
// { name: 'Peter', note: undefined }
```

### U.keywords(content, [forSearch], [alternative], [max_count], [max_length], [min_length])

Type: `method`

Extrahuje z textu kľúčové slová.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `content` | `String|String[]` | yes |  | Text. |
| `forSearch` | `Boolean` | no | `true` | Normalizuje slová pre vyhľadávanie. |
| `alternative` | `Boolean` | no | `false` | Skráti slová. |
| `max_count` | `Number` | no | `200` | Maximálny počet prečítaných slov. |
| `max_length` | `Number` | no | `20` | Dlhšie slová sa preskočia. |
| `min_length` | `Number` | no | `2` | Kratšie slová sa preskočia. |

Returns: `String[]`

Text sa prevedie na malé písmená a rozdelí na slová; výsledkom je zoznam unikátnych slov, najčastejšie ako prvé. S `forSearch` (predvolené) sa odstráni diakritika a `y` sa nahradí `i`, takže rovnaké slová sa pri vyhľadávaní zhodujú. `alternative` skráti každé slovo na 80 % jeho dĺžky, aby sa zhodovali tvary slov. `content` môže byť pole textov.

Example: Vyhľadávací index
```js
var keywords = U.keywords(product.name + ' ' + product.description).join(' ');
```

### U.queue(name, max, fn, [param])

Type: `method`

Spúšťa funkcie s limitom, koľko ich beží naraz.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov fronty. |
| `max` | `Number` | yes |  | Maximum bežiacich funkcií. |
| `fn` | `Function` | yes |  | `function(next, param)`. |
| `param` | `Object` | no |  | Hodnota odovzdaná do `fn`. |

Returns: `Boolean`

Každé volanie pridá `fn(next, param)` do fronty `name`. Naraz beží najviac `max` funkcií tejto fronty; každá musí zavolať `next()`, keď skončí. Vráti `true`, keď `fn` začne hneď, `false`, keď čaká.

Example: Tri sťahovania naraz
```js
urls.forEach(function(url) {
	U.queue('downloads', 3, function(next, url) {
		download(url, next);
	}, url);
});
```

### U.sortcomparer(sort)

Type: `method`

Vytvorí z textu porovnávaciu funkciu pre `Array.sort()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `sort` | `String` | yes |  | Definícia triedenia. |

Returns: `Function` `function(a, b)`

`sort` je zoznam polí oddelených čiarkami, každé s voliteľnou príponou `_asc` alebo `_desc`, napríklad `price_desc,name`. Podporované sú vnorené polia ako `address.city`. Reťazce, čísla, booleany a dátumy sa porovnávajú podľa svojho typu.

Example: Zoradenie produktov
```js
products.sort(U.sortcomparer('price_desc,name_asc'));
```

### U.combine(path1, [path2], [...])

Type: `method`

Spojí cesty relatívne ku koreňovému adresáru aplikácie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Jedna alebo viac častí cesty. |

Returns: `String` Absolútna cesta.

Časť, ktorá začína `~`, je absolútna cesta a nahradí to, čo bolo pred ňou. Na Windows výsledok používa `/`.

Example: Cesty v aplikácii
```js
U.combine('/public/', 'img'); // '/www/app/public/img'
U.combine('~/var/data/', 'file.txt'); // '/var/data/file.txt'
```

### U.join(path1, [path2], [...])

Type: `method`

Spojí časti cesty znakom `/`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Jedna alebo viac častí. |

Returns: `String`

Lomky na začiatku a na konci každej časti sa odstránia a výsledok začína `/`. Prázdne časti sa preskočia.

Example: Spojenie
```js
U.join('a', '/b/', 'c'); // '/a/b/c'
```

### U.getExtension(filename, [raw])

Type: `method`

Vráti príponu názvu súboru bez bodky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | yes |  | Názov súboru alebo URL. |
| `raw` | `Boolean` | no | `false` | Zachová pôvodnú veľkosť písmen. |

Returns: `String`

Prípona sa prevedie na malé písmená, pokiaľ `raw` nie je `true`. Query string za `?` sa ignoruje. Vráti prázdny reťazec, keď prípona neexistuje.

Example: Prípona
```js
U.getExtension('Photo.JPG?width=200'); // 'jpg'
```

### U.getName(path)

Type: `method`

Vráti poslednú časť cesty.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Cesta. |

Returns: `String`

Funguje s oddeľovačmi `/` aj `\`; koncový oddeľovač sa ignoruje.

Example: Názov súboru
```js
U.getName('/www/app/public/logo.png'); // 'logo.png'
```

### U.getContentType(ext)

Type: `method`

Vráti content type (MIME typ) pre príponu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ext` | `String` | yes |  | Prípona. |

Returns: `String`

Prípona môže začínať bodkou. Neznáma prípona dá `application/octet-stream`.

Example: MIME typ
```js
U.getContentType('json'); // 'application/json'
U.getContentType(U.getExtension(filename));
```

### U.setContentType(ext, type)

Type: `method`

Zaregistruje alebo zmení content type prípony.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ext` | `String` | yes |  | Prípona, s bodkou alebo bez nej. |
| `type` | `String` | yes |  | Content type. |

Returns: `Boolean` `true`

Framework používa túto tabuľku na poskytovanie statických súborov, takže nová prípona sa stane aj známym statickým súborom.

Example: Nová prípona
```js
// definitions/init.js
U.setContentType('gpx', 'application/gpx+xml');
```

### U.ls(path, [callback], [filter], [unified])

Type: `method`

Vypíše všetky súbory a adresáre v adresári a jeho podadresároch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Adresár. |
| `callback` | `Function` | no |  | `function(files, directories)`. |
| `filter` | `String|RegExp|Function` | no |  | Filter. |
| `unified` | `Boolean` | no | `false` | Na Windows používa `/`. |

Returns: `Promise|undefined` Promise, keď chýba callback.

`callback(files, directories)` dostane polia absolútnych ciest. Bez callbacku metóda vráti Promise s `{ files, directories }`. `filter` je reťazec (časť názvu, bez ohľadu na veľkosť písmen), RegExp, alebo `function(path, isDirectory)`, ktorá vráti `true`, aby sa položka ponechala; filtre reťazcom a RegExp sa vzťahujú iba na súbory. S `unified` nastaveným na `true` cesty na Windows používajú `/`.

Example: Callback
```js
U.ls(PATH.public(), function(files, directories) {
	console.log(files.length, directories.length);
}, /\.(jpg|png)$/);
```

Example: Promise
```js
var response = await U.ls(PATH.databases(), 'backup');
console.log(response.files);
```

### U.ls2(path, [callback], [filter], [unified])

Type: `method`

Vypíše súbory s ich štatistikami.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Adresár. |
| `callback` | `Function` | no |  | `function(files, directories)`. |
| `filter` | `String|RegExp|Function` | no |  | Filter. |
| `unified` | `Boolean` | no | `false` | Na Windows používa `/`. |

Returns: `Promise|undefined` Promise, keď chýba callback.

Funguje ako `U.ls()`, ale každý súbor je `{ filename, stats }`, kde `stats` je objekt `fs.Stats` (veľkosť, dátumy). Adresáre sú stále cesty.

Example: Celková veľkosť
```js
U.ls2(PATH.temp(), function(files) {
	var size = 0;
	for (var file of files)
		size += file.stats.size;
	console.log(size.filesize());
});
```

### U.encode(value)

Type: `method`

Zakóduje špeciálne HTML znaky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |

Returns: `String`

`null` a `undefined` dajú prázdny reťazec; iné hodnoty sa najprv prevedú na reťazec. Volá `String.encode()`.

Example: Bezpečné HTML
```js
U.encode('<b>'); // '&lt;b&gt;'
```

### U.decode(value)

Type: `method`

Dekóduje HTML entity späť na znaky.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |

Returns: `String`

Opak `U.encode()`. `null` a `undefined` dajú prázdny reťazec.

Example: Čistý text
```js
U.decode('&lt;b&gt;'); // '<b>'
```

### U.btoa(value)

Type: `method`

Zakóduje reťazec alebo Buffer do Base64.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Buffer` | yes |  | Hodnota. |

Returns: `String`

`U.atob(value)` dekóduje Base64 späť na UTF-8 reťazec.

Example: Base64
```js
var encoded = U.btoa('hi'); // 'aGk='
var text = U.atob(encoded); // 'hi'
```

### U.parseXML(xml, [replace])

Type: `method`

Spracuje XML do plochého objektu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `xml` | `String` | yes |  | XML. |
| `replace` | `Boolean` | no | `false` | Nahradí špeciálne znaky v kľúčoch. |

Returns: `Object`

Každý kľúč je cesta elementu spojená bodkami, napríklad `root.item`; opakované elementy dajú pole hodnôt. Atribúty sa ukladajú pod kľúčom s `[]`, napríklad `root.item[]`. S `replace` nastaveným na `true` sa znaky `[`, `]`, `:`, `.` a `_` v kľúčoch zmenia na `_`. CDATA sa číta ako text.

Example: Čítanie XML
```js
var obj = U.parseXML('<root><item id="1">A</item><item>B</item></root>');
// { 'root.item[]': { id: '1' }, 'root.item': ['A', 'B'] }
```

### U.parseInt(value, [def])

Type: `method`

Prevedie ľubovoľnú hodnotu na celé číslo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |
| `def` | `Number` | no | `0` | Hodnota pre prázdny alebo neplatný vstup. |

Returns: `Number`

`null`, `undefined` a prázdny reťazec dajú `def`. Číslo sa vráti tak, ako je. `U.parseFloat(value, [def])` a `U.parseBoolean(value, [def])` fungujú rovnako pre desatinné čísla a booleany (`def` je pre booleany `false`; číslo je `true`, keď je väčšie ako 0).

Example: Hodnoty z query
```js
var page = U.parseInt(this.query.page, 1);
var price = U.parseFloat(this.query.price);
var active = U.parseBoolean(this.query.active);
```

### U.distance(lat1, lon1, lat2, lon2)

Type: `method`

Vráti vzdialenosť medzi dvoma GPS súradnicami v kilometroch.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `lat1` | `Number` | yes |  | Zemepisná šírka prvého bodu. |
| `lon1` | `Number` | yes |  | Zemepisná dĺžka prvého bodu. |
| `lat2` | `Number` | yes |  | Zemepisná šírka druhého bodu. |
| `lon2` | `Number` | yes |  | Zemepisná dĺžka druhého bodu. |

Returns: `Number` Kilometre.

Používa haversinový vzorec na guli s polomerom 6371 km; výsledok má najviac 3 desatinné miesta.

Example: Bratislava – Praha
```js
U.distance(48.1486, 17.1077, 50.0755, 14.4378); // 289.225
```

### U.minify_css(value)

Type: `method`

Minifikuje CSS vstavaným kompilátorom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | CSS kód. |

Returns: `String`

Ten istý kompilátor, ktorý framework používa pre statické súbory `.css`.

Example: Minifikácia
```js
U.minify_css('a { color: red; }'); // 'a{color:red}'
```

### U.minify_js(value)

Type: `method`

Minifikuje JavaScript vstavaným kompilátorom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | JavaScript kód. |

Returns: `String`

Odstráni komentáre a biele znaky. Ten istý kompilátor, ktorý framework používa pre statické súbory `.js`.

Example: Minifikácia
```js
U.minify_js('var a = 1;  // note');
```

### U.minify_html(value)

Type: `method`

Minifikuje HTML vstavaným kompilátorom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | HTML kód. |

Returns: `String`

Odstráni biele znaky medzi tagmi.

Example: Minifikácia
```js
U.minify_html('<div>  <b>x</b>  </div>'); // '<div><b>x</b></div>'
```

### STATUS(id, data, [timeout])

Type: `method` · Since: `0.0.63`

Uloží pomenovaný stav tvojej aplikácie a odovzdá ho do `DEF.onStatus(meta)`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String|Object` | yes |  | Názov stavu, alebo objekt `$`. |
| `data` | `Object` | yes |  | Ľubovoľná hodnota. |
| `timeout` | `Number` | no |  | Oneskorí aktualizáciu a zlúči volania počas tohto času, v milisekundách. |

Returns: `undefined` Nič.

Každé `id` má jeden objekt stavu `{ id, data, date }`. `STATUS()` nahradí jeho `data`, nastaví `date` a zavolá `DEF.onStatus(meta)`, keď ho definuješ. Namiesto `id` môžeš odovzdať objekt `$`; jeho `ID` (alebo `name`) je id.

S `timeout` (v milisekundách) sa aktualizácia oneskorí: prvé volanie spustí časovač, neskoršie volania iba menia `data` a `DEF.onStatus()` sa spustí raz s poslednými dátami, keď časovač skončí. Použi to pre hodnoty, ktoré sa často menia, napríklad priebeh.

S `CONF.allow_stats_status` (predvolene `true`) sa všetky stavy pridajú ako `status` do snapshotu štatistík, ktorý Total.js zapisuje do `<main script>.json` (`CONF.allow_stats_snapshot`).

Example: Priebeh importu
```js
DEF.onStatus = function(meta) {
	console.log(meta.id, meta.data, meta.date);
};

for (var i = 0; i < items.length; i++)
	STATUS('import', { done: i + 1, total: items.length }, 1000);
```

### U.encrypt_data(value, key, [encode])

Type: `method`

Zašifruje reťazec kľúčom a náhodnou maskou.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Text na zašifrovanie. |
| `key` | `String` | yes |  | Kľúč. |
| `encode` | `String` | no | `base64` | Kódovanie Buffera alebo `buffer`. |

Returns: `String|Buffer` Zašifrovaná hodnota.

Výstup sa mení pri každom volaní kvôli náhodnej 4-bajtovej maske. `encode` je kódovanie Buffera (predvolene `base64`); `buffer` vráti surový Buffer. Späť ho prečítaš cez `U.decrypt_data()` s rovnakým kľúčom. Je to ľahká obfuskácia, nie náhrada za `U.encrypt_crypto()`.

Example: Zašifrovanie JSON reťazca
```js
var token = U.encrypt_data(JSON.stringify({ id: user.id }), CONF.secret);
```

### U.decrypt_data(value, key, [encode])

Type: `method`

Dešifruje hodnotu vytvorenú cez `U.encrypt_data()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Buffer` | yes |  | Zašifrovaná hodnota. |
| `key` | `String` | yes |  | Kľúč použitý pri šifrovaní. |
| `encode` | `String` | no | `base64` | Kódovanie `value`. |

Returns: `String` Dešifrovaný text alebo `null`.

`value` je reťazec v kódovaní `encode` (predvolene `base64`) alebo Buffer. Vráti `null`, keď sa hodnota nedá prečítať. Nesprávny kľúč dá nesprávny reťazec, nie `null`, preto výsledok skontroluj (napríklad cez `parseJSON()`).

Example: Dešifrovanie tokenu
```js
var data = (U.decrypt_data(token, CONF.secret) || '').parseJSON();
if (!data)
	return $.invalid(401);
```

### U.encrypt_crypto(type, key, value)

Type: `method`

Zašifruje dáta šifrou Node.js.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Názov šifry, napríklad `aes-256-cbc`. |
| `key` | `String` | yes |  | Kľúč. |
| `value` | `String|Buffer` | yes |  | Dáta. |

Returns: `Buffer` Zašifrované dáta.

Používa `Crypto.createCipheriv(type, key, CONF.default_crypto_iv)`. Dĺžka kľúča musí zodpovedať šifre (32 znakov pre `aes-256-cbc`). `CONF.default_crypto_iv` sa predvolene vytvára z aplikácie, preto ho nastav v konfigurácii, keď majú dáta dešifrovať iné aplikácie.

Example: AES
```js
var key = 'a6e4c7d1b9f2038e5a7c1d4b6e8f0a2c';
var buffer = U.encrypt_crypto('aes-256-cbc', key, 'Hello');
var text = buffer.toString('base64');
```

### U.decrypt_crypto(type, key, value)

Type: `method`

Dešifruje dáta vytvorené cez `U.encrypt_crypto()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Názov šifry. |
| `key` | `String` | yes |  | Kľúč. |
| `value` | `Buffer` | yes |  | Zašifrované dáta. |

Returns: `Buffer` Dešifrované dáta alebo `undefined`.

Používa `Crypto.createDecipheriv(type, key, CONF.default_crypto_iv)`. Vráti `undefined`, keď sa dáta nedajú dešifrovať.

Example: AES
```js
var buffer = U.decrypt_crypto('aes-256-cbc', key, Buffer.from(text, 'base64'));
buffer && console.log(buffer.toString('utf8'));
```

### U.convert62(number)

Type: `method` · Since: `0.0.85`

Prevedie číslo na reťazec v sústave 62.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `number` | `Number` | yes |  | Kladné číslo. |

Returns: `String`

Abecedu tvoria číslice, potom veľké a malé písmená. Desatinné miesta sa zaokrúhlia nadol. Späť ho prečítaš cez `U.from62()`.

Example: Krátky kód
```js
U.convert62(123456789); // '8M0kX'
```

### U.from62(value)

Type: `method` · Since: `0.0.85`

Prevedie reťazec v sústave 62 z `U.convert62()` späť na číslo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Reťazec v sústave 62. |

Returns: `Number`

Example: Späť na číslo
```js
U.from62(U.convert62(1000)); // 1000
```

### U.groupify(id, [count])

Type: `method` · Since: `0.0.88`

Vráti číselnú skupinu pevnej dĺžky pre identifikátor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | Identifikátor. |
| `count` | `Number` | no | `4` | Počet číslic. |

Returns: `String` Reťazec číslic.

Hodnota je `HASH(id, true)` modulo `10^count`, doplnená nulami na `count` číslic. Rovnaké id dá vždy rovnakú skupinu, takže je to užitočné na rozdelenie súborov do podadresárov.

Example: Podadresáre
```js
var id = UID();
var filename = PATH.databases('files/' + U.groupify(id) + '/' + id + '.json');
```

### U.parseBoolean(value, [def])

Type: `method`

Prevedie ľubovoľnú hodnotu na boolean.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |
| `def` | `Boolean` | no | `false` | Predvolená hodnota. |

Returns: `Boolean`

Boolean sa vráti tak, ako je, číslo je `true`, keď je väčšie ako `0`, iné hodnoty sa prevedú na reťazec a spracujú cez `String.parseBoolean()`. `null` a `undefined` vrátia `def`.

Example: Hodnota z query
```js
var active = U.parseBoolean($.query.active);
```

### U.parseFloat(value, [def])

Type: `method`

Prevedie ľubovoľnú hodnotu na desatinné číslo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |
| `def` | `Number` | no | `0` | Predvolená hodnota. |

Returns: `Number`

Číslo sa vráti tak, ako je, iné hodnoty sa prevedú na reťazec a spracujú cez `String.parseFloat()`. `null`, `undefined` a prázdny reťazec vrátia `def`.

Example: Cena
```js
var price = U.parseFloat(model.price, 0);
```

### U.isDate(value)

Type: `method`

Skontroluje, či je hodnota platný `Date`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object` | yes |  | Hodnota. |

Returns: `Boolean`

Vráti `false` pre neplatný dátum ako `new Date('abc')`.

Example: Validácia dátumu
```js
U.isDate(new Date()); // true
U.isDate(new Date('abc')); // false
U.isDate('2024-01-01'); // false
```

### U.DAYS

Type: `property`

Anglické názvy dní v týždni.

Returns: `String Array`

Pole začína `Sunday`, takže zodpovedá `Date.getDay()`.

Example: Názov dňa
```js
var name = U.DAYS[new Date().getDay()];
```

### U.MONTHS

Type: `property`

Anglické názvy mesiacov.

Returns: `String Array`

Pole začína `January`, takže zodpovedá `Date.getMonth()`.

Example: Názov mesiaca
```js
var name = U.MONTHS[new Date().getMonth()];
```

### U.httpstatus(code, [addCode])

Type: `method`

Vráti text HTTP stavového kódu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `Number` | yes |  | HTTP stavový kód. |
| `addCode` | `Boolean` | no | `true` | Pridá kód k textu. |

Returns: `String`

Text pochádza z `http.STATUS_CODES`. S `addCode` (predvolene `true`) sa kód pridá na začiatok.

Example: Text stavu
```js
U.httpstatus(404); // '404: Not Found'
U.httpstatus(404, false); // 'Not Found'
```

### U.toURLEncode(obj)

Type: `method`

Serializuje objekt do URL-kódovaného query stringu.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | Objekt. |

Returns: `String` Napríklad `q=total&page=2`.

Reťazce sa zakódujú cez `encodeURIComponent()`, čísla a booleany sa pridajú tak, ako sú, polia sa spoja cez `,`. `null`, `undefined`, prázdne reťazce a iné objekty (vrátane dátumov) sa preskočia. Vráti prázdny reťazec, keď sa nič nepridá.

Example: Query string
```js
var url = 'https://example.com/api/?' + U.toURLEncode({ q: 'total js', page: 2, tags: ['a', 'b'] });
// q=total%20js&page=2&tags=a%2Cb
```

### U.atob(value)

Type: `method`

Dekóduje base64 reťazec na UTF-8 reťazec.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | Base64 reťazec. |

Returns: `String`

Opak `U.btoa()`.

Example: Dekódovanie
```js
U.atob(U.btoa('Hello')); // 'Hello'
```

### U.isrelative(url)

Type: `method`

Skontroluje, či je URL relatívna.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | URL. |

Returns: `Boolean`

Vráti `false`, keď URL začína `//` alebo obsahuje `http://` či `https://`.

Example: Bezpečné presmerovanie
```js
var url = $.query.redirect || '/';
if (!U.isrelative(url))
	url = '/';
$.redirect(url);
```

### U.isStaticFile(url)

Type: `method`

Skontroluje, či URL vyzerá ako súbor.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | Cesta URL. |

Returns: `Boolean`

Vráti `true`, keď posledných 8 znakov URL obsahuje bodku, napríklad `/img/logo.png`.

Example: Súbor alebo routa
```js
U.isStaticFile('/img/logo.png'); // true
U.isStaticFile('/api/users/'); // false
```

### U.resolve(url, [callback], [param])

Type: `method`

Zistí IPv4 adresu URL a uloží ju do cache.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | URL. |
| `callback` | `Function` | no |  | `function(err, uri, param, addresses)`. |
| `param` | `Object` | no |  | Hodnota odovzdaná callbacku. |

Returns: `Array|undefined` Adresy z cache, keď nie je zadaný callback.

`callback(err, uri, param, addresses)` dostane spracovanú URL s `uri.host` nahradeným prvou adresou. Adresy sa ukladajú do cache pre každý host; bez callbacku metóda vráti adresy z cache (alebo `undefined`). Neúspešné vyhľadanie sa skúsi ešte raz. Príkaz `clear_dnscache` vymaže cache.

Example: DNS vyhľadanie
```js
U.resolve('https://www.totaljs.com', function(err, uri, param, addresses) {
	console.log(err, addresses);
});
```

### U.link(path1, [path2], [...])

Type: `method` · Since: `0.0.39`

Spojí časti URL s presne jednou `/` medzi nimi.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Jedna alebo viac častí URL. |

Returns: `String`

Na rozdiel od `U.join()` nepridáva úvodnú `/` a časti ponechá tak, ako sú.

Example: Zostavenie URL
```js
U.link('https://example.com/', '/api/', 'users'); // 'https://example.com/api/users'
```

### U.normalize(path)

Type: `method` · Since: `0.0.39`

Pridá `/` na začiatok a koniec cesty, keď chýba.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Cesta. |

Returns: `String`

Example: Normalizácia
```js
U.normalize('admin'); // '/admin/'
```

### U.path(path, [delimiter])

Type: `method`

Pridá ku ceste koncový oddeľovač, keď chýba.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Cesta. |
| `delimiter` | `String` | no | `/` | Oddeľovač. |

Returns: `String`

Prázdna cesta vráti oddeľovač.

Example: Cesta k adresáru
```js
U.path('/www/app'); // '/www/app/'
```

### U.getExtensionFromContentType(contentType)

Type: `method` · Since: `0.0.63`

Vráti príponu súboru pre content type.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `contentType` | `String` | yes |  | Content type. |

Returns: `String`

Prehľadá content typy známe pre `U.getContentType()` (vrátane tých pridaných cez `U.setContentType()`). Vráti prvú zhodu bez bodky, alebo `undefined`.

Example: Prípona
```js
U.getExtensionFromContentType('image/png'); // 'png'
```

### U.ObjectToArray(obj)

Type: `method`

Prevedie objekt na pole položiek `{ key, value }`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | yes |  | Objekt. |

Returns: `Array`

`null` alebo `undefined` vráti `EMPTYARRAY`.

Example: Zoznam kľúč-hodnota
```js
U.ObjectToArray({ a: 1, b: 2 }); // [{ key: 'a', value: 1 }, { key: 'b', value: 2 }]
```

### U.createBuffer([value], [encoding])

Type: `method`

Skratka pre `Buffer.from(value || '', encoding)`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String|Array|Buffer` | no | `''` | Dáta. |
| `encoding` | `String` | no | `utf8` | Kódovanie reťazca. |

Returns: `Buffer`

Example: Z base64
```js
var buffer = U.createBuffer(body, 'base64');
```

### U.createBufferSize([size])

Type: `method`

Skratka pre `Buffer.alloc(size || 0)`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `size` | `Number` | no | `0` | Veľkosť v bajtoch. |

Returns: `Buffer` Buffer vyplnený nulami.

Example: Prázdny buffer
```js
var buffer = U.createBufferSize(4);
buffer.writeInt32BE(100);
```

### U.json2replacer(key, value)

Type: `method`

Replacer pre `JSON.stringify()`, ktorý odstraňuje hodnoty `null` a `undefined`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | Kľúč. |
| `value` | `Object` | yes |  | Hodnota. |

Returns: `Object`

Example: Menší JSON
```js
JSON.stringify({ id: 1, name: null }, U.json2replacer); // '{"id":1}'
```

### U.queuecache

Type: `property`

Stav front vytvorených cez `U.queue()`.

Returns: `Object`

Objekt s kľúčmi podľa názvu fronty. Každá položka má `limit`, `running` a `pending` (čakajúce callbacky). Čítaj ho iba na monitorovanie.

Example: Čakajúce položky
```js
var item = U.queuecache.import;
item && console.log(item.running, item.pending.length);
```

### new U.EventEmitter2([obj])

Type: `class`

Malý emitor udalostí.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `obj` | `Object` | no |  | Objekt na rozšírenie. |

Returns: `EventEmitter2`

`new U.EventEmitter2()` vytvorí emitor. `U.EventEmitter2(obj)` (bez `new`) pridá `emit()`, `on()`, `once()`, `off()`, `removeListener()` a `removeAllListeners()` do existujúceho objektu a vráti ho; `U.EventEmitter2.extend(obj)` robí to isté. Listenery sa uchovávajú v `$events`. `emit()` odovzdá najviac 7 argumentov a `this` je emitor.

Example: Rozšírenie objektu
```js
var service = {};
U.EventEmitter2(service);
service.on('ready', function(value) {
	console.log('ready', value);
});
service.emit('ready', 1);
```

### emitter.off(name, [fn])

Type: `method` · Since: `0.0.90`

Odstráni listener alebo všetky listenery udalosti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov udalosti. |
| `fn` | `Function` | no |  | Listener. |

Returns: `EventEmitter2` Emitor.

Bez `fn` sa odstránia všetky listenery `name`. `removeListener()` je alias. `removeAllListeners([name])` odstráni listenery jednej udalosti alebo všetkých udalostí.

Example: Odstránenie listenera
```js
var fn = function() {};
emitter.on('change', fn);
emitter.off('change', fn);
```

### U.Callback(count, [callback])

Type: `method`

Zavolá callback po tom, čo bolo `next()` zavolané `count` krát.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `count` | `Number` | yes |  | Na koľko volaní `next()` sa čaká. |
| `callback` | `Function` | no |  | Funkcia na zavolanie. |

Returns: `Callback` Inštancia s `next()` a `done(fn)`.

Vráti inštanciu s `next()` a `done(callback)`. Callback sa spustí raz, keď počet čakajúcich dosiahne nulu. Trieda je dostupná aj ako globálny `Callback`.

Example: Čakanie na 3 úlohy
```js
var cb = U.Callback(3, function() {
	console.log('all done');
});

for (var i = 0; i < 3; i++)
	setTimeout(() => cb.next(), 100 * i);
```

### U.chunker(name, [max])

Type: `method`

Ukladá veľa položiek do dočasných súborov, stránku po stránke.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Unikátny názov, použitý v názvoch súborov. |
| `max` | `Number` | no | `50` | Počet položiek na súbor. |

Returns: `Chunker`

Každých `max` položiek zapísaných cez `write()` ide do jedného súboru `{name}-{index}.chunker` v dočasnom adresári, skomprimovaného cez deflate. Späť ich prečítaš stránku po stránke cez `each()` alebo `read()`. Vlastnosti: `compress` (predvolene `true`), `autoremove` (predvolene `true`, odstráni každý súbor po prečítaní), `count`, `pages` a `percentage` (priebeh `each()`). Trieda je dostupná ako `U.Chunker`.

Example: Export po stránkach
```js
var chunker = U.chunker('export', 100);

for (var item of items)
	chunker.write(item);

chunker.end();

chunker.each(function(items, next, index) {
	console.log('page', index, items.length);
	next();
}, function() {
	console.log('done');
});
```

### chunker.write(item)

Type: `method`

Pridá položku.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `item` | `Object` | yes |  | Položka, ktorú možno serializovať do JSON. |

Returns: `Chunker`

Keď čaká `max` položiek, zapíšu sa do nového súboru. `append()` je alias. Po poslednej položke zavolaj `end()`.

Example: Zápis
```js
chunker.write({ id: 1, name: 'Peter' });
```

### chunker.end()

Type: `method`

Zapíše zostávajúce položky do posledného súboru.

Returns: `Chunker`

Example: Dokončenie zápisu
```js
chunker.end();
```

### chunker.each(onItem, [onEnd])

Type: `method`

Prečíta všetky stránky jednu po druhej.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `onItem` | `Function` | yes |  | `function(items, next, index)`. |
| `onEnd` | `Function` | no |  | Spustí sa po poslednej stránke. |

Returns: `Chunker`

`onItem(items, next, index)` dostane položky jednej stránky; zavolaj `next()` na prečítanie ďalšej stránky. `onEnd()` sa spustí po poslednej stránke. `percentage` ukazuje priebeh.

Example: Spracovanie stránok
```js
chunker.each(function(items, next) {
	items.wait(save, next);
}, () => console.log('done'));
```

### chunker.read(index, callback)

Type: `method`

Prečíta jednu stránku.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `index` | `Number` | yes |  | Index stránky od `0`. |
| `callback` | `Function` | yes |  | `function(err, items)`. |

Returns: `Chunker`

`callback(err, items)` dostane položky stránky, alebo prázdne pole, keď súbor neexistuje. Čaká, kým sa súbory ešte zapisujú.

Example: Prvá stránka
```js
chunker.read(0, function(err, items) {
	console.log(items);
});
```

### chunker.clear()

Type: `method`

Odstráni všetky súbory chunkera.

Returns: `Chunker`

`destroy()` tiež odstráni súbory a uvoľní inštanciu.

Example: Upratanie
```js
chunker.clear();
```

### U.reader([items])

Type: `method`

Dotazuje pole objektov pomocou NoSQL query buildera.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `items` | `Array|Object|String` | no |  | Položky alebo URL. |

Returns: `Reader`

`items` je pole (alebo jeden objekt), alebo URL obsahu TextDB, ktorý sa stiahne a streamuje. Bez `items` pridávaj dáta cez `reader.push(items)` a ukonči cez `reader.push(null)`, alebo použi `reader.stream(stream)`. `find()`, `list()`, `read()`, `count()`, `scalar(type, key, [key2])` a `stats(groupfield, datefield, key, [type])` vracajú NoSQL query builder (`where()`, `sort()`, `take()`, `callback()`...). `list()` vracia `{ page, pages, limit, count, items }`. `assign(data)` vytvorí dotaz zo serializovaného objektu dotazu.

Example: Filtrovanie poľa
```js
var reader = U.reader(users);

reader.find().where('age', '>', 18).sort('name').take(10).callback(function(err, response) {
	console.log(response);
});

reader.count().callback(function(err, response) {
	console.log(response);
});
```

### reader.push(items)

Type: `method`

Pridá položky do readera.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `items` | `Array|Object|null` | yes |  | Dáta, alebo `null` na konci. |

Returns: `undefined`

Odovzdaj pole alebo jeden objekt pre každú časť dát, potom `null` na ukončenie a získanie výsledkov.

Example: Vloženie dát
```js
var reader = U.reader();
reader.find().where('active', true).callback(console.log);
reader.push(page1);
reader.push(page2);
reader.push(null);
```

### U.streamer(beg, [end], callback, [skip], [stream])

Type: `method`

Rozdelí stream častí na kúsky podľa oddeľovačov.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `beg` | `String|Buffer` | yes |  | Oddeľovač alebo začiatok kúsku. |
| `end` | `String|Buffer` | no |  | Koniec kúsku. |
| `callback` | `Function` | yes |  | `function(value, index)`. |
| `skip` | `Number` | no | `0` | Počet kúskov na preskočenie. |
| `stream` | `Stream` | no |  | Stream pre udalosť `end`. |

Returns: `Function` `function(chunk)`.

Vráti `function(chunk)`, ktorej odovzdáš každú časť. Bez `end` každý kúsok končí `beg` (a obsahuje ho), napríklad riadok končiaci `\n`. S `end` každý kúsok začína `beg` a končí `end`. `callback(value, index)` dostane každý kúsok ako reťazec; vráť `false` na zastavenie. `skip` preskočí prvé kúsky. So `stream` sa zostávajúce dáta spracujú pri udalosti `end` streamu. `U.streamer2()` je to isté, ale dáva Buffery.

Example: Čítanie riadkov
```js
var stream = F.Fs.createReadStream(PATH.databases('log.txt'));
stream.on('data', U.streamer('\n', function(line, index) {
	console.log(index, line.trim());
}, stream));
```

### U.streamer2(beg, [end], callback, [skip], [stream])

Type: `method`

To isté ako `U.streamer()`, ale kúsky sú Buffery.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `beg` | `String|Buffer` | yes |  | Oddeľovač alebo začiatok kúsku. |
| `end` | `String|Buffer` | no |  | Koniec kúsku. |
| `callback` | `Function` | yes |  | `function(buffer, index)`. |
| `skip` | `Number` | no | `0` | Počet kúskov na preskočenie. |
| `stream` | `Stream` | no |  | Stream pre udalosť `end`. |

Returns: `Function` `function(chunk)`.

Example: Binárne kúsky
```js
stream.on('data', U.streamer2('<item>', '</item>', function(buffer) {
	console.log(buffer.length);
}));
```

### U.filestreamer(filename)

Type: `method` · Since: `0.0.59`

Číta textový súbor riadok po riadku v dávkach.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | yes |  | Súbor. |

Returns: `Object` Stream reader.

Vráti stream reader TextDB. Nastav `ondocuments` (volá sa s `this.docs`, riadkami jednej dávky spojenými cez `,`; vráť `false` na zastavenie) a `$callback` (volá sa na konci), potom zavolaj `openread()`. Nastav `array = true`, aby si dostal `docs` ako pole riadkov. Riadky, ktoré začínajú `-`, sa preskočia.

Example: Čítanie súboru JSON-lines
```js
var reader = U.filestreamer(PATH.databases('items.nosql'));
reader.ondocuments = function() {
	var items = JSON.parse('[' + reader.docs + ']');
	console.log(items.length);
};
reader.$callback = () => console.log('done');
reader.openread();
```

### PATH.join(path1, [path2], [...])

Type: `method` · Since: `0.0.39`

Alias pre `path.join()` z Node.js.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Jedna alebo viac častí cesty. |

Returns: `String`

Example: Spojenie
```js
var filename = PATH.join(PATH.root(), 'data', 'file.json');
```

### PATH.exists(path, callback)

Type: `method`

Skontroluje, či súbor alebo adresár existuje.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Cesta. |
| `callback` | `Function` | yes |  | `function(exists, size, isFile)`. |

Returns: `undefined`

`callback(exists, size, isFile)`.

Example: Kontrola súboru
```js
PATH.exists(PATH.public('robots.txt'), function(exists, size, isFile) {
	console.log(exists, size, isFile);
});
```

### PATH.verify(name)

Type: `method`

Vytvorí adresár aplikácie, ak neexistuje.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov adresára. |

Returns: `undefined`

`name` je názov nastavenia `CONF.directory_{name}`, napríklad `databases`. Kontrola prebehne raz pre každý názov.

Example: Zabezpečenie existencie adresára
```js
PATH.verify('private');
```

### PATH.ls(path, [callback], [filter], [unified])

Type: `method`

Alias pre `U.ls()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Adresár. |
| `callback` | `Function` | no |  | `function(files, directories)`. |

Returns: `Promise|undefined`

`PATH.ls2()` je alias pre `U.ls2()`.

Example: Výpis súborov
```js
PATH.ls(PATH.private(), function(files) {
	console.log(files);
});
```

### PATH.unlink(files, [callback])

Type: `method`

Odstráni súbory jeden po druhom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `files` | `String|String Array` | yes |  | Súbory. |
| `callback` | `Function` | no |  | Spustí sa na konci. |

Returns: `undefined`

Chyby sa ignorujú.

Example: Odstránenie súborov
```js
PATH.unlink([PATH.temp('a.tmp'), PATH.temp('b.tmp')], () => console.log('removed'));
```

### PATH.rmdir(directories, [callback])

Type: `method`

Odstráni adresáre s celým ich obsahom.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `directories` | `String|String Array` | yes |  | Adresáre. |
| `callback` | `Function` | no |  | Spustí sa na konci. |

Returns: `undefined`

Chyby sa ignorujú.

Example: Odstránenie adresára
```js
PATH.rmdir(PATH.temp('import'), () => console.log('removed'));
```

### PATH.private([filename])

Type: `method`

Vráti cestu v adresári private.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_private` (predvolene `/private/`).

Example: Cesta
```js
var filename = PATH.private('data.json');
```

### PATH.models([filename])

Type: `method`

Vráti cestu v adresári models.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_models` (predvolene `/models/`).

Example: Cesta
```js
var filename = PATH.models('file.js');
```

### PATH.builds([filename])

Type: `method`

Vráti cestu v adresári builds.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_builds` (predvolene `/builds/`).

Example: Cesta
```js
var filename = PATH.builds('file.js');
```

### PATH.views([filename])

Type: `method`

Vráti cestu v adresári views.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_views` (predvolene `/views/`).

Example: Cesta
```js
var filename = PATH.views('index.html');
```

### PATH.updates([filename])

Type: `method`

Vráti cestu v adresári updates.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_updates` (predvolene `/updates/`).

Example: Cesta
```js
var filename = PATH.updates('file.js');
```

### PATH.modules([filename])

Type: `method`

Vráti cestu v adresári modules.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_modules` (predvolene `/modules/`).

Example: Cesta
```js
var filename = PATH.modules('file.js');
```

### PATH.schemas([filename])

Type: `method`

Vráti cestu v adresári schemas.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_schemas` (predvolene `/schemas/`).

Example: Cesta
```js
var filename = PATH.schemas('file.js');
```

### PATH.extensions([filename])

Type: `method`

Vráti cestu v adresári extensions.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_extensions` (predvolene `/extensions/`).

Example: Cesta
```js
var filename = PATH.extensions('file.js');
```

### PATH.operations([filename])

Type: `method`

Vráti cestu v adresári operations.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_operations` (predvolene `/operations/`).

Example: Cesta
```js
var filename = PATH.operations('file.js');
```

### PATH.tasks([filename])

Type: `method`

Vráti cestu v adresári tasks.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_tasks` (predvolene `/tasks/`).

Example: Cesta
```js
var filename = PATH.tasks('file.js');
```

### PATH.controllers([filename])

Type: `method`

Vráti cestu v adresári controllers.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_controllers` (predvolene `/controllers/`).

Example: Cesta
```js
var filename = PATH.controllers('file.js');
```

### PATH.definitions([filename])

Type: `method`

Vráti cestu v adresári definitions.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_definitions` (predvolene `/definitions/`).

Example: Cesta
```js
var filename = PATH.definitions('file.js');
```

### PATH.tests([filename])

Type: `method`

Vráti cestu v adresári tests.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_tests` (predvolene `/tests/`).

Example: Cesta
```js
var filename = PATH.tests('file.js');
```

### PATH.services([filename])

Type: `method`

Vráti cestu v adresári services.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_services` (predvolene `/services/`).

Example: Cesta
```js
var filename = PATH.services('file.js');
```

### PATH.packages([filename])

Type: `method`

Vráti cestu v adresári packages.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_packages` (predvolene `/packages/`).

Example: Cesta
```js
var filename = PATH.packages('file.js');
```

### PATH.themes([filename])

Type: `method`

Vráti cestu v adresári themes.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_themes` (predvolene `/themes/`).

Example: Cesta
```js
var filename = PATH.themes('default/index.html');
```

### PATH.components([filename])

Type: `method`

Vráti cestu v adresári components.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_components` (predvolene `/components/`).

Example: Cesta
```js
var filename = PATH.components('file.js');
```

### PATH.templates([filename])

Type: `method`

Vráti cestu v adresári templates.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_templates` (predvolene `/templates/`).

Example: Cesta
```js
var filename = PATH.templates('email.html');
```

### PATH.plugins([filename])

Type: `method` · Since: `0.0.88`

Vráti cestu v adresári plugins.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_plugins` (predvolene `/plugins/`).

Example: Cesta
```js
var filename = PATH.plugins('file.js');
```

### PATH.flowstreams([filename])

Type: `method`

Vráti cestu v adresári flowstreams.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Názov súboru. |

Returns: `String` Absolútna cesta.

Adresár je `CONF.directory_flowstreams` (predvolene `/flowstreams/`).

Example: Cesta
```js
var filename = PATH.flowstreams('file.js');
```

### OBSOLETE(name, message)

Type: `method`

Vypíše varovanie o zastaranom kóde.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Čo je zastarané. |
| `message` | `String` | yes |  | Čo použiť namiesto toho. |

Zapíše dátum, názov a správu do konzoly a zvýši `F.stats.other.obsolete`. Nič sa nevypíše, keď je `CONF.nowarnings` `true` (framework ho nastaví, keď watcher reštartuje aplikáciu s `--restart`).

Example: Varovanie
```js
function oldsave(model) {
	OBSOLETE('oldsave()', 'Use save() instead.');
	return save(model);
}
```

### UID1([type], [date])

Type: `method`

Vygeneruje jedinečný identifikátor s desiatkovou časovou časťou.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no |  | Názov samostatného počítadla. |
| `date` | `Date` | no | `NOW` | Čas identifikátora. |

Returns: `String` Identifikátor.

Ako `UID()`, ale časová časť je počet minút od 2020-01-31 23:00 UTC zapísaný desiatkovými číslicami. Identifikátory končia písmenom verzie `b`. S `type` má každý typ vlastné počítadlo. `date` vytvorí identifikátor pre iný čas.

Example: Identifikátor
```js
var id = UID1();
var orderid = UID1('orders');
```
