import { v4 as uuid } from 'uuid';
export default class Utils {
+ static logPrefix(prefixString = ''): string {
+ return new Date().toLocaleString() + prefixString;
+ }
+
static generateUUID(): string {
return uuid();
}
}
static convertToInt(value: any): number {
- let changedValue = value;
+ let changedValue: number = value;
if (!value) {
return 0;
}
if (Number.isSafeInteger(value)) {
- return value;
+ return changedValue;
}
// Check
- if (typeof value === 'string') {
+ if (Utils.isString(value)) {
// Create Object
changedValue = parseInt(value);
}
}
static convertToFloat(value: any): number {
- let changedValue = value;
+ let changedValue: number = value;
if (!value) {
return 0;
}
// Check
- if (typeof value === 'string') {
+ if (Utils.isString(value)) {
// Create Object
changedValue = parseFloat(value);
}
return Utils.roundTo(Utils.getRandomFloat(max), scale);
}
- static logPrefix(prefixString = ''): string {
- return new Date().toLocaleString() + prefixString;
+ static getRandomFloatFluctuatedRounded(staticValue: number, fluctuationPercent: number, scale = 2): number {
+ if (fluctuationPercent === 0) {
+ return Utils.roundTo(staticValue, scale);
+ }
+ const fluctuationRatio = fluctuationPercent / 100;
+ return Utils.getRandomFloatRounded(staticValue * (1 + fluctuationRatio), staticValue * (1 - fluctuationRatio), scale);
}
static cloneObject<T>(object: T): T {