# Custom modules

## Modules

A module is a named library of reusable functions, types and values. You can [create your own modules](/flow-connect/working-with-connect/create-and-design/modules/create-module.md) from the Hub and consume them in your applications.

Modules are only allowed to declared functions, types and values.

```typescript
// This code may be placed in a module. We will call it MyModule.

// A function which reverses a text value.
function reverse(input: text) {
    let result = "";
    for c in input {
        set result = c & result;
    }
    return result;
}

// A value containing some placeholder text.
let placeholderText = "Lorem ipsum";
```

Given such a module, we can use it in a script step:

```typescript
// In a script step in an application
// which refers to MyModule by dragging it onto the canvas:

return MyModule.reverse(MyModule.placeholderText); // Returns "muspi meroL";
```

## Assertions

While developing a module, it is often useful to investigate the behavior of its functions before consuming them in an application. You can do this using *assertions*.

An assertion is a statement indicating what you expect to be true about a function. Similar to a unit test in other programming environments, an assertion can be *checked* while the code is being developed.

```typescript
// In a module named "MyModule"

function reverse(input: text) {
    let result = "";
    for c in input {
        set result = c & result;
    }
    return result;
}

// A couple of assertions defining the behavior of the reverse function.
assert reverse("abc") == "cba";
assert reverse("a") == "a";
assert reverse("") == "";
```

To check the assertions in a module, press the **Check Assertions** button above the module editor. Assertions which evaluate to true are considered *successful*; assertions which evaluate to false (or raise a runtime error) are considered *failed*. The success or failure of each individual assertion will be indicated by a green check mark or a red cross, respectively, next to the line.

When applications are run, assert statements are ignored.

Making use of assertions is a **highly recommended practice**, as they help verify that the code in the modules retains its expected behavior as you continue to work on it.

## Private

Functions and values in modules can be marked as *private*. A private function or value can be used by other functions and values inside the module but are not visible to applications that use the modules.

A private function or value is declared by adding the `private` keyword before the `function` or `let` keywords.

```typescript
// Declare a private email validation regex pattern.
private let emailPattern = @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";

// Declare a public email validation function
function isValidEmail(candidate: text) => regexMatch(candidate, emailPattern);

// Assertions are never visible from outside and do not need to be marked as private.
assert isValidEmail("info@novacura.com");
assert not isValidEmail("info.novacura.com");
```

## FlowScript Playground

All modules that are open in the Designer are automatically made available in the FlowScript Playground. The Playground will use the *current* version of the module, regardless of whether it is saved.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.novacura.com/flow-connect/reference/reference/flowscript/walkthrough/custom-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
