Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lesjoursfr/html-to-image

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lesjoursfr/html-to-image - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

17

lib/index.d.ts
/// <reference types="node" />
import { URL } from "url";
interface OperationResult {
error: string | undefined;
result: "ok" | undefined;
}
export declare enum HtmlToImageOutputType {

@@ -11,2 +7,10 @@ png = "png",

}
export interface HtmlToImageOptions {
xvfb: boolean;
xvfbArgs: string | undefined;
}
export interface OperationResult {
error: string | undefined;
result: "ok" | undefined;
}
export declare class HtmlToImage {

@@ -17,5 +21,6 @@ url: URL;

outputType: HtmlToImageOutputType;
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType);
options: HtmlToImageOptions;
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType, options?: HtmlToImageOptions);
private command;
render(): Promise<OperationResult>;
}
export {};

@@ -9,2 +9,7 @@ "use strict";

const script = (0, path_1.resolve)(__dirname, "./electron.js");
var HtmlToImageOutputType;
(function (HtmlToImageOutputType) {
HtmlToImageOutputType["png"] = "png";
HtmlToImageOutputType["jpeg"] = "jpeg";
})(HtmlToImageOutputType || (exports.HtmlToImageOutputType = HtmlToImageOutputType = {}));
function cleanOutput(std) {

@@ -23,7 +28,2 @@ // We look for a line that contains a valid JSON string

}
var HtmlToImageOutputType;
(function (HtmlToImageOutputType) {
HtmlToImageOutputType["png"] = "png";
HtmlToImageOutputType["jpeg"] = "jpeg";
})(HtmlToImageOutputType || (exports.HtmlToImageOutputType = HtmlToImageOutputType = {}));
class HtmlToImage {

@@ -34,3 +34,4 @@ url;

outputType;
constructor(url, output, selector, outputType) {
options;
constructor(url, output, selector, outputType, options) {
// Required options

@@ -41,6 +42,13 @@ this.url = url;

this.outputType = outputType ?? HtmlToImageOutputType.jpeg;
this.options = options || { xvfb: false, xvfbArgs: undefined };
}
command() {
if (this.options.xvfb) {
return `xvfb-run ${this.options.xvfbArgs || ""} node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`;
}
return `node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`;
}
async render() {
// Render the Image
const command = `node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`;
// Render the PDF
const command = this.command();
const { stdout } = await execp(command);

@@ -47,0 +55,0 @@ // Clean output

{
"name": "@lesjoursfr/html-to-image",
"version": "1.0.0",
"version": "1.0.1",
"description": "A library to generate images from HTML.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -9,3 +9,13 @@ import { exec } from "child_process";

interface OperationResult {
export enum HtmlToImageOutputType {
png = "png",
jpeg = "jpeg",
}
export interface HtmlToImageOptions {
xvfb: boolean;
xvfbArgs: string | undefined;
}
export interface OperationResult {
error: string | undefined;

@@ -28,7 +38,2 @@ result: "ok" | undefined;

export enum HtmlToImageOutputType {
png = "png",
jpeg = "jpeg",
}
export class HtmlToImage {

@@ -39,4 +44,11 @@ url: URL;

outputType: HtmlToImageOutputType;
options: HtmlToImageOptions;
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType) {
constructor(
url: URL,
output: string,
selector: string,
outputType?: HtmlToImageOutputType,
options?: HtmlToImageOptions
) {
// Required options

@@ -47,9 +59,20 @@ this.url = url;

this.outputType = outputType ?? HtmlToImageOutputType.jpeg;
this.options = options || { xvfb: false, xvfbArgs: undefined };
}
async render(): Promise<OperationResult> {
// Render the Image
const command = `node ${require.resolve(
private command(): string {
if (this.options.xvfb) {
return `xvfb-run ${this.options.xvfbArgs || ""} node ${require.resolve(
"electron/cli.js"
)} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`;
}
return `node ${require.resolve(
"electron/cli.js"
)} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`;
}
async render(): Promise<OperationResult> {
// Render the PDF
const command = this.command();
const { stdout } = await execp(command);

@@ -56,0 +79,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc