mapcomplete/Utils.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-07-31 02:58:58 +00:00
import {UIElement} from "./UI/UIElement";
import {DropDown} from "./UI/Input/DropDown";
import {State} from "./State";
import Locale from "./UI/i18n/Locale";
2020-07-23 23:12:57 +00:00
export class Utils {
/**
* Gives a clean float, or undefined if parsing fails
* @param str
*/
static asFloat(str): number {
if (str) {
const i = parseFloat(str);
if (isNaN(i)) {
return undefined;
}
return i;
}
return undefined;
}
public static Upper(str : string){
return str.substr(0,1).toUpperCase() + str.substr(1);
}
2020-07-31 02:58:58 +00:00
static DoEvery(millis: number, f: (() => void)) {
2020-07-31 15:11:44 +00:00
if(State.runningFromConsole){
return;
}
2020-07-31 02:58:58 +00:00
window.setTimeout(
function () {
f();
Utils.DoEvery(millis, f);
}
, millis)
}
public static CreateLanguagePicker(label: string | UIElement = "") {
return new DropDown(label, State.state.layoutToUse.data.supportedLanguages.map(lang => {
return {value: lang, shown: lang}
}
), Locale.language);
}
}