hatamiarash7/laravel-utils

v1.1 2019-06-27 19:27 UTC

This package is auto-updated.

Last update: 2024-09-15 19:35:00 UTC


README

Packagist Version BCH compliance

laravel的有用函数。

安装

composer require hatamiarash7/laravel-utils dev-master # Latest version
composer require hatamiarash7/laravel-utils            # Stable version

使用方法

每个目的都有一个单独的类。数组,字符串,…请查看每个类的示例。

字符串函数

use Hatamiarash7\Utils\StringUtils;


// Remove given words from a string. Pass them as array.
StringUtils::removeWords($words, $string);

// Return length of string. Normal or UTF-8.
StringUtils::len($string);

// Convert all characters to lowercase.
StringUtils::lowercase($string);

// Convert all characters to uppercase.
StringUtils::uppercase($string);

// Count the number of substring occurrences.
StringUtils::subCount($haystack, $needle);

// Summarize a string by limit. You can use end string for summarized string.
StringUtils::summarize($content, $max_characters = 100, $append = " ...")

// Convert English letters to Persian.
StringUtils::toPersian($expression)

// Convert numeral string to Persian price format.
StringUtils::toPersianPrice($expression)

数组函数

use Hatamiarash7\Utils\ArrayUtils;


// Remove the duplicates from an array.
ArrayUtils::unique($array, $keepKeys = false);

// Check is key exists and return value.
ArrayUtils::key($key, $array, $returnValue = false);

// Check is value exists in the array and return key.
ArrayUtils::exists($value, array $array, $returnKey = false);

// Returns the first element in an array.
ArrayUtils::first(array $array);

// Returns the last element in an array.
ArrayUtils::last(array $array);

// Returns the first key in an array.
ArrayUtils::firstKey(array $array);

// Returns the last key in an array.
ArrayUtils::lastKey(array $array);

// Searches for a given value in an array of arrays, objects and scalar values.
ArrayUtils::search(array $array, $search);

// Add a prefix to each key of array.
ArrayUtils::addPrefix(array $array, $prefix);

变量函数

use Hatamiarash7\Utils\VariableUtils;


// Smart convert string to int.
ArrayUtils::int($value);

// Return only digits chars of a string.
ArrayUtils::digits($value);

测试

所有测试都是使用orchestral的测试框架编写的。

检查并运行它们以获取有关函数的更多信息。

支持

ko-fi

贡献

如果您想添加新函数(甚至一个新类)

  1. Fork 仓库!
  2. 创建您的功能分支: git checkout -b my-new-functions
  3. 提交您的更改: git commit -am '添加一些函数'
  4. 将更改推送到分支: git push origin my-new-functions
  5. 提交拉取请求:D

问题

每个项目可能有很多问题。通过报告这些问题来为该项目的更好发展做出贡献。