# fontoxpath-module-loader

> Loads XQuery modules into [fontoxpath](https://github.com/FontoXML/fontoxpath) and does something with the result. Can be easily configured to load that module from disk, or from a REST endpoint, or whatever else async stuff you have.

Latest version **1.0.2** (published 2021-10-12) · 0 weekly downloads

## Install

```sh
npm install fontoxpath-module-loader
pnpm add fontoxpath-module-loader
yarn add fontoxpath-module-loader
bun add fontoxpath-module-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-10-12 |
| First published | 2020-02-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wvbe |

## Links

- npm: https://www.npmjs.com/package/fontoxpath-module-loader
- npm.io page: https://npm.io/package/fontoxpath-module-loader

## Dependencies (1)

- [fontoxpath](https://npm.io/package/fontoxpath.md) ^3.21.0

## Recent versions

- 1.0.2 (latest) — 2021-10-12
- 1.0.1 — 2020-02-21
- 1.0.0 — 2020-02-21
- 1.0.0-rc.8 — 2020-02-19
- 1.0.0-rc.7 — 2020-02-19
- 1.0.0-rc.6 — 2020-02-19
- 1.0.0-rc.5 — 2020-02-19
- 1.0.0-rc.4 — 2020-02-19
- 1.0.0-rc.3 — 2020-02-18
- 1.0.0-rc.2 — 2020-02-18
- 1.0.0-rc.1 — 2020-02-18

## README

# fontoxpath-module-loader

Loads XQuery modules into [fontoxpath](https://github.com/FontoXML/fontoxpath) and does something with the result. Can
be easily configured to load that module from disk, or from a REST endpoint, or whatever else async stuff you have.

Exposes the `evaluateXPath` function which is similar to `fontoxpath.evaluateXPath`, except that you give it
the location of your "main" XQuery module and it will try to resolve any "library" XQuery modules from there.

## Use

```js
import { evaluateXPath, eva } from 'fontoxpath-module-loader';

const result = await evaluateXPath(
	// Given a target location and referrer, return the location.
	(referrer, target) => path.resolve(path.dirname(referrer), target),

	// Given a target location, return the contents of that XQuery module
	(target) => fs.readFileSync(target, 'utf8'),

	// The location of the main XQuery module
	'my-module-file.xqm'
);
```

Where `my-module-file.xqm` could contain, for example:

```xqm
import module namespace foo = "https://foo.bar" at "./my-other-xquery-example.xql";

foo:do-something()
```

## `evaluateXPath()`

Runs a query and returns the result to you. Is the same as `fontoxpath.evaluateXPath` with exception of the first three
arguments:

| _n_ | Name & type                                                           | Description                                                                                                                                                |
|-----|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.  | `resolveLocation (referrer: string, target: string): Promise<string>` | Translates a potentially relative file reference to an absolute file reference. Used to resolve one module referring to another one. May return a promise. |
| 2.  | `resolveContent (target: string): Promise<string>`                    | Download/steal/borrow the XQuery module source that belongs to the given `target` location. May return a promise.                                          |
| 3.  | `location: string`                                                    | The location of your main XQuery module.                                                                                                                   |

Please revise the [fontoxpath](https://github.com/FontoXML/fontoxpath) documentation for the other arguments of
`evaluateXPath`:

| _n_ | Name & type                         | Description                                                                                                                                                                       |
|-----|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 4.  | `contextNode?: fontoxpath.Node`     | Is exactly the `contextNode` argument that would normally be passed to `fontoxpath.evaluateXPath`.                                                                                |
| 5.  | `domFacade?: fontoxpath.IDomFacade` | Is exactly the `domFacade` argument that would normally be passed to `fontoxpath.evaluateXPath`.                                                                                  |
| 6.  | `variables?: object`                | Is exactly the `variables` argument that would normally be passed to `fontoxpath.evaluateXPath`.                                                                                  |
| 7.  | `returnType?: number`               | Is exactly the `returnType` argument that would normally be passed to `fontoxpath.evaluateXPath`.                                                                                 |
| 8.  | `options?: any`                     | Is exactly the `options` argument that would normally be passed to `fontoxpath.evaluateXPath`. The `language` property defaults to `fontoxpath.evaluateXPath.XQUERY_3_1_LANGUAGE` |

Returns a node, string, boolean, number, array, object or null based on the expression in your XQuery module file.

## `evaluateUpdatingExpression()`

Runs a query, updates the given DOM in place, and potentially also returns a result to you. Is the same as
`fontoxpath.evaluateUpdatingExpression` with exception of the first three arguments:

| _n_ | Name & type                                                           | Description                                                                                                                                                |
|-----|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.  | `resolveLocation (referrer: string, target: string): Promise<string>` | Translates a potentially relative file reference to an absolute file reference. Used to resolve one module referring to another one. May return a promise. |
| 2.  | `resolveContent (target: string): Promise<string>`                    | Download/steal/borrow the XQuery module source that belongs to the given `target` location. May return a promise.                                          |
| 3.  | `location: string`                                                    | The location of your main XQuery module.                                                                                                                   |

Please revise the [fontoxpath](https://github.com/FontoXML/fontoxpath) documentation for the other arguments of
`evaluateUpdatingExpression`:

| _n_ | Name & type                         | Description                                                                                        |
|-----|-------------------------------------|----------------------------------------------------------------------------------------------------|
| 4.  | `contextNode?: fontoxpath.Node`     | Is exactly the `contextNode` argument that would normally be passed to `fontoxpath.evaluateXPath`. |
| 5.  | `domFacade?: fontoxpath.IDomFacade` | Is exactly the `domFacade` argument that would normally be passed to `fontoxpath.evaluateXPath`.   |
| 6.  | `variables?: object`                | Is exactly the `variables` argument that would normally be passed to `fontoxpath.evaluateXPath`.   |
| 7.  | `options?: any`                     | Is exactly the `options` argument that would normally be passed to `fontoxpath.evaluateXPath`.     |

Will apply any updates as per your XQUF expression to the given `contextNode`. Additionally, your XQUF may return
something which results in this function resolving to that node, string, number, similar to what `evaluateXPath` would
return.

---
_Source: https://npm.io/package/fontoxpath-module-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
