nette-utils
Provides Nette Utils helper classes. Use when working with Arrays, Strings, Image, Finder, FileSystem, Json, Validators, DateTime, Html element builder, Random, Callback, Type, or SmartObject from nette/utils. Do NOT use for Nette Schema, Nette Forms, Nette Database, Latte filters, or DI configuration.
What this skill does
## Nette Utils
A collection of useful PHP utility classes for everyday tasks.
```shell
composer require nette/utils
```
For detailed references:
- [Arrays, ArrayHash, ArrayList](references/arrays.md)
- [Strings and regex functions](references/strings.md)
- [Image manipulation](references/image.md)
- [File searching with Finder](references/finder.md)
---
## DateTime
Extended `DateTime` class with strict validation and DST fixes.
```php
use Nette\Utils\DateTime;
// Create from various formats
DateTime::from(1138013640); // from timestamp
DateTime::from('2024-02-26 04:15:32'); // from string
DateTime::from($dateTimeInterface); // from object
// Create from parts (throws on invalid date)
DateTime::fromParts(2024, 2, 26, 4, 15);
// Immutable modification
$clone = $original->modifyClone('+1 day');
// Convert relative time to seconds
DateTime::relativeToSeconds('10 minutes'); // 600
DateTime::relativeToSeconds('-1 hour'); // -3600
// JSON serialization (ISO 8601)
echo json_encode($dateTime); // "2024-02-26T04:15:32+01:00"
```
---
## Json
Safe JSON encoding/decoding with exceptions.
```php
use Nette\Utils\Json;
// Encode
$json = Json::encode($data);
$json = Json::encode($data, pretty: true); // formatted
$json = Json::encode($data, asciiSafe: true); // escape unicode
$json = Json::encode($data, htmlSafe: true); // escape < > &
$json = Json::encode($data, forceObjects: true); // arrays as objects
// Decode
$data = Json::decode($json); // returns stdClass
$data = Json::decode($json, forceArray: true); // returns array
// Both throw Nette\Utils\JsonException on error
```
---
## Validators
Value validation and type checking.
```php
use Nette\Utils\Validators;
// Type checking
Validators::is($value, 'int'); // true/false
Validators::is($value, 'int|string|bool'); // union types
Validators::is($value, 'int:0..100'); // range
Validators::is($value, 'string:10..20'); // length range
Validators::is($value, 'array:1..5'); // count range
// Specific validators
Validators::isEmail('[email protected]'); // true
Validators::isUrl('https://nette.org'); // true
Validators::isUri('mailto:[email protected]'); // true
Validators::isNumeric('123'); // true (string number)
Validators::isNumericInt('123'); // true (string integer)
Validators::isUnicode($string); // valid UTF-8?
Validators::isInRange($value, [0, 100]); // in range?
Validators::isNone($value); // 0, '', false, null, []?
// Assertion (throws on failure)
Validators::assert($value, 'string:5..10');
Validators::assertField($array, 'key', 'int');
```
### Expected Types
| Type | Description |
|------|-------------|
| `int`, `float`, `bool`, `string`, `array`, `null` | PHP types |
| `scalar` | `int\|float\|bool\|string` |
| `list` | indexed array |
| `number` | `int\|float` |
| `numeric` | number or numeric string |
| `unicode` | valid UTF-8 string |
| `email`, `url`, `uri` | format validation |
| `alnum`, `alpha`, `digit`, `lower`, `upper` | character classes |
| `class`, `interface` | existing class/interface |
| `file`, `directory` | existing path |
---
## FileSystem
File operations with exception handling.
```php
use Nette\Utils\FileSystem;
// Read/Write
$content = FileSystem::read('/path/to/file');
FileSystem::write('/path/to/file', $content);
// Read large files line by line
foreach (FileSystem::readLines('/path/to/file') as $line) {
echo $line;
}
// Copy/Move/Delete
FileSystem::copy($source, $target);
FileSystem::rename($source, $target);
FileSystem::delete($path); // works on directories too
// Directory operations
FileSystem::createDir('/path/to/dir');
FileSystem::makeWritable('/path');
// Path utilities
FileSystem::isAbsolute('../path'); // false
FileSystem::normalizePath('/file/../path'); // '/path'
FileSystem::joinPaths('a', 'b', 'file.txt'); // 'a/b/file.txt'
FileSystem::resolvePath('/base', '../file.txt'); // '/file.txt'
FileSystem::unixSlashes('path\\to\\file'); // 'path/to/file'
```
---
## Floats
Safe floating-point comparisons.
```php
use Nette\Utils\Floats;
// Compare floats (handles precision issues)
Floats::isZero(0.0); // true
Floats::areEqual(0.1 + 0.2, 0.3); // true (!)
Floats::isLessThan($a, $b);
Floats::isLessThanOrEqualTo($a, $b);
Floats::isGreaterThan($a, $b);
Floats::isGreaterThanOrEqualTo($a, $b);
// Compare with result
Floats::compare($a, $b); // -1, 0, or 1
```
---
## Random
Cryptographically secure random values.
```php
use Nette\Utils\Random;
// Random string (default: 0-9, a-z)
Random::generate(10); // 'a4b3c2d1e0'
Random::generate(10, 'A-Z'); // 'XYZABCDEF'
Random::generate(10, '0-9A-Za-z'); // 'aB3cD4eF5g'
Random::generate(10, 'A-Za-z!@#$%'); // 'aBc!@Def#$'
```
---
## Paginator
Pagination calculations.
```php
use Nette\Utils\Paginator;
$paginator = new Paginator;
$paginator->setItemCount(100); // total items
$paginator->setItemsPerPage(10);
$paginator->setPage(3);
echo $paginator->getPageCount(); // 10
echo $paginator->getOffset(); // 20 (for SQL OFFSET)
echo $paginator->getLength(); // 10 (for SQL LIMIT)
echo $paginator->isFirst(); // false
echo $paginator->isLast(); // false
```
---
## Html
HTML element builder.
```php
use Nette\Utils\Html;
// Create element
$el = Html::el('a', ['href' => 'https://nette.org']);
$el->setText('Nette');
echo $el; // <a href="https://nette.org">Nette</a>
// Fluent interface
$el = Html::el('div')
->id('container')
->class('main active')
->data('id', 123)
->setHtml('<p>Content</p>');
// Shorthand
Html::el('input', ['type' => 'text', 'name' => 'email']);
Html::el('div class="box"'); // from string
```
---
## Callback
Working with PHP callables.
```php
use Nette\Utils\Callback;
// Normalize to closure
$closure = Callback::closure($callable);
$closure = Callback::closure($obj, 'method');
$closure = Callback::closure('Class::method');
// Check validity
Callback::check($callable); // throws if invalid
// Invoke with exception wrapping
Callback::invokeSafe($callable, $args, $onError);
// Reflection
$reflection = Callback::toReflection($callable);
```
---
## Type
PHP type utilities.
```php
use Nette\Utils\Type;
// Get type from reflection
$type = Type::fromReflection($reflectionProperty);
$type = Type::fromReflection($reflectionParameter);
// Parse type string
$type = Type::fromString('int|string|null');
// Type info
$type->getSingleName(); // 'int' or null if union
$type->getNames(); // ['int', 'string', 'null']
$type->isUnion(); // true
$type->isIntersection(); // false
$type->isBuiltin(); // true
$type->allowsNull(); // true
$type->isClass(); // false
```
---
## SmartObject Trait
Modern PHP object features for classes.
```php
use Nette\SmartObject;
class MyClass
{
use SmartObject;
private string $name;
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
}
$obj = new MyClass;
$obj->name = 'John'; // calls setName()
echo $obj->name; // calls getName()
```
### Online Documentation
For detailed information, use WebFetch on these URLs:
- [Arrays](https://doc.nette.org/en/utils/arrays) – array helpers
- [Strings](https://doc.nette.org/en/utils/strings) – string functions and regex
- [Images](https://doc.nette.org/en/utils/images) – image manipulation
- [FileSystem](https://doc.nette.org/en/utils/filesystem) – file operations
- [Finder](https://doc.nette.org/en/utils/finder) – file searching
- [JSON](https://doc.nette.org/en/utils/json) – safe JSON handling
- [Validators](https://doc.nette.org/en/utils/validators) – type checking and validation
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.