# insomnia-plugin-utils

> Create new functions from arguments passed as key and value or in generic format and generate the values in the result you want

Latest version **1.0.3** (published 2022-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install insomnia-plugin-utils
pnpm add insomnia-plugin-utils
yarn add insomnia-plugin-utils
bun add insomnia-plugin-utils
```

## 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.3 |
| Published | 2022-10-19 |
| First published | 2022-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 882.5 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Puglielli |
| Maintainers | puglielli |
| Keywords | insomnia, plugin, custom, generate, random, json, string, converter, amount, functions |

## Links

- npm: https://www.npmjs.com/package/insomnia-plugin-utils
- Repository: https://github.com/Puglielli/insomnia-plugin-utils
- Issues: https://github.com/Puglielli/insomnia-plugin-utils/issues
- npm.io page: https://npm.io/package/insomnia-plugin-utils

## Dependencies (3)

- [fs](https://npm.io/package/fs.md) ^0.0.1-security
- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [moment](https://npm.io/package/moment.md) ^2.29.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-10-19
- 1.0.2 — 2022-10-19
- 1.0.1 — 2022-09-11
- 1.0.0 — 2022-09-10

## README

# insomnia-plugin-utils

Create complex or simple functions for your data directly in the Insomnia REST Client!

This plugin is published in [npm](https://www.npmjs.com/package/insomnia-plugin-utils).


## Installation

1. Open Insomnia.
2. Go to **Insomnia > Preferences**.
3. Go to "Plugins" tab.
4. Type "insomnia-plugin-utils" in the "Install Plugin" field.
5. Click "Install Plugin".

_Any questions about installing the plugin, go to [Insomnia "Managing plugins" documentation](https://support.insomnia.rest/article/26-plugins#managing-plugins)._


## Usage

Use [Template Tags](https://docs.insomnia.rest/insomnia/template-tags) (i.e. CTRL + SPACE, then find "Utils - *") to add plugin types.

![Screenshot](https://raw.githubusercontent.com/Puglielli/insomnia-plugin-utils/main/docs/images/template-tags-utils.png)

### Examples

- Random UUID
  - ![Screenshot](https://raw.githubusercontent.com/Puglielli/insomnia-plugin-utils/main/docs/images/example-uuid.png)

- Random Amount (to use the `Random amount` type, you need to enter two fields `min` and `max`)
  - ![Screenshot](https://raw.githubusercontent.com/Puglielli/insomnia-plugin-utils/main/docs/images/example-amount.png)


## Creativity and Imagination

- The `Random amount` type is an example of what can be created with this plugin, you can pass as many `key:value` as you need and assemble the return you want without having to do much.

- Structure of the types object.

  ```
  {
    type: string,
    displayName: string,
    liveDisplayName?: string,
    description?: string,
    method: (args) => expression,

    // Only type === 'enum'
    options: Array<{
      {
        displayName: string,
        value: string
      }
    ]
  }
  ```

### Example to add new basic type

- Open the file `types-method.js`.
- Look up for the variable `typesMethod`.
- You can follow the pattern of [insomnia](https://docs.insomnia.rest/insomnia/template-tags) doc itself or duplicate existing types except `Random amount`.

### Example to add new complex type

- Open the file `types-method.js`.
- Look up for the variable `typesMethod`.
- Now to create one more complex type like `Random amount`.

- Structure type
  ```
  {
    type: "string",
    displayName: "Random names",
    liveDisplayName: "Name",
    description: "Generate random names",
    defaultValue: "names: Philip,Luciana",
    method: (args) => random_names(args)
  }
  ```

- Structure function
  ```
  const random_names = (args) => {
    const value = getArgsValue(args)
    const keys = ["names"]

    let isValid = containsKeys(value, ...keys)

    if (!isValid.ok) {
      const errorMessage = `The input { ${value} } not contain all keys [${keys}] is missing ${isValid.missingKeys}`
      console.error(errorMessage)
      return errorMessage
    }

    const obj = toObject(value)

    names = obj.names.split(',')

    const random = Math.floor(Math.random() * names.length);

    return names[random]
  }
  ```

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