# loy

> like joi but for outputs

Latest version **0.0.11** (published 2019-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install loy
pnpm add loy
yarn add loy
bun add loy
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2019-12-12 |
| First published | 2018-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 0 |
| Unpacked size | 30.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | fega |

## Links

- npm: https://www.npmjs.com/package/loy
- Repository: https://github.com/fega/loy
- Homepage: https://github.com/fega/loy#readme
- Issues: https://github.com/fega/loy/issues
- npm.io page: https://npm.io/package/loy

## Recent versions

- 0.0.11 (latest) — 2019-12-12
- 0.0.10 — 2019-10-25
- 0.0.9 — 2019-10-25
- 0.0.8 — 2019-10-25
- 0.0.7 — 2019-03-12
- 0.0.6 — 2019-03-12
- 0.0.5 — 2019-03-12
- 0.0.4 — 2019-03-12
- 0.0.3 — 2019-03-10
- 0.0.2 — 2018-11-26
- 0.0.1 — 2018-11-26
- 0.0.0 — 2018-11-23

## README

# loy

> Like Joi but for outputs

Loy is a little helper for defining REST outputs, Aimed to be used inside the [Moser web framework](https://github.com/fega/mongo-server).

Loy accomplish two missions:

- Define the REST output in order to generate documentation automatically.
- Restrict output fields based on user's permissions.

## Usage

Define an output function:

```javascript
import {Give} from 'Joi'

const out:(resource,user)=>{
  return {
    field1: Give(resource.field1, user)
      .for('admin') // define the necessary user permission
      .or('user') // alternative permission
      // documentation:
      .as('string')
      .example('field example')
      .description('field description')
      // always finish with this:
      .ok()
  }
}

```

Moser will execute the function, and return the field only if the user have the permission.

to get the output definition

```javascript
import {Give, Describe} from 'Joi'

const description= Describe(out)

```

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