# djs-utility

> A package to help you out make discord bots with discord.js easily.

Latest version **4.0.0** (published 2022-05-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install djs-utility
pnpm add djs-utility
yarn add djs-utility
bun add djs-utility
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-05-04 |
| First published | 2021-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 54.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Krish |
| Maintainers | itskrish |
| Keywords | d.js-utility, pagination, confirm, discord.js |

## Links

- npm: https://www.npmjs.com/package/djs-utility
- Repository: https://github.com/KrishAgarwal2811/djs-utility
- Homepage: https://github.com/KrishAgarwal2811/djs-utility#readme
- Issues: https://github.com/KrishAgarwal2811/djs-utility/issues
- npm.io page: https://npm.io/package/djs-utility

## Dependencies (1)

- [discord.js](https://npm.io/package/discord.js.md) ^13.0.1

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2022-05-04
- 3.2.0 (next) — 2022-02-02
- 3.2.1 — 2022-02-02
- 3.1.0 — 2021-10-01
- 2.1.0 — 2021-08-13
- 2.0.3 — 2021-08-06
- 2.0.2 — 2021-08-06
- 2.0.1 — 2021-08-06
- 2.0.0 — 2021-07-09

## README

# A library to make your discord bot easily.

`djs-utility` is for helping you out to write less code and do your stuff. It provides you with some pre-written code which you can to do compicated in just cuople of lines.

# Documentation

Install the package

```bash
npm install djs-utility
```

Importing the package

```js
const utility = require("djs-utility");
```

or via import

```js
import * as utility from ("djs-utility");
```

## Using the features

### `pagination`

```js
const { pagination } = require("djs-utility");

pagination({
  message: message,
  pages: [embedOne, embedTwo, ..., lastEmbed],
  initialText: "`!help command` will show an extra help"
});

```

**Parameters:**

- **message** - The message object (required)
- **pages** - An array of `MessageEmbed`s as individual pages (required)
- **initialPage** - The starting page number if you don't want it to be 0. _Default is 0_ (optional)
- **initialText** - If you want any extra text on top of every pages. _Default is ""_ (optional)
- **timeout** - The maximun amount of time the reaction collector will listen for reactions. _Default is `12000`_. (optional)
- **emojis** - If you don't want the default emojis. Pass an object. (optional)

```js
emojis: {
  pageNumber: EmojiResolvable,
  home: EmojiResolvable,
  left: EmojiResolvable,
  right: EmojiResolvable,
  end: EmojiResolvable,
  stop: EmojiResolvable,
}
```

> You can also import `paginationEmbedOptions` and `emojiOptions` for defining optional variables.
> For example:

```ts
import { paginationEmbedOptions, emojiOptions, pagination } from "djs-utility";
const emojis: emojiOptions = {
  ...
}

const options: paginationEmbedOptions = {
  ...,
  emojis
}

pagination(options);
```

> Output:
>
> ![pagination-example](./images/pagination.png)

> _Note: You need some intents to enable these features as per discord.js@v13. For reference see [index.ts](./src/test-bot/index.ts)_

---
### `string pagination`

```js
const { stringPagination } = require("djs-utility");

stringPagination({
  message: message,
  pages: [embedOne, embedTwo, ..., lastEmbed]
});
```

**Parameters:**

- **message** - The message object (required)
- **pages** - An array of `String` as individual pages (required)
- **initialPage** - The starting page number if you don't want it to be 0. _Default is 0_ (optional)
- **timeout** - The maximun amount of time the reaction collector will listen for reactions. _Default is `12000`_. (optional)
- **emojis** - If you don't want the default emojis. Pass an object. (optional)

> Emojis are same for this too (`emojiOptions`)
>
> Similarly you can also import `stringPaginationEmbedOptions`.

> For example:

```ts
import { stringPaginationEmbedOptions as pgOptions, stringPagination } from "djs-utility";
const options: pgOptions = {
  ...
}

stringPagination(options);
```

> For NodeJS you can also set alias. For example:

```js
const { stringPagination: pagination } = require("djs-utility");

pagination(...);
```

> _Note: You need some intents to enable these features as per discord.js@v13. For reference see [index.ts](./src/test-bot/index.ts)_

---
### `confirm`

```js
const { confirm } = require("djs-utility");

confirm({
  message,
  content: "Are you sure?",
})
  .then((result) => {
    // result is true if user reacts with the check
    // or else it's false if user reacts with cross emoji
  })
  .catch((err) => {
    // err.error = true
    // in the most cases err.errorType will be timeout error
  });
```

**Parameters:**

- **message** - The message object (required)
- **content** - Either it must be a `string` or `MessageEmbed` (required)
- **timeout** - The maximun amount of time the reaction collector will listen for reactions. _Default is `60000`_. (optional)
- **emojis** - If you don't want the default emojis. Pass an object. (optional)
  - check - The check emoji which results to true
  - cross - The cross emoji which results to false

> You can import `confirmOptions` for typescript intellisense
>
> For example:

```ts
import { confirm, confirmOptions } from "djs-utility";
const options: confirmOptions = {
  ...
}

confirm(options);
```

> _Note: You need some intents to enable these features as per discord.js@v13. For reference see [index.ts](./src/test-bot/index.ts)_

---
### `codeBlockParser`
A code Block Parser to extract language and code out of code blocks.

**Parameters:**
- **string** - string containing codeBlock

**return:**
- `Array<[Object]>`
  - `lang ?: string`
  - `code ?: string`
> Example :

```ts
import {codeBlockParser} from "djs-utility";
console.log(
  codeBlockParser("```js\n🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working```"));
```
> Output :

```js
[{ lang: 'js', code: '🥳🥳🥳🥳🥳🥳🥳🥳🥳🥳 working' }]
```

---
# Contributing
Contributions are always welcome!

### Steps to contribute:

1. Fork the repo
1. Clone the repo `git clone <your forked repo>`
1. Make a new branch for your feature
1. Write the code
1. Make a new file called `config.js` in `test` folder and copy the contents of `test/sample.config.js` and update the token.
1. Run `npm run test:all` _(See more scripts in `package.json`)_
1. Push you code and make a pull request
1. That's it!

> Then you code will be reviewed by the authors.

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