Add slugify string node

This commit is contained in:
2026-08-05 12:34:51 +00:00
parent c26f97785b
commit 285eb40c92
3 changed files with 53 additions and 0 deletions
+31
View File
@@ -2,6 +2,8 @@ from functools import lru_cache
from itertools import islice
import json
import os
import re
import unicodedata
def _clone_container(value):
@@ -259,6 +261,16 @@ def _strip_iteration_suffix(value):
return f"{prefix}{extension}"
def _slugify_string(value):
if not isinstance(value, str):
return ""
normalized = unicodedata.normalize("NFKD", value)
ascii_value = normalized.encode("ascii", "ignore").decode("ascii")
slug = re.sub(r"[^a-zA-Z0-9]+", "-", ascii_value.lower())
return slug.strip("-")
class DumasJSONStringToObjectNode:
CATEGORY = "Dumas/JSON"
RETURN_TYPES = ("JSON",)
@@ -298,6 +310,23 @@ class DumasStripIterationSuffixNode:
return (_strip_iteration_suffix(filename),)
class DumasSlugifyStringNode:
CATEGORY = "Dumas/String"
RETURN_TYPES = ("STRING",)
FUNCTION = "slugify_string"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"default": "", "multiline": False}),
}
}
def slugify_string(self, text):
return (_slugify_string(text),)
class DumasJSONObjectToStringNode:
CATEGORY = "Dumas/JSON"
RETURN_TYPES = ("STRING",)
@@ -630,6 +659,7 @@ class DumasJSONUnflattenNode:
NODE_CLASS_MAPPINGS = {
"DumasJSONStringToObject": DumasJSONStringToObjectNode,
"DumasStripIterationSuffix": DumasStripIterationSuffixNode,
"DumasSlugifyString": DumasSlugifyStringNode,
"DumasJSONObjectToString": DumasJSONObjectToStringNode,
"DumasJSONGetValue": DumasJSONGetValueNode,
"DumasJSONSetValue": DumasJSONSetValueNode,
@@ -650,6 +680,7 @@ NODE_CLASS_MAPPINGS = {
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasJSONStringToObject": "Dumas JSON String to Object",
"DumasStripIterationSuffix": "Dumas Strip Iteration Suffix",
"DumasSlugifyString": "Dumas Slugify String",
"DumasJSONObjectToString": "Dumas JSON Object to String",
"DumasJSONGetValue": "Dumas JSON Get Value",
"DumasJSONSetValue": "Dumas JSON Set Value",