Some raw and useful helpers functions

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/straylightagency/helpers

dev-main 2026-01-02 14:15 UTC

This package is auto-updated.

Last update: 2026-01-02 14:15:54 UTC


README

Just some raw and useful helpers functions.

Installation

Require this package with composer.

composer require straylightagency/helpers

API Documentation

Format a comma separated float "65,25" into a regular dotted float "65.25", useful for pricing.

price_format(num: mixed, decimals: int = 2, decimal_separator: ?string = ".", thousands_separator: ?string = "" ): float

Check if an int|float value is within a certain bound. If the value is in range it returns the value, if the value is not in range it returns the nearest bound.

clamp(value: int|float, min: int|float, max: int|float): float|int

Get the contents of a svg file, applying a class list on it before returning if $class_list is not null.

svg_get_contents(file_path: string, class_list: ?string = null): string

Convert iso code to emoji.

iso_to_emoji(code: string): string

Same as array_map but the callback get the key associated to the value.

array_map_keys(callback: ?callable, array: array): array

Do a preg_match_all using callback with patterns.

preg_match_callback_array(patterns: array, subject: string): array

Equivalent to array_diff but recursively.

array_recursive_diff(a: array, b: array):array

Ensure the value is an array, otherwise returns an empty array. Avoid foreach error when the value is not an expected array.

array_safe(array: mixed): array

Return a valid Google map url using address information provided. Second parameter itinerary allows to return an itinerary path instead of a pin on the map.

google_map_url(address: array, itinerary: bool = false): string

Find the ID of a video from the Vimeo url. Return null if it failed.

vimeo_id(vimeo_url: string): ?int

Find the ID of a video from the YouTube url. Return null if it failed.

youtube_id(youtube_url: string): ?string

Requirement

PHP 8.3 or above

See also

Credits

License

The MIT License (MIT).