# utils

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

## iteratorToArray(iterator) ⇨ `T[]`

Since 5.12.0

Converts an Iterator to a JavaScript array.

| Param    | Type       | Description              |
| -------- | ---------- | ------------------------ |
| iterator | `Iterator` | The Iterator to convert. |

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

* JavaScript

  ```js
  import { iteratorToArray } from '@soleil-se/app-util/server';


  // Convert a Java Iterator to array
  const someIterator = getSomeIterator();
  const array = iteratorToArray(someIterator);
  ```

* TypeScript

  ```ts
  import { iteratorToArray } from '@soleil-se/app-util/server';


  // Convert a Java Iterator to array
  const someIterator = getSomeIterator();
  const array = iteratorToArray<string>(someIterator);
  ```

## nodeIteratorToArray(nodeIterator) ⇨ `Node[]`

Since 5.12.0

Converts a NodeIterator to an array of Nodes.

| Param        | Type           | Description                  |
| ------------ | -------------- | ---------------------------- |
| nodeIterator | `NodeIterator` | The NodeIterator to convert. |

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

* JavaScript

  ```js
  import { nodeIteratorToArray } from '@soleil-se/app-util/server';


  // Convert NodeIterator to array
  const nodeIterator = node.getNodes();
  const nodes = nodeIteratorToArray(nodeIterator);
  ```

* TypeScript

  ```ts
  import { nodeIteratorToArray } from '@soleil-se/app-util/server';


  // Convert NodeIterator to array
  const nodeIterator = node.getNodes();
  const nodes = nodeIteratorToArray(nodeIterator);
  ```

## listToArray(list) ⇨ `T[]`

Since 5.12.0

Converts a Java List to a JavaScript array.

| Param | Type   | Description          |
| ----- | ------ | -------------------- |
| list  | `List` | The List to convert. |

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

* JavaScript

  ```js
  import { listToArray } from '@soleil-se/app-util/server';


  // Convert List to array
  const javaList = PropertyUtil.getStrings(node, 'someProperty');
  const array = listToArray(javaList);
  ```

* TypeScript

  ```ts
  import { listToArray } from '@soleil-se/app-util/server';


  // Convert List to array
  const javaList = PropertyUtil.getStrings(node, 'someProperty');
  const array = listToArray<string>(javaList);
  ```

## setToArray(set) ⇨ `T[]`

Since 5.12.0

Converts a Java Set to a JavaScript array.

| Param | Type  | Description         |
| ----- | ----- | ------------------- |
| set   | `Set` | The Set to convert. |

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

* JavaScript

  ```js
  import { setToArray } from '@soleil-se/app-util/server';


  // Convert Java Set to array
  const javaSet = getSomeSet();
  const array = setToArray(javaSet);
  ```

* TypeScript

  ```ts
  import { setToArray } from '@soleil-se/app-util/server';


  // Convert Java Set to array
  const javaSet = getSomeSet();
  const array = setToArray<string>(javaSet);
  ```

## nativeRequire(module)

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.

| Param  | Type     | Description                       |
| ------ | -------- | --------------------------------- |
| module | `string` | The module identifier to require. |

**Returns:** `any` - The exported module.

```js
import { nativeRequire } from '@soleil-se/app-util/server';


// Import a Sitevision API package
const PortletContextUtil = nativeRequire('PortletContextUtil');
const PropertyUtil = nativeRequire('PropertyUtil');
```