ascii-kit
- API documentation
Classes
Font
Represents a font that can be used to generate ASCII art.
Example
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()
new Font(font: string): Font
Parameters
Parameter | Type |
---|---|
font | string |
Returns
Methods
metadata()
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()
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
Parameter | Type | Description |
---|---|---|
text | string | The text to generate ASCII art from. |
options ? | Options | Options 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()
new Tree(content: TreeContent, config?: TreeConfig): Tree
Creates an instance of the Tree generator.
Parameters
Parameter | Type | Description |
---|---|---|
content | TreeContent | The content object representing the directory structure. |
config ? | TreeConfig | An object with options for generating the directory structure string. |
Returns
Methods
generate()
generate(): string
Generates the string representation of the directory structure.
Returns
string
A string representing the content of structure
as a directory structure.
Properties
Property | Type |
---|---|
config | TreeConfig |
content | TreeContent |
Functions
image2ascii()
function image2ascii(input: Image2AsciiInput, opts?: Image2AsciiOptions): Promise<string>
Converts an image to an ASCII art string.
Parameters
Parameter | Type | Description |
---|---|---|
input | Image2AsciiInput | The path to the image to convert or a Buffer containing the image data. |
opts ? | Image2AsciiOptions | Optional options. |
Returns
Promise
<string
>
A promise that resolves with the ASCII art string.
Example
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()
function qrcode(input: string, opts?: QRcodeOpts): Promise<string>
Generates a QR code string.
Parameters
Parameter | Type | Description |
---|---|---|
input | string | The input string to generate the QR code from. |
opts ? | QRcodeOpts | Optional options for generating the QR code. |
Returns
Promise
<string
>
- A promise that resolves with the generated QR code string.
Example
try {
const qrString = await qrcode('https://dovenv.pigeonposse.com');
console.log(qrString);
} catch (error) {
console.error('Error generating QR code:', error);
}
svg2ascii()
function svg2ascii(input: string, opts?: Svg2AsciiOptions): Promise<string>
Converts a SVG string to an ASCII art string.
Parameters
Parameter | Type | Description |
---|---|---|
input | string | The SVG string to convert. |
opts ? | Svg2AsciiOptions | Optional options. |
Returns
Promise
<string
>
A promise that resolves with the ASCII art string.
Example
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()
function tree(content: TreeContent, opts?: TreeConfig): string
Returns a string representing the content of an object as a directory structure.
Parameters
Parameter | Type | Description |
---|---|---|
content | TreeContent | The content object representing the directory structure. |
opts ? | TreeConfig | An object with options for generating the directory structure string. |
Returns
string
A string representing the content of structure
as a directory structure.
Example
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
type Image2AsciiInput: ArrayBuffer | Buffer;
Input of the image.
Image2AsciiOptions
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
Name | Type | Description |
---|---|---|
aspectRatio ? | number | Since 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 ? | string | The 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 | string | The 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 | string | The width to resize the image to. Use a percentage to set the image width to x% of the terminal window width. Default 100% |
QRcodeOpts
type QRcodeOpts: {
small: boolean;
};
Type declaration
Name | Type |
---|---|
small | boolean |
TreeConfig
type TreeConfig: {
hook: {
onData: (data: TreeHookOptions) => TreeHookOptions;
transform: (data: TreeHookOptions) => string;
};
pattern: TreePattern;
};
Defines the configuration options for generating the directory tree.
Type declaration
Name | Type | Description |
---|---|---|
hook ? | { onData : (data : TreeHookOptions ) => TreeHookOptions ; transform : (data : TreeHookOptions ) => string ; } | Hook functions to modify the data passed and style the tree. |
hook.onData ? | (data : TreeHookOptions ) => TreeHookOptions | A custom function to modify the data passed to the style functions. |
hook.transform ? | (data : TreeHookOptions ) => string | A custom function to style the tree. |
pattern ? | TreePattern | Custom pattern to use for indentation and line breaks. |
TreeContent
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