toString for arrays and dicts

201c4203e883ff3f85e3d0d5cefdc023896546a1
This commit is contained in:
4eb0da
2024-05-16 13:52:50 +03:00
parent fa96cb6042
commit 082d4ebe89
4 changed files with 27 additions and 8 deletions
+15 -2
View File
@@ -1,6 +1,8 @@
import type {
ArrayValue,
BooleanValue,
ColorValue,
DictValue,
EvalContext,
EvalValue,
IntegerValue,
@@ -10,14 +12,21 @@ import type {
} from '../eval';
import type { VariableType, VariableValue } from '../variable';
import { registerFunc, registerMethod } from './funcs';
import { BOOLEAN, COLOR, INTEGER, NUMBER, STRING, URL } from '../const';
import { ARRAY, BOOLEAN, COLOR, DICT, INTEGER, NUMBER, STRING, URL } from '../const';
import { transformColorValue, valToString } from '../utils';
import { MAX_INT, MIN_INT, toBigInt } from '../bigint';
function toString(
_ctx: EvalContext,
arg: IntegerValue | NumberValue | BooleanValue | ColorValue | UrlValue | StringValue
arg: IntegerValue | NumberValue | BooleanValue | ColorValue | UrlValue | StringValue | ArrayValue | DictValue
): EvalValue {
if (arg.type === ARRAY || arg.type === DICT) {
return {
type: STRING,
value: JSON.stringify(arg.value)
};
}
return {
type: STRING,
value: valToString(arg)
@@ -191,6 +200,8 @@ export function registerStd(): void {
registerFunc('toString', [COLOR], toString);
registerFunc('toString', [URL], toString);
registerFunc('toString', [STRING], toString);
registerFunc('toString', [ARRAY], toString);
registerFunc('toString', [DICT], toString);
registerFunc('toNumber', [INTEGER], toNumber);
registerFunc('toNumber', [STRING], toNumber);
@@ -224,4 +235,6 @@ export function registerStd(): void {
registerMethod('toString', [COLOR], toString);
registerMethod('toString', [URL], toString);
registerMethod('toString', [STRING], toString);
registerMethod('toString', [ARRAY], toString);
registerMethod('toString', [DICT], toString);
}
@@ -12,7 +12,8 @@
],
"result_type": "string",
"platforms": [
"ios"
"ios",
"web"
]
},
{
@@ -61,7 +62,8 @@
],
"result_type": "string",
"platforms": [
"ios"
"ios",
"web"
]
},
{
@@ -238,7 +238,8 @@
}
],
"platforms": [
"ios"
"ios",
"web"
]
},
{
@@ -263,7 +264,8 @@
}
],
"platforms": [
"ios"
"ios",
"web"
]
},
{
+4 -2
View File
@@ -113,7 +113,8 @@
}
],
"platforms": [
"ios"
"ios",
"web"
]
},
{
@@ -133,7 +134,8 @@
}
],
"platforms": [
"ios"
"ios",
"web"
]
},
{