Skip to content

Commit 8d2d352

Browse files
Utility and TextSanitizer class added
1 parent 00df6af commit 8d2d352

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Support Package For PHP and Laravel
7979
* [wrap](#wrap)
8080
* [head](#head)
8181
* [last](#last)
82+
* [TextSanitizer](#TextSanitizer)
83+
* [Usage](#sanitizer-usage)
84+
* [phone](#phone)
8285
* [Country](#country)
8386
* [Usage](#country-usage)
8487
* [iso3](#country-iso3)

src/Str.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,43 @@ public static function text($string = null)
518518
return Tame::text($string);
519519
}
520520

521+
/**
522+
* Shorten String to Given Limit
523+
*
524+
* @param mixed $string
525+
* @param mixed $limit
526+
* @param mixed $replacer
527+
* [optional]
528+
*
529+
* @return string
530+
*/
531+
public static function shorten($string = null, $limit = 50, $replacer = '...')
532+
{
533+
return Tame::shortenString($string, $limit, $replacer);
534+
}
535+
536+
/**
537+
* Filter sanitize string|text
538+
*
539+
* @param string|null $string
540+
* @return string
541+
*/
542+
public static function sanitize($string = null)
543+
{
544+
return Tame::filter_input($string);
545+
}
546+
547+
/**
548+
* Format number to nearest thousand
549+
*
550+
* @param float|int $number
551+
* @return string
552+
*/
553+
public static function toThousand($number = 0)
554+
{
555+
return Tame::formatNumberToNearestThousand($number);
556+
}
557+
521558
/**
522559
* Encrypt string
523560
*
@@ -540,21 +577,6 @@ public static function decrypt($jsonString = null)
540577
return Tame::decryptStr($jsonString);
541578
}
542579

543-
/**
544-
* Shorten String to Given Limit
545-
*
546-
* @param mixed $string
547-
* @param mixed $limit
548-
* @param mixed $replacer
549-
* [optional]
550-
*
551-
* @return string
552-
*/
553-
public static function shorten($string = null, $limit = 50, $replacer = '...')
554-
{
555-
return Tame::shortenString($string, $limit, $replacer);
556-
}
557-
558580
/**
559581
* Get the singular form of a word.
560582
*

src/Tame.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,24 @@ public static function countDivisibleNumbers($index = 100, $amount = 0)
341341
return floor($amount / $index);
342342
}
343343

344+
/**
345+
* Alias for `calculateExponent` method
346+
*
347+
* @param float|int $base The base number.
348+
* @param float|int $exponent The exponent to raise the base to.
349+
* @return float|int
350+
*/
351+
public static function exponent($base = 0, $exponent = 0)
352+
{
353+
return self::calculateExponent($base, $exponent);
354+
}
355+
344356
/**
345357
* Calculate the result of raising a base to an exponent.
346358
*
347359
* @param float|int $base The base number.
348360
* @param float|int $exponent The exponent to raise the base to.
349-
* @return float|int
361+
* @return float|int
350362
* - The result of the exponentiation.
351363
*/
352364
public static function calculateExponent($base = 0, $exponent = 0)
@@ -864,8 +876,9 @@ public static function filter_input($string = null)
864876

865877
/**
866878
* Format number to nearest thousand
879+
*
867880
* @param float|int $number
868-
* @return void
881+
* @return string
869882
*/
870883
public static function formatNumberToNearestThousand(float|int $number = 0)
871884
{

tests/textsanitizer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
Visit https://example.com google.com or mail me at [email protected]. +23409109209
1111
I love #coding with @friends. I also have two cats. 11092092-3";
1212

13-
$text2 = "I'm a beautiful zero nine zero and sweet in seven
14-
five seven eight available from ";
15-
13+
$text2 = "I'm a beautiful zero nine zero and sweet in seven five seven eight available from ";
1614
$text3 = "Reach me on zero eight one double two 555 nine or 0812225559";
1715

1816
dd(

0 commit comments

Comments
 (0)