npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

djs-utility

v4.0.0

Published

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

Downloads

20

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

npm install djs-utility

Importing the package

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

or via import

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

Using the features

pagination

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 MessageEmbeds 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)
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:

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

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

pagination(options);

Output:

pagination-example

Note: You need some intents to enable these features as per discord.js@v13. For reference see index.ts


string pagination

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:

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

stringPagination(options);

For NodeJS you can also set alias. For example:

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


confirm

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:

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


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 :

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

Output :

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

Contributing

Contributions are always welcome!

Steps to contribute:

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

Then you code will be reviewed by the authors.