Hoppa till innehåll

utils

General utility functions for working with Sitevision APIs and converting Java collections to JavaScript arrays.

Since 5.12.0

Converts an Iterator to a JavaScript array.

ParamTypeDescription
iteratorIteratorThe Iterator to convert.

Returns: T[] - Array containing all items from the iterator.

import { iteratorToArray } from '@soleil-se/app-util/server';
// Convert a Java Iterator to array
const someIterator = getSomeIterator();
const array = iteratorToArray(someIterator);

nodeIteratorToArray(nodeIterator) ⇨ Node[]

Section titled “nodeIteratorToArray(nodeIterator) ⇨ Node[]”
Since 5.12.0

Converts a NodeIterator to an array of Nodes.

ParamTypeDescription
nodeIteratorNodeIteratorThe NodeIterator to convert.

Returns: Node[] - Array containing all nodes from the iterator.

import { nodeIteratorToArray } from '@soleil-se/app-util/server';
// Convert NodeIterator to array
const nodeIterator = node.getNodes();
const nodes = nodeIteratorToArray(nodeIterator);
Since 5.12.0

Converts a Java List to a JavaScript array.

ParamTypeDescription
listListThe List to convert.

Returns: T[] - Array containing all items from the list.

import { listToArray } from '@soleil-se/app-util/server';
// Convert List to array
const javaList = PropertyUtil.getStrings(node, 'someProperty');
const array = listToArray(javaList);
Since 5.12.0

Converts a Java Set to a JavaScript array.

ParamTypeDescription
setSetThe Set to convert.

Returns: T[] - Array containing all items from the set.

import { setToArray } from '@soleil-se/app-util/server';
// Convert Java Set to array
const javaSet = getSomeSet();
const array = setToArray(javaSet);
Since 5.0.0

Require a module natively, bypassing Webpack bundling. This function behaves like a native require() in Rhino and is used to import system packages where Webpack bundling interferes with native module resolution.

ParamTypeDescription
modulestringThe module identifier to require.

Returns: any - The exported module.

import { nativeRequire } from '@soleil-se/app-util/server';
// Import a Sitevision API package
const PortletContextUtil = nativeRequire('PortletContextUtil');
const PropertyUtil = nativeRequire('PropertyUtil');