> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Build a Function Library in Studio Two

## Article: Build a Function Library in Studio Two

## Article Link: https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/build-a-function-library-in-studio-two.md

## Article Content:

# Build a Function Library in Studio Two

A [function library](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/about-function-libraries.md) is a manifest plus an implementation file. You generate the files first, then declare each function in the manifest and export a matching function from the implementation.

This article walks through that loop from a scaffolded library to one with your own functions.

Follow the instructions below to:

1. Scaffold the library.
2. Declare functions in the manifest.
3. Implement the functions.

## Step 1 | Scaffold the library

Start from a generated function library rather than an empty folder, so the file structure and registration are already in place.

For the full procedure, see [Add a Function Library Extension in Studio Two](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/add-a-function-library-extension-in-studio-two.md).

You can find the new files under `src/extensions/site/function-libraries/<extension-folder>/`. The remaining steps use 2 of them: the manifest, `<extension-folder>.extension.ts`, and the implementation, `<extension-folder>.ts`. For what every file in the folder is for, see [Function Library Extension Files and Code](https://dev.wix.com/docs/site-extensions/function-libraries/function-library-extension-files-and-code.md).

## Step 2 | Declare functions in the manifest

`<extension-folder>.extension.ts` is the manifest you own. It names the library and lists each function a Wix user can connect in the editor.

A generated library includes a working `formatPrice` function as a starting point:

```ts
import { extensions } from '@wix/custom-extensions';

export default extensions.functionLibrary({
  id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
  name: 'My Function Library',
  type: 'companionApp.myFunctionLibrary',
  functions: {
    formatPrice: {
      displayName: 'Format price',
      description: 'Formats an amount as a price string',
      parameters: [
        {
          dataType: 'number',
          displayName: 'Amount',
        },
        {
          dataType: 'text',
          displayName: 'Currency symbol',
          optional: true,
        },
      ],
      returns: {
        dataType: 'text',
        displayName: 'Formatted price',
      },
    },
  },
  resources: {
    client: {
      url: './extensions/site/function-libraries/my-function-library/my-function-library.ts',
    },
  },
});
```

Keep the `id` field stable once other code or editor bindings depend on it. Change `name` when you want a different label in the editor.

Add an entry to `functions` for every function you want to expose. The key is the function name. The `displayName` field is what a Wix user sees when connecting the function. Each parameter and the return value needs a `dataType` that matches the implementation.

For every field, see [About the Function Library Manifest](https://dev.wix.com/docs/site-extensions/function-libraries/about-the-function-library-manifest.md) and [Function Reference](https://dev.wix.com/docs/site-extensions/function-libraries/function-reference.md).

## Step 3 | Implement the functions

Write the functions in `<extension-folder>.ts`. Export one named function per key in the manifest's `functions` map. Parameter order, requiredness, and types must match the manifest.

The generated implementation for `formatPrice` looks like this:

```ts
/**
 * This file contains the utility functions exposed by this function library.
 *
 * Every exported function must be described in the `functions` map of the extension
 * file, so that it can be used in the Wix editor.
 */
export function formatPrice(amount: number, currencySymbol = '$'): string {
  return `${currencySymbol}${amount.toFixed(2)}`;
}
```

Replace `formatPrice` or add more exports as your library grows. If you add a function to the implementation, add a matching entry to the manifest before a Wix user can connect it.

When the library behaves the way you want, click **Publish** to ship it with your site.

## See also

- [About Function Libraries](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/about-function-libraries.md)
- [Add a Function Library Extension in Studio Two](https://dev.wix.com/docs/studio-two/code-your-site/code-model/function-libraries/add-a-function-library-extension-in-studio-two.md)
- [Function Library Extension Files and Code](https://dev.wix.com/docs/site-extensions/function-libraries/function-library-extension-files-and-code.md)
- [About the Function Library Manifest](https://dev.wix.com/docs/site-extensions/function-libraries/about-the-function-library-manifest.md)
- [Function Libraries](https://dev.wix.com/docs/overview/extensions-framework/site-extensions/function-libraries.md)