# metricsfn

> Get metric data on your scripts

Latest version **1.0.41** (published 2023-11-09) · MIT license · 0 weekly downloads

## Install

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

## 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.41 |
| Published | 2023-11-09 |
| First published | 2023-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | pupariadev |
| Maintainers | pupariadev |
| Keywords | metrics, analytics, pupariaa, monitoring, followed, follow, scripts |

## Links

- npm: https://www.npmjs.com/package/metricsfn
- Repository: https://github.com/Pupariaa/MetricsFn
- Homepage: https://github.com/Pupariaa/MetricsFn#readme
- Issues: https://github.com/Pupariaa/MetricsFn/issues
- npm.io page: https://npm.io/package/metricsfn

## Recent versions

- 1.0.41 (latest) — 2023-11-09
- 1.0.4 — 2023-11-09
- 1.0.3 — 2023-11-09
- 1.0.2 — 2023-11-09
- 1.0.1 — 2023-11-09
- 1.0.0 — 2023-11-09

## README

# Metricsfn

## Introduction

`metricsfn` is a lightweight JavaScript library designed to facilitate the collection of metrics and performance data in an application.

## Installation

Install the library via npm:

```bash
npm install metricsfn
```



## Usage
```JS const Metrics = require('metrics-library');

// Create an instance of Metrics
const metrics = new Metrics();

// Initialize Metrics
metrics.Init();

// Add an ID
metrics.ID(123);

// Add data
metrics.UserID('user123')
    .TimeSamp()
    .ParseErrors();

// Retrieve data
const data = metrics.env();
console.log(data);
```
## Example 
```JS
const axios = require('axios')
const Metrics = require('metricsfn')
const metrics = new Metrics();

async function makeRequest(url, method = 'GET', data = null) {
  metrics.Init();
  const id = 123
  metrics.ID(id);
  metrics.ID(id).TimeSamp()

  const datas = {};
  const metricsDatas = {};

  try {
    metrics.TimerStart(id);
    const response = await axios({
      method,
      url,
      data,
    });

    metrics.ID(id).FetchTimeExec(metrics.TimerStop(id)).Success()
    datas = response.data
    metricsDatas = metrics.ID(id).env()

    return {datas, metricsDatas};

  } catch (error) {
    metrics.ID(id).FetchTimeExec(metrics.TimerStop(id)).FetchError().Aborted()
    metricsDatas = metrics.ID(id).env()

    return {datas, metricsDatas};

  }

}

const apiUrl = 'https://jsonplaceholder.typicode.com/posts/1';
makeRequest(apiUrl, 'GET');
```

## Available Methods

### `Init()`

Initializes the Metrics library.

### `ID(id: string)`

Adds a new ID to the data table.

- `id`: Unique identifier.

### `UserID(data: string)`

Adds the user ID to the data.

- `data`: User ID.

### `TimeSamp()`

Adds a timestamp to the data.

### `ParseErrors()`

Increments the parse errors count in the data.

### `SyntaxErrors()`

Increments the syntax errors count in the data.

### `FilterTimeExec(timesamp: string)`

Adds filter execution time to the data.

- `timesamp`: Timestamp of filter execution time.

### `GenerateTimeExec(timesamp: string)`

Adds generation execution time to the data.

- `timesamp`: Timestamp of generation execution time.

### `FetchTimeExec(timesamp: string)`

Adds fetch execution time to the data.

- `timesamp`: Timestamp of fetch execution time.

### `Aborted()`

Indicates in the data that the operation was aborted.

### `Exited()`

Indicates in the data that the operation was exited.

### `Success()`

Indicates in the data that the operation was successful.

### `TimerStart(key: string)`

Starts a timer with the specified key.

- `key`: Timer key.

### `TimerStop(key: string)`

Stops the timer and returns the elapsed time.

- `key`: Timer key.

### `TimerClear(key: string)`

Stops and clears the timer associated with the specified key.

- `key`: Timer key.

### `env()`

Gets the complete data array.

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