LogoPixi’VN
indexNamespacesTextReplacesFunctions

Function: replace()

> replace(text, replaceOptions): string

Defined in: node_modules/@drincs/pixi-vn-json/dist/index.d.ts:1245

Applies all registered handlers of the specified type to the given text in order.

For each handler:

  1. All [key] tokens currently present in the text are collected.
  2. For each unique key, the handler's validation is tested against the key.
  3. If validation passes, the handler is called with the key.
  4. If the handler returns a string, all occurrences of [key] in the text are replaced with that string.
  5. After the handler has processed all tokens, the next handler starts on the updated text.

Parameters

text

string

The source text to process.

replaceOptions

Specifies which phase of handlers to run.

type

"before-translation" | "after-translation"

Which phase of handlers to execute.

Returns

string

The text after all matching handlers have been applied.

Example

// Given handlers that replace [name] -> "Mario" and [surname] -> "Rossi":
TextReplaces.replace("Ciao [name] [surname]. [name] vai pure", { type: "before-translation" })
// => "Ciao Mario Rossi. Mario vai pure"