Common functions.
Example
var common = require('/lib/xp/common');
Methods
(static) sanitize(text) → {string}
Transform a text string so that it can be safely used in cases where the range of accepted characters is restricted.
Some usage examples are: as an XP content or node name, as a principal name, in a URL or in a filesystem path.
The following changes will be applied to the input text:
- convert characters to lowercase (according to the rules of the default locale)
- replace punctuation symbols and blank spaces with the hyphen character ('-')
- remove some unsafe and invisible Unicode characters
- strip duplicated hyphen characters
- remove diacritic characters
- map letters to the English alphabet (ASCII encoding)
Parameters:
Name | Type | Description |
---|---|---|
text |
string | Text string to sanitize. |
Returns:
Sanitized text.
- Type
- string
Example
// Sanitize string
var sanitizedText = common.sanitize("Piña CØLADÆ <script>alert('hi!');</script>");
print(sanitizedText);
var result = sanitizedText === 'pina-coladae-script-alerthi-script';