<?php

namespace App\Support;

class Str
{
    public static function slug(string $value): string
    {
        $value = strtolower(trim($value));
        $value = preg_replace('/[^a-z0-9]+/', '-', $value) ?: '';
        return trim($value, '-') ?: 'user';
    }

    public static function random(int $length = 40): string
    {
        return bin2hex(random_bytes((int)ceil($length / 2)));
    }
}
