npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@qumra/arabic-canvas

v0.1.5

Published

Render Arabic text (shaping + RTL) onto a canvas as an image for thermal printing

Readme

@qumra/arabic-canvas

npm version types license

Render Arabic text correctly (shaping + letter joining + RTL) onto a canvas, ready to print as an image.

Part of the @qumra suite — and Qumra's competitive edge. Thermal printers cannot reliably print Arabic as text, so the only dependable approach is to render it as an image. This package does exactly that, leaning on the browser's text-shaping engine (Canvas 2D) which joins letters and handles direction automatically.

Features

  • 🅰️ Correct Arabic — shaping, letter joining, and RTL handled by the browser engine.
  • 🧾 Two entry points: renderArabic (free text) and renderReceipt (full layout).
  • ↩️ Automatic word wrapping for lines wider than the paper.
  • 📐 Height auto-rounded to a multiple of 8 (an ESC/POS requirement).
  • 🧩 Low-level canvas helpers exported for building custom layouts.

Installation

npm install @qumra/arabic-canvas

Quick start

import { renderArabic, renderReceipt } from '@qumra/arabic-canvas';
import { QumraReceiptEncoder } from '@qumra/receipt-encoder';

// A single line (defaults to 58mm / 384 dots — pass width: 576 for 80mm)
const canvas = renderArabic('مرحباً بكم في قمرة');

// Or a full receipt layout
const receipt = renderReceipt({
  storeName: 'متجر قمرة',
  items: [{ name: 'قهوة', price: '15.00' }],
  total: '15.00',
  footer: 'شكراً لزيارتكم',
});

const data = new QumraReceiptEncoder().initialize().image(receipt).cut().encode();

API

renderArabic(text, options?)HTMLCanvasElement

Renders text (one or more lines separated by \n).

| Option | Default | Description | |---|---|---| | width | 384 | Image width in dots (58mm; use 576 for 80mm). | | fontSize | 28 | Font size in pixels. | | fontFamily | 'sans-serif' | Font family. | | align | 'right' | 'right' \| 'center' \| 'left'. | | padding | 16 | Side padding in pixels. | | wrap | true | Wrap lines wider than the image. |

renderReceipt(content, options?)HTMLCanvasElement

Renders a full receipt layout (header, items with prices, total, footer).

content: {
  storeName?: string; address?: string; date?: string;
  items?: { name: string; price: string | number }[];
  total?: string | number; footer?: string;
}
options?: { width?: number; fontFamily?: string; padding?: number; wrap?: boolean }

width defaults to 384 (58mm). The image height is rounded up to a multiple of 8.

Low-level helpers

| Export | Description | |---|---| | createCanvas(width, height) | Canvas with height rounded to a multiple of 8. | | ctxOf(canvas) | A 2D context configured for top-baseline drawing. | | prepareSurface(ctx, w, h) | White background + black ink. | | createMeasureContext() | A 1×1 context for measuring text width. | | wrapLine · wrapLines | Pure, testable word-wrap utilities. |

Requirements

  • Requires a browser environment (Canvas 2D) — available in the browser and the Electron renderer.
  • Node support (server-side rendering via node-canvas) is on the roadmap.

Related packages

License

MIT © Qumra