{"id":18463721,"url":"https://github.com/commandstring/utils","last_synced_at":"2025-04-08T07:32:46.623Z","repository":{"id":63925654,"uuid":"571841826","full_name":"CommandString/Utils","owner":"CommandString","description":"Utilities used in some of my other packages","archived":true,"fork":false,"pushed_at":"2023-08-26T13:01:44.000Z","size":49,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T19:27:35.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CommandString.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-29T01:57:52.000Z","updated_at":"2025-02-18T01:13:08.000Z","dependencies_parsed_at":"2023-02-04T17:31:06.576Z","dependency_job_id":null,"html_url":"https://github.com/CommandString/Utils","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommandString%2FUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CommandString","download_url":"https://codeload.github.com/CommandString/Utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796336,"owners_count":20997553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T09:07:47.430Z","updated_at":"2025-04-08T07:32:46.265Z","avatar_url":"https://github.com/CommandString.png","language":"PHP","readme":"\n\n# CommandString/Utils #\nBasic utility functions for PHP\n\n# ArrayUtils #\n\n```php\ntoStdClass(array $array): stdClass\n```\n\nConverts array to an stdClass\n\n```php\n$users = [\n    \"value\" =\u003e [\n        \"users\" =\u003e [\n            [\n                \"username\" =\u003e \"user\",\n                \"password\" =\u003e \"********\",\n                \"email\" =\u003e \"user@example.com\"\n            ]\n        ]\n    ],\n    \"token\" =\u003e \"********************************\"\n];\n\n$users = ArrayUtils::toStdClass($users);\n\nvar_dump($users);\n/* output\nobject(stdClass)#2 (2) {\n    [\"value\"]=\u003e\n    object(stdClass)#4 (1) {\n        [\"users\"]=\u003e\n        object(stdClass)#5 (1) {\n        [\"0\"]=\u003e\n        object(stdClass)#6 (3) {\n            [\"username\"]=\u003e\n            string(4) \"user\"\n            [\"password\"]=\u003e\n            string(8) \"********\"\n            [\"email\"]=\u003e\n            string(16) \"user@example.com\"\n        }\n        }\n    }\n    [\"token\"]=\u003e\n    string(32) \"********************************\"\n}\n*/\n```\n---\n```php\nrandomize(array $array): array\n```\n\nrandomizes the given array\n\n```php\n$characters = str_split(\"Command_String\");\n$randomized_characters = ArrayUtils::randomize($characters);\n\nforeach ($randomized_characters as $character) {\n    echo $character;\n}\n```\n\n# StringUtils\n\n```php\ngetBetween(string $start, string $end, string $string, bool $include_start_end_with_response = false): string\n```\n\nGets text between to specified points in a string and returns it.\n\n```php\n$greeting = \"My name is Bob! What's yours?\";\n\n$name = StringUtils::getBetween(\"is \", \"!\", $greeting);\n\necho $name; // output: Bob\n```\n\n***If*** you want the start and end to be returned you can set the fourth argument to true, a good use case for this would be parsing a json string out of a blob of text\n\n```php\n$text = 'fdsjhyasdfuygfdsuygfduygfsd{\"name\": \"Bob\"}asduygasduyauysduytasduy?';\n\n$json = StringUtils::getBetween(\"{\", \"}\", $text, true);\n\necho $json; // output: {\"name\": \"Bob\"}\n\nvar_dump(json_decode($json)); \n/* output: \nobject(stdClass)#3 (1) {\n  [\"name\"]=\u003e\n  string(5) \"Bob\"\n}\n*/\n```\n\n# GeneratorUtils\n\n```php\nuuid(int $length = 16, array $characters = []): string\n```\n\nGenerates a UUID.\n\nGenerically the method will return a 16 character alphanumeric string \n\n```php\necho GeneratorUtils::uuid(); // output: 6MwqCff0wdpUl1sdw\n```\n\nYou can adjust the length as needed\n\n```php\necho GeneratorUtils::uuid(5); // output: 8zWgWw\n```\n\nYou can also supply characters for the generator to use\n\n```php\necho GeneratorUtils::uuid(10, [1, 0]); // output: 11110100100\n```\n\n# FileSystemUtils \n\n```php\ngetAllFiles(string $directory, bool $recursive = false): array\n```\n\nGet all files in a directory, if the second parameter is true then files in subdirectories will be included in the returned array\n\n---\n\n```php\ngetAllSubDirectories(string $directory, bool $recursive = false): array\n```\n\nGet all subdirectories in a directory and if recursive is true all subdirectories of the subdirectories will be included\n\n---\n\n```php\ngetAllFilesWithExtensions(string $directory, array $extensionsToFind, bool $recursive = false): array\n```\n\nGet all files in a directory with one of the supplied extensions. If the third parameter is true then the directories' subdirectories will be searched as well.\n\n---\n\n# ColorUtils\n\n```php\nRGBAtoHEX(int $red, int $blue, int $green, ?int $alpha = null): string\n```\n\nConverts a RGBA color code to a HEX color code\n\n---\n\n```php\nHEXtoRGBA(string $hex): array\n```\n\nConverts a HEX color code to a RGBA color code.\n\n---\n\n# FileSizeUtils\n\n```php\nconvertFileSize(FileSizeUtils $from_type, FileSizeUtils $to_type, float $from_size): float\n```\n\nConvert a file size from one type to another\n\n---\n\n```php\nhumanReadable(FileSizeUtils $type, float $size, int $decimals = 0): string\n```\n\nCreates reduces the format that appends to type abbreviation to the end.\n\n```php\necho FileSizeUtils::humanReadable(FileSizeUtils::MEGABYTE, 5000); // output: 5 GB\n```\n\n---\n\n```php\nreduceFileSize(FileSizeUtils $type, float $size): stdClass\n```\n\nReduces a file size to the smallest it can be before being smaller than 1. An stdClass with a type property is then returned alongside a size property for the new size.\n\n```php\nvar_dump(FileSizeUtils::humanReadable(FileSizeUtils::MEGABYTE, 5000));\n/**\n *  object(stdClass)#12 (2) {\n *  [\"type\"]=\u003e\n *      enum(CommandString\\Utils\\FileSizeUtils::GIGABYTE)\n *  [\"size\"]=\u003e\n *      float(5)\n *  }\n */\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Futils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommandstring%2Futils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommandstring%2Futils/lists"}