Skip to content

LLM Resources

ascii-kit - API documentation

Classes

Font

Represents a font that can be used to generate ASCII art.

Example

ts
import font1row from '@ascci-art/font-1row'
import { Font } from '@ascii-art/core'

const font = new Font( font1row )
console.log( await font.text( 'Boo!' ) )

Constructors

new Font()
ts
new Font(font: string): Font
Parameters
ParameterType
fontstring
Returns

Font

Methods

metadata()
ts
metadata(): Promise<FontMeta>

Gets the metadata for the font.

Returns

Promise<FontMeta>

An object containing the metadata: - fig: The font's layout data. - options: The default options for the font. - numChars: The number of characters in the font. - comment: The font's comment.

text()
ts
text(text: string, options?: Options): Promise<string>

Generate a string of ASCII art from the given text, using the font that this class was constructed with.

Parameters
ParameterTypeDescription
textstringThe text to generate ASCII art from.
options?OptionsOptions to pass to the underlying figlet.text method.
Returns

Promise<string>

A promise that resolves with the generated ASCII art.


Tree

Represents a utility for generating a directory structure string from an object.

Constructors

new Tree()
ts
new Tree(content: TreeContent, config?: TreeConfig): Tree

Creates an instance of the Tree generator.

Parameters
ParameterTypeDescription
contentTreeContentThe content object representing the directory structure.
config?TreeConfigAn object with options for generating the directory structure string.
Returns

Tree

Methods

generate()
ts
generate(): string

Generates the string representation of the directory structure.

Returns

string

A string representing the content of structure as a directory structure.

Properties

PropertyType
configTreeConfig
contentTreeContent

Functions

image2ascii()

ts
function image2ascii(input: Image2AsciiInput, opts?: Image2AsciiOptions): Promise<string>

Converts an image to an ASCII art string.

Parameters

ParameterTypeDescription
inputImage2AsciiInputThe path to the image to convert or a Buffer containing the image data.
opts?Image2AsciiOptionsOptional options.

Returns

Promise<string>

A promise that resolves with the ASCII art string.

Example

ts
const res = await fetch(
  'https://raw.githubusercontent.com/pigeonposse/backan/main/docs/public/logo.png'
);
const input = await res.arrayBuffer();
const ascii = await image2ascii( input, {
  fit         : 'width',
  width       : '100%',
  height      : '100%',
  chars       : ' #+@',
} )

console.log( ascii )

qrcode()

ts
function qrcode(input: string, opts?: QRcodeOpts): Promise<string>

Generates a QR code string.

Parameters

ParameterTypeDescription
inputstringThe input string to generate the QR code from.
opts?QRcodeOptsOptional options for generating the QR code.

Returns

Promise<string>

  • A promise that resolves with the generated QR code string.

Example

ts
try {
  const qrString = await qrcode('https://dovenv.pigeonposse.com');
  console.log(qrString);
} catch (error) {
  console.error('Error generating QR code:', error);
}

svg2ascii()

ts
function svg2ascii(input: string, opts?: Svg2AsciiOptions): Promise<string>

Converts a SVG string to an ASCII art string.

Parameters

ParameterTypeDescription
inputstringThe SVG string to convert.
opts?Svg2AsciiOptionsOptional options.

Returns

Promise<string>

A promise that resolves with the ASCII art string.

Example

ts
const input = `
<svg width="200" height="200" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
  <circle cx="100" cy="100" r="50" fill="#FF0000"/>
</svg>
`
const ascii = await svg2ascii( input )
console.log( ascii )

tree()

ts
function tree(content: TreeContent, opts?: TreeConfig): string

Returns a string representing the content of an object as a directory structure.

Parameters

ParameterTypeDescription
contentTreeContentThe content object representing the directory structure.
opts?TreeConfigAn object with options for generating the directory structure string.

Returns

string

A string representing the content of structure as a directory structure.

Example

ts
const result = tree({
  src: {
    components: {
      "Button.js": null,
      "Header.js": null
    },
    utils: {
      "helpers.js": null
    },
    "index.js": null
  },
  "package.json": null
  name: "my-project",
});

console.log(result);

Type Aliases

Image2AsciiInput

ts
type Image2AsciiInput: ArrayBuffer | Buffer;

Input of the image.


Image2AsciiOptions

ts
type Image2AsciiOptions: {
  aspectRatio: number;
  chars: string;
  container: {
     height: number;
     width: number;
    };
  fit:   | "box"
     | "width"
     | "height"
     | "original"
     | "none";
  height: number | string;
  width: number | string;
};

Type declaration

NameTypeDescription
aspectRatio?numberSince a monospace character is taller than it is wide, this property defines the integer approximation of the ratio of the width to height. You probably don't need to change this. Default 2
chars?stringThe characters to use for the asciified image. Default .,:;i1tfLCG08@
container?{ height: number; width: number; }The container options for the asciified image.
container.height?number-
container.width?number-
fit?| "box" | "width" | "height" | "original" | "none"The fit to resize the image to: • box - Resize the image such that it fits inside a bounding box defined by the specified width and height. Maintains aspect ratio. • width - Resize the image by scaling the width to the specified width. Maintains aspect ratio. • height - Resize the image by scaling the height to the specified height. Maintains aspect ratio. • original - Doesn't resize the image. • none - Scales the width and height to the specified values, ignoring original aspect ratio. Default box
height?number | stringThe height to resize the image to. Use a percentage to set the image width to x% of the terminal window height. Default 100%
width?number | stringThe width to resize the image to. Use a percentage to set the image width to x% of the terminal window width. Default 100%

QRcodeOpts

ts
type QRcodeOpts: {
  small: boolean;
};

Type declaration

NameType
smallboolean

TreeConfig

ts
type TreeConfig: {
  hook: {
     onData: (data: TreeHookOptions) => TreeHookOptions;
     transform: (data: TreeHookOptions) => string;
    };
  pattern: TreePattern;
};

Defines the configuration options for generating the directory tree.

Type declaration

NameTypeDescription
hook?{ onData: (data: TreeHookOptions) => TreeHookOptions; transform: (data: TreeHookOptions) => string; }Hook functions to modify the data passed and style the tree.
hook.onData?(data: TreeHookOptions) => TreeHookOptionsA custom function to modify the data passed to the style functions.
hook.transform?(data: TreeHookOptions) => stringA custom function to style the tree.
pattern?TreePatternCustom pattern to use for indentation and line breaks.

TreeContent

ts
type TreeContent: {};

The content object representing the directory structure. A file is represented by null, and a folder by a nested TreeContent object.

Index Signature

[key: string]: null | Tree | TreeContent