Home Reference Source Repository
import Util from 'discord-graf/src/util.js'
public class | source

Util

Static Member Summary

Static Public Members
public static get

Useful pattern constants

Static Method Summary

Static Public Methods
public static

disambiguation(items: Object[], label: string, property: string): string

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

public static

nbsp(text: string): string

Convert spaces to non-breaking spaces

public static

paginate(items: Object[], page: number, pageLength: number): Object

Paginate an array of items

public static

search(items: Object[], searchString: string, options: Object): Object[]

Search for matches in a list of items

public static

split(text: string, maxLength: number, splitOn: string): string[]

Splits a string using specified characters into multiple strings of a maximum length

public static

usage(command: string, server: Server, onlyMention: boolean): string

Build a command usage string

Static Public Members

public static get patterns: Object source

Useful pattern constants

Static Public Methods

public static disambiguation(items: Object[], label: string, property: string): string source

Build a disambiguation list - useful for telling a user to be more specific when finding partial matches from a command

Params:

NameTypeAttributeDescription
items Object[]

An array of items to make the disambiguation list for

label string

The text to refer to the items as (ex. "characters")

property string
  • optional
  • default: name

The property on items to display in the list

Return:

string

The disambiguation list

public static nbsp(text: string): string source

Convert spaces to non-breaking spaces

Params:

NameTypeAttributeDescription
text string

The text to convert

Return:

string

The converted text

public static paginate(items: Object[], page: number, pageLength: number): Object source

Paginate an array of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to paginate

page number
  • optional
  • default: 1

The page to select

pageLength number
  • optional
  • default: 10

The number of items per page

Return:

Object

The resulting paginated object

Return Properties:

NameTypeAttributeDescription
items Object[]

The chunk of items for the current page

page number

The current page

maxPage number

The maximum page

pageLength number

The numer of items per page

pageText string

The current page string ("page x of y")

Search for matches in a list of items

Params:

NameTypeAttributeDescription
items Object[]

An array of items to search in

searchString string

The string to search for

options Object

An options object

options.property string
  • optional
  • default: name

The property on items to search against

options.searchInexact boolean
  • optional
  • default: true

Whether or not to search for inexact matches

options.searchExact boolean
  • optional
  • default: true

Whether or not to search for exact matches (will narrow down inexact matches if applicable)

options.useStartsWith boolean
  • optional
  • default: false

Whether or not to search inexact by checking to see if the item starts with the search string rather than contains

Return:

Object[]

The matched items

public static split(text: string, maxLength: number, splitOn: string): string[] source

Splits a string using specified characters into multiple strings of a maximum length

Params:

NameTypeAttributeDescription
text string

The string to split

maxLength number
  • optional
  • default: 1925

The maximum length of each split string

splitOn string
  • optional
  • default: \n

The characters to split the string with

Return:

string[]

The split strings

public static usage(command: string, server: Server, onlyMention: boolean): string source

Build a command usage string

Params:

NameTypeAttributeDescription
command string

The short command string (ex. "roll d20")

server Server
  • optional
  • default: null
  • nullable: true

The Discord.js Server instance of the server to use the prefix of

onlyMention boolean
  • optional
  • default: false

Whether or not the usage string should only show the mention form

Return:

string

The command usage string