定制 creativestyle/utilities 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

creativestyle/utilities

最新稳定版本:v3.0.1

Composer 安装命令:

composer require creativestyle/utilities

包简介

Static method utilities collection with high reusability

README 文档

README

Build Status

Common PHP Utilities Library

A collection of utility methods for Strings, Arrays and Numbers. A must-have in most projects.

Installation

composer require creativestyle/utilities

ArrayHelpers

pickColumn(array $table, $column)

Assuming that you've got an array of associate arrays ($table) this method will return a single-dimensional array with values of the selected key ($column).

pick(array $keys, array $subject)

Picks selected $keys from the $subject associative array.

map(array $arr, $callback)

Maps the array allowing you to change the keys.

Callback is called with ($key, $value) parameters and shall return a [$newkey => $newvalue] array.

It's possible to map a single entry to multiple by returning more than one item from the $callback.

average(array $arr, $key = null)

Averages array values. If key is set then the column indicated by key is averaged.

RandHelpers

seed()

Returns long string of digits.

randBool($trueChance)

Returns random bool with $trueChance [0, 1] of returning true.

arrayRand(array $array)

Returns random array element.

sample(array $array, $count = 1)

Returns $count unique random elements from the $array.

If the desired number of results is equal or greater to the array size then the array is shuffled. If it's less or equal to 0, then empty array is returned.

gaussianRand($mu, $sigma)

Returns a random number from gaussian distribution with desired params.

normalProbabilityDensity($x, $mu, $sigma)

Returns a random number from normal distribution with desired params.

StringHelpers

urlize($text)

Transliterates the text keeping only alphanumeric characters and -. Whitespace is collapsed and transformed to -.

slugify($text)

Alias to urlize().

joinNotEmpty(array $elements, $delimiter = ', ')

Behaves the same way as implode but skips empty array elements.

endsWith($haystack, $needle)

Checks if $haystack ends with $needle.

startsWith($haystack, $needle)

Checks if $haystack starts with $needle.

convertToTitleCase($string)

Converts the string To The Title Case.

capitalize($string)

Capitalizes the string (same as ucfirst) in a multibyte-safe manner.

humanize($text)

Humanizes a camelCase variable name. For example virtualRealityInterposer will become Virtual reality interposer.

humanizeConst($constName)

Works similar to humanize but converts const names like VIRTUAL_REALITY_INTERPOSER.

isCoercibleToString($value)

Returns true if the value can be converted to string (is a scalar or has __toString method).

统计信息

  • 总下载量: 704
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-16