glyphView. fontEditor. a few more host functions
This commit is contained in:
parent
cc33b9a015
commit
a874101a3d
4 changed files with 88 additions and 49 deletions
|
|
@ -20,6 +20,8 @@ export const _rt = {
|
|||
cat: (a: any) => (b: any) => Array.isArray(a) ? [...a, ...b] : a + b,
|
||||
max: (a: number) => (b: number) => Math.max(a, b),
|
||||
min: (a: number) => (b: number) => Math.min(a, b),
|
||||
floor: (a: number) => Math.floor(a),
|
||||
ceiling: (a: number) => Math.ceil(a),
|
||||
|
||||
eq: (a: any) => (b: any) => ({ _tag: deepEqual(a, b) ? 'True' : 'False' }),
|
||||
neq: (a: any) => (b: any) => ({ _tag: deepEqual(a, b) ? 'False' : 'True' }),
|
||||
|
|
@ -94,6 +96,11 @@ export const _rt = {
|
|||
hasField: (field: string) => (obj: any) => ({
|
||||
_tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False'
|
||||
}),
|
||||
getfield: (field: string) => (obj: any) => obj[field] !== undefined
|
||||
? { _tag: 'Some', _0: obj[field] }
|
||||
: { _tag: 'None' },
|
||||
entries: (obj: any) => Object.entries(obj).map(([k, v]) => ({ key: k, value: v })),
|
||||
keys: (obj: any) => Object.keys(obj),
|
||||
isFunction: (v: any) => ({ _tag: typeof v === 'function' ? 'True' : 'False' }),
|
||||
storeSearch: (query: string) => {
|
||||
return Object.keys(store)
|
||||
|
|
@ -228,6 +235,9 @@ export const _rt = {
|
|||
const compiled = compile(defs[0].body);
|
||||
const fn = new Function('_rt', 'store', `return ${compiled}`);
|
||||
const result = fn(_rt, store);
|
||||
if (result === undefined) {
|
||||
return { _tag: 'None' };
|
||||
}
|
||||
return { _tag: 'Value', _0: result };
|
||||
} catch (e: any) {
|
||||
return { _tag: 'Err', _0: e.message };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue