# @statoscope/stats-extension-custom-reports

> Statoscope extension to store custom reports in stats

Latest version **5.28.1** (published 2023-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @statoscope/stats-extension-custom-reports
pnpm add @statoscope/stats-extension-custom-reports
yarn add @statoscope/stats-extension-custom-reports
bun add @statoscope/stats-extension-custom-reports
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.28.1 |
| Published | 2023-10-20 |
| First published | 2021-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1579 |
| Author | Sergey Melyukov |
| Maintainers | smelukov |

## Links

- npm: https://www.npmjs.com/package/@statoscope/stats-extension-custom-reports
- Repository: https://github.com/statoscope/statoscope
- Homepage: https://github.com/statoscope/statoscope/
- Issues: https://github.com/statoscope/statoscope/issues
- npm.io page: https://npm.io/package/@statoscope/stats-extension-custom-reports

## Dependencies (4)

- [@statoscope/stats](https://npm.io/package/@statoscope/stats.md) 5.28.1
- [@statoscope/types](https://npm.io/package/@statoscope/types.md) 5.28.1
- [@statoscope/helpers](https://npm.io/package/@statoscope/helpers.md) 5.28.1
- [@statoscope/extensions](https://npm.io/package/@statoscope/extensions.md) 5.28.1

## Recent versions

- 5.28.1 (latest) — 2023-10-20
- 5.28.0 — 2023-09-24
- 5.27.0 — 2023-08-24
- 5.25.0 — 2023-02-17
- 5.25.0-alpha.0 — 2023-02-16
- 5.24.0 — 2022-07-22
- 5.23.0 — 2022-07-14
- 5.22.0 — 2022-07-03
- 5.19.0 — 2021-11-25
- 5.14.1 — 2021-10-13
- 5.14.0 — 2021-10-13
- 5.13.1 — 2021-10-11
- 5.12.1 — 2021-10-08
- 5.9.0 — 2021-09-27

## README

# Statoscope Package Custom Reports

[![npm version](https://badge.fury.io/js/%40statoscope%2Fstats-extension-package-info.svg)](https://badge.fury.io/js/%40statoscope%2Fstats-extension-custom-reports)
[![Financial Contributors on Open Collective](https://opencollective.com/statoscope/all/badge.svg?label=financial+contributors)](https://opencollective.com/statoscope)

Statoscope extension to store custom reports in stats.

A custom report is:

```ts
export type Report<TData, TContext> = {
  id: string; // report id
  name?: string; // report title
  compilation?: string | null; // if specified then a report will be shown only in specific compilation
  data?: TData | (() => Promise<TData> | TData); // raw data for the report or a function that produces a data (may return promise)
  view: string | ViewConfig<TData, TContext>; // any DiscoveryJS. String turns to script to eval
};
```

## View as a script

Sometimes we need to make a report with more complex view (e.g. with event handling).

JSON can't handle functions, but you can pass any script source into `view`-property instead of JSON.

This source will be `eval`ed on client and should return any DiscoveryJS view.

**my-custom-report-view.js:**
```js
(() => [
  {
    view: 'button',
    data: {
      text: 'Click me',
    },
    onClick() {
      alert('It works!');
    },
  },
])();
```

**Report config:**
```js
({
  id: 'foo',
  view: fs.readFileSync('./my-custom-report-view.js', 'utf8')
})
```

---
_Source: https://npm.io/package/@statoscope/stats-extension-custom-reports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
