Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically import fs #51

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fs from "fs";

class Bard {
static JSON = "json";
static MD = "markdown";
Expand Down Expand Up @@ -305,7 +303,18 @@ class Bard {
typeof config.image === "string" &&
/\.(jpeg|jpg|png|webp)$/.test(config.image)
) {
result.imageBuffer = fs.readFileSync(config.image).buffer;
import("fs")
.then((fs) => {
result.imageBuffer = fs.readFileSync(
config.image,
).buffer;
})
.catch((e) => {
throw new Error(
"Loading from an image file path is " +
"not supported in a browser environment",
);
});
} else {
throw new Error(
"Provide your image as a file path to a .jpeg, .jpg, .png, or .webp, or a Buffer."
Expand Down
Loading