Skip to content

Commit 13e43d6

Browse files
author
thuongtruong109
committed
docs(README): update description
1 parent f7332a4 commit 13e43d6

File tree

11 files changed

+58
-48
lines changed

11 files changed

+58
-48
lines changed

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
# v1.2.1 - 2025-08-26
1+
# v1.2.0 - 2025-08-26
22

33
## What changed
44

5-
- Refactor code into smaller modules
5+
- [Modularize refactor code](https://github.com/thuongtruong109/flashot/commit/f7332a493590b8f74485da727b7d54e23decb614)
66
- Image generation format choice (WebP, Png, Jpeg)
77
- Quality setting for Jpeg images
88
- Define tokens style (ThemedToken)
99
- Change default font family (JetBrains Mono)
1010
- Fix width size rendering
1111
- Improved error handling for invalid input
12-
- Ignore publish non-related files
12+
- Ignore publish non-related files (public/\*\*)
13+
- Update README description
1314

1415
# v1.1.0 - 2025-08-25
1516

1617
## What changed
1718

18-
- Added support for fetching code snippets from URLs
19+
- [Added support for fetching code snippets from URLs](https://github.com/thuongtruong109/flashot/commit/b1396d761c58415a77a7e68a9bb966f217762a10)
1920
- Improved image generation speed and quality
2021
- Enhanced customization options for themes and styles
2122

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ Flashot is the **blazing-fast image generation tool** for code snippets, designe
2121

2222
**Super fast:** (generated in **~135ms**)
2323

24-
<img src="./test/.snapshot/demo.png" alt="Example output" />
24+
<img src="./test/.snapshot/demo.webp" alt="Example output" />
2525
</div>
2626

2727
## ✨ Features
2828

2929
- 💻 **Inline code support:** Easily convert inline code snippets to images
3030
- 🌐 **URL support:** Fetch code snippets directly from URLs
31-
- 🎨 **Customizable themes:** Choose from various themes to match your style
31+
- 🎨 **Customizable styles:** Choose from various options to match your style
3232
- 🖼️ **High-quality output:** Generates crisp and clear images which keep the original code's formatting intact
3333
-**Blazing fast:** Optimized for speed, ensuring quick image generation
34-
- 🛠️ **Flexible API:** Easy to integrate into your projects with a simple API
34+
- 🛠️ **Easy to use:** Easy to integrate into your projects with a simple API
35+
- 🪓 **Multi-format support:** Generate images in various formats (PNG, JPEG, WebP)
36+
- 🔷 **TypeScript support:** Fully typed for better developer experience
37+
- 🔍 **Extensive testing:** Thoroughly tested with a comprehensive suite of unit tests
38+
- 🔋 **Easy integration:** Simple API for seamless integration into your projects
3539

3640
## 📦 Installation
3741

@@ -88,10 +92,12 @@ Then you can use the `buffer` to display the image or send it in a response.
8892
const defaultOptions = {
8993
lang: "ts", // default is javascript
9094
theme: "ayu-dark", // default is github-dark
91-
font: "https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2", // custom font
92-
width: 800, // default is auto
93-
height: 400, // default is auto
94-
bg: "transparent", // default is theme's background
95+
font: "https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2", // default is bunny.net/jetbrains-mono.
96+
format: OutputFormat.Png, // default is OutputFormat.Webp, has three options: OutputFormat.Png, OutputFormat.Jpeg, OutputFormat.Webp
97+
quality: 100, // default is 100 (1-100), only applies to JPEG formats
98+
width: 800, // default is system's width
99+
height: 400, // default is system's height
100+
bg: "transparent", // default is system's background
95101
gap: 1, // gap between lines (default is 1)
96102
style: {
97103
borderRadius: 10, // default is 8
@@ -101,24 +107,26 @@ const defaultOptions = {
101107
};
102108
```
103109

104-
| Option | Description | Default |
105-
| -------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
106-
| `lang` | Code language ([supported](https://shiki.style/languages)) | `"js"` |
107-
| `theme` | Rendering theme ([supported](https://shiki.style/themes)) | `"github-dark"` |
108-
| `font` | Font for rendering (URL or ArrayBuffer) | [`ubuntu`](https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2) |
109-
| `width` | Image width | System default |
110-
| `height` | Image height | System default |
111-
| `bg` | Background color | Theme's background |
112-
| `gap` | Gap between lines | `1` |
113-
| `style` | Additional container styles ([docs](https://takumi.kane.tw/docs/deep-dives/stylesheets)) | `{ borderRadius: 8, padding: 25 }` |
110+
| Option | Description | Default |
111+
| --------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
112+
| `lang` | Code language ([supported](https://shiki.style/languages)) | `"js"` |
113+
| `theme` | Rendering theme ([supported](https://shiki.style/themes)) | `"github-dark"` |
114+
| `font` | Font for rendering (URL or ArrayBuffer) | [`Jetbrains Mono`](https://fonts.bunny.net/jetbrains-mono/files/jetbrains-mono-latin-400-normal.woff2) |
115+
| `format` | Output image format (`OutputFormat.Png`, `OutputFormat.Jpeg`, `OutputFormat.Webp`) | `OutputFormat.Webp` |
116+
| `quality` | Image quality (1-100) for JPEG formats | `100` |
117+
| `width` | Image width | System default |
118+
| `height` | Image height | System default |
119+
| `bg` | Background color | Theme's background |
120+
| `gap` | Gap between lines | `1` |
121+
| `style` | Additional container styles ([docs](https://takumi.kane.tw/docs/deep-dives/stylesheets)) | `{ borderRadius: 8, padding: 25 }` |
114122

115123
## 📚 Technologies
116124

117125
-**[Bun](https://bun.sh)** - Fast all-in-one JavaScript runtime and toolkit
118126
- 🏗️ **[TypeScript](https://www.typescriptlang.org/)** - Type-safe development with strict mode enabled
119127
- 📦 **[Vite](https://vitejs.dev/)** - Lightning-fast build tool with optimized bundling
120-
- 🔋 **[Vitest](https://vitest.dev/)** - Blazing fast unit testing & interactive test UI framework
121-
- 🪓 **[shiki](https://github.com/shikijs/shiki)** and **[takumi](https://github.com/kane50613/takumi)**
128+
- 🧪 **[Vitest](https://vitest.dev/)** - Blazing fast unit testing & interactive test UI framework
129+
- 🎨 **[shiki](https://github.com/shikijs/shiki)** and **[takumi](https://github.com/kane50613/takumi)**
122130
- 📝 **[Biome](https://biomejs.dev/)** - Fast formatter and linter for consistent code style
123131
- 🚀 **Dual Module Support** - ESM and CommonJS output with proper type definitions
124132
- 🔥 **[ESLint](https://eslint.org/)** - Advanced linting with TypeScript and SonarJS rules

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "flashot",
3-
"description": "📟 Rapidly convert code snippets into images",
4-
"version": "1.2.0",
3+
"description": "📟 Rapidly snapshot code snippets as images",
4+
"version": "1.2.1",
55
"type": "module",
66
"main": "./dist/index.cjs",
77
"module": "./dist/index.js",

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export async function urlToImg(
2828
options?: ThemeOptions,
2929
): Promise<Buffer<ArrayBufferLike>> {
3030
try {
31-
const res = await fetch(url);
31+
const res = await fetch(url, {
32+
mode: "no-cors",
33+
});
3234
const data2 = await res.text();
3335
return codeToImg(data2, options);
3436
} catch (err) {

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export async function codeToContainer(
4949
}
5050

5151
export async function loadFont(font: string): Promise<ArrayBuffer> {
52-
return await fetch(font).then((r) => r.arrayBuffer());
52+
return await fetch(font, {
53+
mode: "no-cors",
54+
}).then((r) => r.arrayBuffer());
5355
}
5456

5557
export function renderSize(code: string, opts: Required<ThemeOptions>) {

test/.snapshot/custom.png

53 Bytes
Loading

test/.snapshot/demo.webp

38 Bytes
Loading

test/.snapshot/inline.webp

-13.5 KB
Loading

test/index.test.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,30 @@ import { codeToImg, urlToImg } from "../src";
77

88
describe("inline-test", () => {
99
it("default", async () => {
10-
const start = Date.now();
1110
const code = await readFile(fileURLToPath(import.meta.url), "utf8");
1211
const img = await codeToImg(code);
1312
const outDir = join(process.cwd(), "test/.snapshot");
1413
await mkdir(outDir, { recursive: true });
1514
const outPath = join(outDir, "inline.webp");
1615
await writeFile(outPath, img);
17-
const end = Date.now();
18-
console.log(`Image generated in ${end - start}ms`);
1916
});
2017

2118
it("demo", async () => {
2219
const sampleCode = `<!DOCTYPE html>
23-
<html lang="en">
24-
<head>
25-
<meta charset="UTF-8" />
26-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
27-
<link rel="icon" type="image/x-icon" href="favicon.ico" />
28-
<title>Flashot</title>
29-
</head>
30-
<body>
31-
<h1>Hello, world!</h1>
32-
<p>
33-
Welcome to Flashot, the tool for converting code snippets into images!
34-
</p>
35-
</body>
36-
</html>`;
20+
<html lang="en">
21+
<head>
22+
<meta charset="UTF-8" />
23+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
24+
<link rel="icon" type="image/x-icon" href="favicon.ico" />
25+
<title>Flashot</title>
26+
</head>
27+
<body>
28+
<h1>Hello, world!</h1>
29+
<p>
30+
Welcome to Flashot, the tool for converting code snippets into images!
31+
</p>
32+
</body>
33+
</html>`;
3734
const img = await codeToImg(sampleCode, {
3835
lang: "html",
3936
format: OutputFormat.WebP,
@@ -46,9 +43,9 @@ describe("inline-test", () => {
4643

4744
it("custom", async () => {
4845
const sampleCode = `package main
49-
func main() {
50-
fmt.Println("Hello, world!")
51-
}`;
46+
func main() {
47+
fmt.Println("Hello, world!")
48+
}`;
5249
const img = await codeToImg(sampleCode, {
5350
lang: "go",
5451
bg: "transparent",

0 commit comments

Comments
 (0)