Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
ascii-canvas
Advanced tools
Readme
ASCII canvas is library that help position elements on the screen.
I can be used with Node.js or Browser to render ASCII Text. I can be used with other ASCII libraries like charts and position them on the screen.
npm install ascii-canvas
const { Canvas, Item } = require('ascii-canvas');
// or
import { Canvas, Item } from 'ascii-canvas';
<script src="https://unpkg.com/ascii-canvas"></script>
<script>
const { Canvas, Item } = canvas;
</script>
const ROWS = 24;
const COLS = 80;
const my_canvas = new Canvas(COLS, ROWS);
// see boxen on npm
const str = boxen('unicorn', { padding: 1 });
const x_start = 10;
const y_start = 5;
myCanvas.append(new Item(frame()));
for (var i = 0; i < 3; ++i) {
const x = i * 10;
const y = i * 3;
const box = new Item(str, { x: x_start + x, y: y_start + y });
my_canvas.append(box);
}
console.log(my_canvas.toString());
// functions to render box frame
function rep(str, count) {
return new Array(count).fill(str).join('');
}
function frame() {
const output = [];
const x_count = COLS - 2;
const y_Count = ROWS - 2;
output.push(`+${rep('-', x_count)}+`);
for (let i = 0; i < y_Count; ++i) {
output.push(`|${rep(' ', x_count)}|`);
}
output.push(`+${rep('-', x_count)}+`);
return output.join('\n');
}
Browser Demo. To see demo in Node.js you need to do those steps.
# clone repo
git clone https://github.com/jcubic/ascii-canvas.git
cd ascii-canvas
# install dev dependencies (including example ASCII libraries)
npm install
# run the code
node --experimental-modules ./demo/demo.js
class Canvas {
constructor(width, height, { overflow: true || false });
remove(item);
resize(width, height);
append(item);
toString();
get children;
}
class Item {
constructor(string, {x, y, z});
clone();
remove();
update(string)
move({x,y,z});
get width;
get height;
get x;
get y;
get z;
get rect;
}
Copyright (C) 2020-2023 Jakub T. Jankiewicz jcubic@onet.pl
Released with MIT License
FAQs
String based text rendering for Node and Browser
The npm package ascii-canvas receives a total of 6 weekly downloads. As such, ascii-canvas popularity was classified as not popular.
We found that ascii-canvas demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.