Canvacord

RankCardBuilder

extendsBuilder<RankCardBuilderProps>

Creates a new rank card builder.

new RankCardBuilder()

Examples

1const card = new RankCardBuilder()
2 .setUsername('kiki')
3 .setDisplayName('Kiki')
4 .setDiscriminator('1234')
5 .setAvatar('...')
6 .setCurrentXP(300)
7 .setRequiredXP(600)
8 .setLevel(2)
9 .setRank(5)
10 .setStatus('online');
11
12const pngBuffer = await card.build({
13 format: 'png'
14});

Properties

components

The components of this builder.

graphemeProvider

The grapheme provider of this builder.

height

the height of this builder.

Type:number

options

The options manager of this builder.

Type:BuilderOptionsManager<RankCardBuilderProps>

tw

The tailwind subset to apply to this builder.

Type:string

width

the width of this builder.

Type:number

style

Get the style of this builder.

Type:CSSProperties

Methods

addComponent(component);

Add component to this builder.

ParameterTypeDescriptionOptional
component
T|Array<T>

the component to add.

adjustCanvas();

Adjust the canvas size.

bootstrap(data);

Bootstrap this builder with data.

ParameterTypeOptional
data
RankCardBuilderProps
Returns:void

build(options);

Convert this builder into an image.

ParameterTypeDescriptionOptional
options

the build options.

the image buffer or svg string.

render();

Renders this rank card into the canvas.

Returns:Promise<Element>

setAvatar(image);

Sets the avatar for this rank card.

ParameterTypeDescriptionOptional
image

The avatar for this rank card.

setBackground(image);

Sets the background for this rank card.

ParameterTypeDescriptionOptional
image

The background for this rank card.

setBackgroundCrop(pos);

Set background crop for this rank card.

ParameterTypeOptional
pos
Partial<undefined|Partial<{height:number|; width:number|; x:number|; y:number;}>>

setCurrentXP(xp);

Sets the current xp for this rank card.

ParameterTypeDescriptionOptional
xp

The current xp for this rank card.

setDisplayName(name);

Sets the username for this rank card.

ParameterTypeDescriptionOptional
name

The username for this rank card.

setFonts(fontConfig);

Sets the fonts to be used for this rank card.

ParameterTypeDescriptionOptional
fontConfig
Required<Partial<{progress:Partial<{level:Partial<{text:string|; value:string;}>|; rank:Partial<{text:string|; value:string;}>|; xp:Partial<{text:string|; value:string;}>;}>|; username:Partial<{handle:string|; name:string;}>;}>>

The fonts to be used for this rank card.

setGraphemeProvider(provider);

Set grapheme image provider for this builder.

ParameterTypeOptional
provider

setLevel(level);

Sets the level of this rank card.

ParameterTypeDescriptionOptional
level

The level of this rank card.

setOverlay(overlay);

Set overlay for this rank card.

ParameterTypeOptional
overlay

setProgressCalculator(calc);

Sets the progress calculator for this rank card. The value returned by this calculator defines the width of the progress bar.
Valid range is 0-100. Returning a number less than 0 or greater than 100 will be clamped within this range, or invalid values will result in 0% width.

ParameterTypeDescriptionOptional
calc
(current: number|required: number)=>number

The progress calculator for this rank card.

setRank(rank);

Sets the rank of this rank card.

ParameterTypeDescriptionOptional
rank

The rank of this rank card.

setRequiredXP(xp);

Sets the required xp for this rank card.

ParameterTypeDescriptionOptional
xp

The required xp for this rank card.

setStatus(status);

Sets the status for this rank card.

ParameterTypeDescriptionOptional
status
RankCardUserStatus

The status for this rank card.

setStyle(newStyle);

Set the style of this builder.

ParameterTypeDescriptionOptional
newStyle
CSSProperties

the new style.

setStyles(config);

Configures the renderer for this rank card.

ParameterTypeDescriptionOptional
config
Partial<Partial<{avatar:Partial<{container:Stylable|; image:Stylable|; status:Stylable;}>|; background:Stylable|; container:Stylable|; overlay:Stylable|; progressbar:Partial<{container:Stylable|; thumb:Stylable|; track:Stylable;}>|; statistics:Partial<{container:Stylable|; level:Partial<{container:Stylable|; text:Stylable|; value:Stylable;}>|; rank:Partial<{container:Stylable|; text:Stylable|; value:Stylable;}>|; xp:Partial<{container:Stylable|; text:Stylable|; value:Stylable;}>;}>|; username:Partial<{container:Stylable|; handle:Stylable|; name:Stylable;}>;}>>

The configuration for this rank card.

setTextStyles(config);

Configures the texts for this rank card.

ParameterTypeDescriptionOptional
config
Partial<Partial<{level:string|; rank:string|; xp:string;}>>

The configuration for this rank card.

setUsername(name);

Sets the handle name for this rank card.

ParameterTypeDescriptionOptional
name

The handle name for this rank card.

static from(template);

Create a builder from builder template.

ParameterTypeOptional
template
Returns:Builder<Record<string|unknown>>