feat: util/simpleSerialize 추가
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { isInteger, isString } from "lodash";
|
||||
|
||||
export function simpleSerialize(...values : (string|number)[]): string{
|
||||
const result = [];
|
||||
for(const value of values){
|
||||
if(isString(value)){
|
||||
result.push(`str(${value.length},${value})`);
|
||||
continue;
|
||||
}
|
||||
if(isInteger(value)){
|
||||
result.push(`int(${value})`);
|
||||
}
|
||||
const float6 = value.toLocaleString("en-US", {maximumFractionDigits: 6});
|
||||
result.push(`float(${float6})`);
|
||||
}
|
||||
return result.join('|');
|
||||
}
|
||||
@@ -850,4 +850,25 @@ class Util extends \utilphp\util
|
||||
yield $a => $b;
|
||||
}
|
||||
}
|
||||
|
||||
public static function simpleSerialize(string|int|float ...$values): string{
|
||||
$result = [];
|
||||
foreach($values as $value){
|
||||
if(is_string($value)){
|
||||
$length = mb_strlen($value);
|
||||
$result[] = "str({$length},{$value})";
|
||||
continue;
|
||||
}
|
||||
if(is_int($value)){
|
||||
$result[] = "int({$value})";
|
||||
continue;
|
||||
}
|
||||
if(is_float($value)){
|
||||
$value = number_format($value, 6, '.', '');
|
||||
$result[] = "float({$value})";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return join('|', $result);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user