Common Library

Contents

This library contains common functions.

Usage

Add the following to your build.gradle file:

dependencies {
  include "com.enonic.xp:lib-common:${xpVersion}"
}

In your JavaScript controller, add a require statement:

const commonLib = require('/lib/xp/common');

You are now ready to use the library functionality.

Functions

sanitize

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 Kind Details

text

string

The text to sanitize

Returns

string : The sanitized text

Example

Sanitize string
var sanitizedText = commonLib.sanitize("Piña CØLADÆ <script>alert('hi!');</script>");
Sample response
"pina-coladae-script-alerthi-script"

Contents

Contents