完成判断字符/数字节点

This commit is contained in:
zebord
2024-11-11 22:04:56 +08:00
parent 7d9a7de5ba
commit cd659107f9
3 changed files with 65 additions and 1 deletions
+15
View File
@@ -54,6 +54,21 @@ watermark_image: connect the image you want to use as a watermark
watermark_opacity: watermark transparency, default 0.5, maximum value 1
~~~
## Update log 2024-11-11
### Utils
1. LmcqInputValidator: Used to validate input value types, can determine whether the input is a pure number or a string
~~~
Function details
input_text: Input text to be validated
check_type: Validation type, options:
- is_digit: Check if it's a pure number
- is_string: Check if it's a string (any input that's not a pure number is considered a string)
~~~
## Contribute
zebord
+14
View File
@@ -53,6 +53,20 @@ watermark_opacity:水印透明度,默认0.5,最大值为1
~~~
## 更新日志 2024-11-11
### Utils
1. LmcqInputValidator:用于验证输入值的类型,可以判断输入是纯数字还是字符串
~~~
功能详解
input_text: 需要验证的输入文本
check_type: 验证类型,可选项:
- is_digit:判断是否为纯数字
- is_string:判断是否为字符串(任何非纯数字的输入都被视为字符串)
~~~
## 参与贡献
+36 -1
View File
@@ -710,4 +710,39 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"LmcqImageSaverTransit": "Lmcq Image Saver Transit",
"LmcqImageSaverWeb": "Lmcq Image Saver Web",
"LmcqLoadFluxNF4Checkpoint": "Lmcq Load Flux NF4 Checkpoint"
}
}
class LmcqInputValidator:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input_text": ("STRING", {"default": ""}),
"check_type": (["is_digit", "is_string"], ), # 修改为判断数字或字符串
}
}
RETURN_TYPES = ("BOOLEAN",)
RETURN_NAMES = ("result",)
FUNCTION = "validate_input"
CATEGORY = "Lmcq/Utils"
def validate_input(self, input_text, check_type):
if not input_text:
return (False,)
if check_type == "is_digit":
return (input_text.isdigit(),)
else: # is_string
# 判断是否为字符串 - 只要不是纯数字就认为是字符串
return (not input_text.isdigit(),)
# 在 NODE_CLASS_MAPPINGS 字典中添加新节点
NODE_CLASS_MAPPINGS.update({
"LmcqInputValidator": LmcqInputValidator
})
# 在 NODE_DISPLAY_NAME_MAPPINGS 字典中添加显示名称
NODE_DISPLAY_NAME_MAPPINGS.update({
"LmcqInputValidator": "Lmcq Input Validator"
})