charify 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 CrazyBrain Labs
3
+ Copyright (c) 2025 AbdoDev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "charify",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "High-quality image to ASCII art CLI",
5
5
  "keywords": [
6
6
  "ascii",
package/src/charify.js CHANGED
@@ -1,8 +1,10 @@
1
- import sharp from "sharp";
2
1
  import { PRESETS, DEFAULTS } from "./constants.js";
3
2
  import { SharpMissingError } from "./errors.js";
3
+ import { loadSharp } from "./loadSharp.js";
4
4
 
5
5
  export async function convertToAscii(buffer, options = {}) {
6
+ const sharp = await loadSharp();
7
+
6
8
  if (!sharp) {
7
9
  throw new SharpMissingError();
8
10
  }
@@ -0,0 +1,50 @@
1
+ import { execSync } from "child_process";
2
+ import readline from "readline";
3
+
4
+ let sharpInstance;
5
+
6
+ function askYesNo(question) {
7
+ return new Promise((resolve) => {
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout,
11
+ });
12
+
13
+ rl.question(question, (answer) => {
14
+ rl.close();
15
+ resolve(answer.trim().toLowerCase() === "y");
16
+ });
17
+ });
18
+ }
19
+
20
+ export async function loadSharp() {
21
+ if (sharpInstance) return sharpInstance;
22
+
23
+ try {
24
+ sharpInstance = (await import("sharp")).default;
25
+ return sharpInstance;
26
+ } catch {
27
+ console.warn(
28
+ "[Warning]: 'sharp' package not found. charify might not work without it."
29
+ );
30
+
31
+ const install = await askYesNo(
32
+ "Do you want to install 'sharp' now? (y/n): "
33
+ );
34
+ if (!install) {
35
+ console.log("Skipping 'sharp' installation. Please install it manually.");
36
+ return null;
37
+ }
38
+
39
+ try {
40
+ execSync("npm install sharp", { stdio: "inherit" });
41
+ sharpInstance = (await import("sharp")).default;
42
+ console.log("'sharp' installed successfully.");
43
+ return sharpInstance;
44
+ } catch (installErr) {
45
+ throw new Error(
46
+ "Failed to install 'sharp'. Please install it manually and try again."
47
+ );
48
+ }
49
+ }
50
+ }