Skip to content

sanitize

The sanitize function removes unwanted characters from a string.

sanitize(value: string)

Removes a default set of characters from the string:

  • ; (semicolon)
  • " (double quotes)
  • ' (single quotes)
  • ( (open bracket)
  • ) (closing bracket)

Example:

js
let stringToSanitize = 'H\'e(ll)o\' ;wo\"rld\";';
let sanitizedString = sanitize(stringToSanitize);
write('sanitizedString', sanitizedString);

Output:

json
{
  "sanitizedString": "Hello world"
}

sanitize(value: string, characters: string)

Removes only the characters specified in the second argument. This overrides the default removal set.

Example:

js
let stringToSanitize = 'H\'e(ll)o\' ;wo\"rld\";';
let sanitizedString = sanitize(stringToSanitize, 'l');
write('sanitizedString', sanitizedString);

Output:

json
{
  "sanitizedString": "H'e()o' ;wo\"rd\";"
}