Common
All imports from base package are available both on the server and client.
appId : String
Section titled “appId : String”DOM friendly unique identifier for the WebApp.
import { appId } from '@soleil-se/app-util';
console.log(appId); // For example: 12_682d461b1708a9bb1ea13efdisOffline : Boolean
Section titled “isOffline : Boolean”If the WebApp is running in offline mode or not.
import { isOffline } from '@soleil-se/app-util';
console.log(isOffline); // true or falseisOnline : Boolean
Section titled “isOnline : Boolean”If the WebApp is running in online mode or not.
import { isOnline } from '@soleil-se/app-util';
console.log(isOnline); // true or falseisServer : Boolean
Section titled “isServer : Boolean”If the current code is running on the server.
import { isServer } from '@soleil-se/app-util';
console.log(isServer); // true or falseisBrowser : Boolean
Section titled “isBrowser : Boolean”If the current code is running in the browser.
import { isBrowser } from '@soleil-se/app-util';
console.log(isBrowser); // true or falsegetNamespace([prefix]) ⇨ String
Section titled “getNamespace([prefix]) ⇨ String”Get a prefixed namespace unique for app.
Returns: String - Prefixed namespace.
| Param | Type | Default |
|---|---|---|
| [prefix] | string | 'app' |
import { getNamespace } from '@soleil-se/app-util';
console.log(getNamespace());// For example: app_12_682d461b1708a9bb1ea13efd
console.log(getNamespace('input'));// For example: input_12_682d461b1708a9bb1ea13efd
// If the app is in a decoration template the Portlet ID is the same for all instances, so the ID of the decorated node is used as well.console.log(getNamespace('decoration'));// For example: decoration_10_3871c02f1754f3aa8f9d4eb_12_70c3d424173b4900fc550e1cgenerateId([prefix]) ⇨ String
Section titled “generateId([prefix]) ⇨ String”Generate a unique identifier with a random UUID without dashes.
Returns: String - Unique identifier.
| Param | Type | Default |
|---|---|---|
| [prefix] | string | 'id' |
import { generateId } from '@soleil-se/app-util';
console.log(generateId());// For example: id_550e8400e29b41d4a716446655440000
console.log(generateId('input'));// For example: input_550e8400e29b41d4a716446655440000getRouteUri(route, [query]) ⇨ String
Section titled “getRouteUri(route, [query]) ⇨ String”Get URI for a route.
Returns: String - URI for route.
| Param | Type | Description |
|---|---|---|
| route | String | A route. |
| query | Object | Object with query string parameters |
import { getRouteUri } from '@soleil-se/app-util';
console.log(getRouteUri('/items'));// URI structure: /appresource/{pageId}/{portletId}>/itemsimport { getRouteUri } from '@soleil-se/app-util';
console.log(getRouteUri('/items', { foo: 'bar' }));// URI structure: /appresource/{pageId}/{portletId}>/items?foo=bargetResourceUri(resource) ⇨ String
Section titled “getResourceUri(resource) ⇨ String”Get URI for a resource.
Returns: String - URI for a resource.
| Param | Type | Description |
|---|---|---|
| resource | String | A resource. |
import { getResourceUri } from '@soleil-se/app-util';
console.log(getResourceUri('/image.png'));// URI structure: /webapp-files/<webappname>/<webappversion>/image.pnggetAppProps([key]) ⇨ * | Object
Section titled “getAppProps([key]) ⇨ * | Object”Get props that are passed to app when rendering.
Returns: * | Object - Value or object.
| Param | Type | Description |
|---|---|---|
| [key] | String | Key for value. |
import { getAppProps } from '@soleil-se/app-util';
// Get value with keyconst myValue = getAppProps('myValue');// Or with destructuringconst { myValue } = getAppProps();stringifyParams(params [, options]) ⇨ String
Section titled “stringifyParams(params [, options]) ⇨ String”Stringify an object to a query string compatible with Sitevision.
Returns: String - Stringified parameters.
| Param | Type | Default | Description |
|---|---|---|---|
| params | Object | Object with parameters to stringify. | |
| [options] | Object | {} | Options object. |
| [options.addQueryPrefix] | Boolean | false | If a leading ? should be added to the string. |
import { stringifyParams } from '@soleil-se/app-util';
const queryString = stringifyParams({ foo: 'bar', num: 1 });// foo=bar&num=1
const queryString = stringifyParams({ foo: 'bar', num: 1 }, { addQueryPrefix: true });// ?foo=bar&num=1parseParams(url) ⇨ Object
Section titled “parseParams(url) ⇨ Object”Parse an URL, URI or query string to an object containing its query parameters.
Returns: Object - Parsed parameters.
| Param | Type | Default | Description |
|---|---|---|---|
| url | String | URL, URI or query string to be parsed, must start with or contain ”?” |
import { parseParams } from '@soleil-se/app-util';
const params = parseParams('?foo=bar&arr[]=1&arr[]=2');// { foo: 'bar', arr: [1, 2] }