Skip to main content

TextFilterUtils

Utility functions for filtering text wrapping TextService and legacy Chat API surfaces.

Functions

promiseNonChatStringForBroadcast

TextFilterUtils.promiseNonChatStringForBroadcast(
textstring,
fromUserIdnumber,
textFilterContextTextFilterContext
) → Promise<string>

Returns a filtered string for broadcast. Tends to look like this:

TextFilterUtils.promiseNonChatStringForBroadcast(text, player.UserId, Enum.TextFilterContext.PublicChat)
	:Then(function(filtered)
		print(filtered)
	end)

The two options for textFilterContext are Enum.TextFilterContext.PublicChat and Enum.TextFilterContext.PrivateChat.

promiseLegacyChatFilter

TextFilterUtils.promiseLegacyChatFilter(
playerFromPlayer,
textstring
) → Promise<string>

Legacy filter broadcast using the Chat:FilterStringForBroadcast API call. It's recommended you use TextFilterUtils.promiseNonChatStringForBroadcast instead.

promiseNonChatStringForUserAsync

TextFilterUtils.promiseNonChatStringForUserAsync(
textstring,
fromUserIdnumber,
toUserIdnumber,
textFilterContextTextFilterContext
) → Promise<string>

Returns a filtered string for a specific user to another user. This is preferable over broadcast if possible.

getNonChatStringForBroadcastAsync

TextFilterUtils.getNonChatStringForBroadcastAsync(
textstring,
fromUserIdnumber,
textFilterContextTextFilterContext
) → Promise<string>

Blocking call to get a non-chat string for broadcast. Wraps TextService.FilterStringAsync.

getNonChatStringForUserAsync

TextFilterUtils.getNonChatStringForUserAsync(
textstring,
fromUserIdnumber,
toUserIdnumber,
textFilterContextTextFilterContext
) → Promise<string>

Blocking call to get a non-chat string for a user.

hasNonFilteredText

TextFilterUtils.hasNonFilteredText(textstring) → boolean

Returns true if there's non-filtered text or characters in the text

getProportionFiltered

TextFilterUtils.getProportionFiltered(textstring) → number

Computes proportional text that is filtered ignoring whitespace.

countFilteredCharacters

TextFilterUtils.countFilteredCharacters(textstring) → (
number,--

filtered characters

number,--

Unfiltered characters

number--

White space characters

)

Gets the number of filtered characters in the text string

addBackInNewLinesAndWhitespace

TextFilterUtils.addBackInNewLinesAndWhitespace(
textstring,
filteredTextstring
) → number

Adds in new lines and whitespace to the text

Show raw api
{
    "functions": [
        {
            "name": "promiseNonChatStringForBroadcast",
            "desc": "Returns a filtered string for broadcast. Tends to look like this:\n\n```lua\nTextFilterUtils.promiseNonChatStringForBroadcast(text, player.UserId, Enum.TextFilterContext.PublicChat)\n\t:Then(function(filtered)\n\t\tprint(filtered)\n\tend)\n```\n\nThe two options for textFilterContext are `Enum.TextFilterContext.PublicChat` and `Enum.TextFilterContext.PrivateChat`.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fromUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "textFilterContext",
                    "desc": "",
                    "lua_type": "TextFilterContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 33,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "promiseLegacyChatFilter",
            "desc": "Legacy filter broadcast using the `Chat:FilterStringForBroadcast` API call. It's recommended\nyou use [TextFilterUtils.promiseNonChatStringForBroadcast] instead.",
            "params": [
                {
                    "name": "playerFrom",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 54,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "promiseNonChatStringForUserAsync",
            "desc": "Returns a filtered string for a specific user to another user. This is preferable over broadcast if\npossible.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fromUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "toUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "textFilterContext",
                    "desc": "",
                    "lua_type": "TextFilterContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 84,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "getNonChatStringForBroadcastAsync",
            "desc": "Blocking call to get a non-chat string for broadcast. Wraps [TextService.FilterStringAsync].",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fromUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "textFilterContext",
                    "desc": "",
                    "lua_type": "TextFilterContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 106,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "getNonChatStringForUserAsync",
            "desc": "Blocking call to get a non-chat string for a user.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fromUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "toUserId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "textFilterContext",
                    "desc": "",
                    "lua_type": "TextFilterContext"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 137,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "hasNonFilteredText",
            "desc": "Returns true if there's non-filtered text or characters in the text",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 183,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "getProportionFiltered",
            "desc": "Computes proportional text that is filtered ignoring whitespace.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 202,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "countFilteredCharacters",
            "desc": "Gets the number of filtered characters in the text string",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "filtered characters",
                    "lua_type": "number"
                },
                {
                    "desc": "Unfiltered characters",
                    "lua_type": "number"
                },
                {
                    "desc": "White space characters",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 220,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        },
        {
            "name": "addBackInNewLinesAndWhitespace",
            "desc": "Adds in new lines and whitespace to the text",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "filteredText",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 246,
                "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "TextFilterUtils",
    "desc": "Utility functions for filtering text wrapping [TextService] and legacy [Chat] API surfaces.",
    "source": {
        "line": 6,
        "path": "src/textfilterutils/src/Shared/TextFilterUtils.lua"
    }
}