Continue script abstraction

This commit is contained in:
hydrant
2020-03-01 13:15:50 +01:00
parent 37f499a446
commit d7a76caf2a
14 changed files with 531 additions and 8 deletions

View File

@@ -0,0 +1,48 @@
import { UIMenuItem, Point, Menu } from "./libs/NativeUI/index";
function createMenuItem(title: string, description?: string, fn?: (menuItem: UIMenuItem) => void): UIMenuItem {
var item: UIMenuItem = new UIMenuItem(title, description || "");
if (fn) {
fn(item);
}
return item;
}
function createMenu(title: string, subtitle: string, pos: Point, items: MenuMap): Menu {
var menu: Menu = new Menu(title, subtitle, pos);
Object.entries(items).forEach((value, index, array) => {
menu.AddItem(items[value[0]]);
});
menu.Close(true);
return menu;
}
function parseJson<TData>(json: string): TData {
var dateTimeReviver = function (key: string, value: any) {
var a;
if (typeof value === 'string') {
a = /\/Date\((\d*)\)\//.exec(value);
if (a) {
return new Date(+a[1]);
}
}
return value;
}
return <TData>JSON.parse(json, dateTimeReviver);
}
interface MenuMap {
[key: string]: UIMenuItem;
}
export {
createMenuItem,
parseJson,
createMenu,
MenuMap
}