diff --git a/plugin/lib/quickcomposer/data/index.js b/plugin/lib/quickcomposer/data/index.js index 671ccf0..61b7424 100644 --- a/plugin/lib/quickcomposer/data/index.js +++ b/plugin/lib/quickcomposer/data/index.js @@ -4,6 +4,7 @@ const zlib = require("./zlib"); const { htmlParser } = require("./htmlParser"); const array = require("./array"); const object = require("./object"); +const type = require("./type"); const time = require("./time"); const { regexTransform } = require("./regexTransform"); @@ -15,5 +16,6 @@ module.exports = { array, object, time, + type, regexTransform, }; diff --git a/plugin/lib/quickcomposer/data/type.js b/plugin/lib/quickcomposer/data/type.js new file mode 100644 index 0000000..ef04920 --- /dev/null +++ b/plugin/lib/quickcomposer/data/type.js @@ -0,0 +1,12 @@ +const get = (value) => { + return typeof value; +}; + +const check = (value, type) => { + return typeof value === type; +}; + +module.exports = { + get, + check, +}; diff --git a/src/js/composer/commands/dataCommands.js b/src/js/composer/commands/dataCommands.js index e4ca27d..60d100e 100644 --- a/src/js/composer/commands/dataCommands.js +++ b/src/js/composer/commands/dataCommands.js @@ -5,6 +5,60 @@ export const dataCommands = { icon: "format_color_text", defaultOpened: false, commands: [ + { + value: "typeof", + label: "类型检查", + icon: "check_circle", + subCommands: [ + { + value: "quickcomposer.data.type.get", + label: "获取类型", + icon: "text_fields", + outputs: { + label: "类型", + suggestName: "valueType", + typeName: "字符串", + }, + }, + { + value: "quickcomposer.data.type.check", + label: "判断类型", + icon: "text_fields", + config: [ + { + component: "QSelect", + icon: "text_fields", + options: [ + { label: "字符串", value: "string" }, + { label: "数字", value: "number" }, + { label: "布尔", value: "boolean" }, + { label: "数组", value: "array" }, + { label: "对象", value: "object" }, + { label: "函数", value: "function" }, + { label: "空", value: "null" }, + { label: "未定义", value: "undefined" }, + { label: "Buffer", value: "buffer" }, + ], + width: 12, + }, + ], + outputs: { + label: "判断结果", + suggestName: "isType", + typeName: "布尔", + }, + }, + ], + config: [ + { + label: "要检查的值", + component: "VariableInput", + defaultValue: newVarInputVal("var"), + icon: "text_fields", + width: 12, + }, + ], + }, { value: "quickcomposer.data.string.reverse", label: "字符串处理",