diff --git a/README.md b/README.md index ca99cdc..eaa47be 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index ed0201e..80585e2 100644 --- a/README_CN.md +++ b/README_CN.md @@ -53,6 +53,20 @@ watermark_opacity:水印透明度,默认0.5,最大值为1 ~~~ +## 更新日志 2024-11-11 + +### Utils + +1. LmcqInputValidator:用于验证输入值的类型,可以判断输入是纯数字还是字符串 + +~~~ +功能详解 + +input_text: 需要验证的输入文本 +check_type: 验证类型,可选项: + - is_digit:判断是否为纯数字 + - is_string:判断是否为字符串(任何非纯数字的输入都被视为字符串) +~~~ ## 参与贡献 diff --git a/nodes.py b/nodes.py index 8f27fe2..03bd457 100644 --- a/nodes.py +++ b/nodes.py @@ -710,4 +710,39 @@ NODE_DISPLAY_NAME_MAPPINGS = { "LmcqImageSaverTransit": "Lmcq Image Saver Transit", "LmcqImageSaverWeb": "Lmcq Image Saver Web", "LmcqLoadFluxNF4Checkpoint": "Lmcq Load Flux NF4 Checkpoint" -} \ No newline at end of file +} + +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" +}) \ No newline at end of file