salient/utils

The utils package of the Salient toolkit

v0.99.54 2024-09-20 02:11 UTC

README

The utils component of the Salient toolkit

Latest Stable Version License CI Status Code Coverage

salient/utils provides a suite of useful utility methods via stateless classes.

  • Arr works with arrays and iterables.

  • Date works with date and time values, timezones and intervals.

  • Debug gets caller information by normalising backtrace data.

  • Env retrieves environment variables, loads values from .env files, and applies values from the environment to the script.

  • File provides methods for filesystem operations that throw exceptions on failure.

  • Format makes data human-readable.

  • Get extracts, converts and generates data. For example:

    • Get::coalesce() replicates the SQL COALESCE() function
    • Get::code() improves upon var_export()
    • Get::copy() gets a deep copy of an object
    • Get::eol() gets a string's end-of-line sequence
    • Get::uuid() generates or converts a UUID
  • Inflect converts English words to different forms, e.g. from singular to plural.

  • Json provides methods for encoding and decoding JSON data that throw exceptions on failure.

  • Package retrieves information from Composer's runtime API, e.g. the name of the root package.

  • Reflect works with PHP's reflection API.

  • Regex provides methods for working with regular expressions that throw exceptions on failure.

  • Str manipulates strings. For example:

    • Str::expandLeadingTabs() expands leading tabs to spaces
    • Str::matchCase() matches the case of one string to another
    • Str::ngrams() gets a string's n-grams
    • Str::snake() converts a string to snake_case
    • Str::splitDelimited() safely splits strings that contain delimiters
  • Sys retrieves information about the runtime environment, and provides a handler for exit signals (SIGTERM, SIGINT and SIGHUP).

  • Test performs tests on values.

Documentation

API documentation for salient/utils tracks the main branch of the toolkit's GitHub repository, where further documentation can also be found.