Skip to content

Commit 2d9da00

Browse files
committed
feat(Functions): Added numeric utils
1 parent 0b3eaf9 commit 2d9da00

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"files": [
3434
"xwp-helper-fns.php",
35+
"xwp-helper-fns-num.php",
3536
"xwp-helper-fns-req.php"
3637
]
3738
}

xwp-helper-fns-num.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Numeric functions and helpers
4+
*
5+
* @package eXtended WordPress
6+
* @subpackage Functions
7+
*/
8+
9+
if ( ! function_exists( 'xwp_is_float_str' ) ) :
10+
11+
/**
12+
* Check if a string is a integer
13+
*
14+
* @param mixed $str The string to check.
15+
* @return bool
16+
*/
17+
function xwp_is_int_str( mixed $str ): bool {
18+
if ( is_int( $str ) ) {
19+
return true;
20+
}
21+
22+
return is_string( $str ) && ctype_digit( strval( abs( $str ) ) );
23+
}
24+
25+
endif;
26+
27+
if ( ! function_exists( 'xwp_is_float_str' ) ) :
28+
29+
/**
30+
* Check if a string is a float
31+
*
32+
* @param mixed $str The string to check.
33+
* @return bool
34+
*/
35+
function xwp_is_float_str( mixed $str ): bool {
36+
if ( is_float( $str ) ) {
37+
return true;
38+
}
39+
40+
return is_numeric( $str ) && ( (string) (float) $str ) === $str;
41+
}
42+
43+
endif;

0 commit comments

Comments
 (0)