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

idea-html2pdf

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idea-html2pdf - npm Package Compare versions

Comparing version 1.0.6 to 1.1.0

dist/src/html2pdf.d.ts

152

.eslintrc.js
module.exports = {
overrides: [
{
files: ['*.ts'],
env: {
browser: true,
es6: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
},
plugins: ['@typescript-eslint', 'eslint-plugin-import', 'eslint-plugin-jsdoc', 'eslint-plugin-prefer-arrow'],
rules: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
Object: {
message: 'Avoid using the `Object` type. Did you mean `object`?'
},
Function: {
message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.'
},
Boolean: {
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?'
},
Number: {
message: 'Avoid using the `Number` type. Did you mean `number`?'
},
String: {
message: 'Avoid using the `String` type. Did you mean `string`?'
},
Symbol: {
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?'
}
}
}
],
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: { delimiter: 'semi', requireLast: true },
singleline: { delimiter: 'semi', requireLast: false }
}
],
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-inferrable-types': ['error', { ignoreParameters: true }],
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }],
'@typescript-eslint/semi': ['error', 'always', { omitLastInOneLineBlock: true }],
'@typescript-eslint/triple-slash-reference': [
'error',
{ path: 'always', types: 'prefer-import', lib: 'always' }
],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unified-signatures': 'error',
'arrow-body-style': 'error',
'arrow-parens': ['off', 'always'],
'brace-style': ['error', '1tbs'],
'comma-dangle': ['error', 'never'],
complexity: 'off',
'constructor-super': 'error',
curly: 'off',
'eol-last': 'error',
eqeqeq: ['error', 'always'],
'guard-for-in': 'error',
'max-classes-per-file': 'off',
'max-len': ['error', { code: 120, tabWidth: 2 }],
'new-parens': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-caller': 'error',
'no-case-declarations': 'off',
'no-cond-assign': 'error',
'no-console': ['error', { allow: ['log'] }],
'no-debugger': 'error',
'no-empty': 'error',
'no-eval': 'error',
'no-extra-semi': 'error',
'no-fallthrough': 'error',
'no-invalid-this': 'error',
'no-irregular-whitespace': 'error',
'no-multiple-empty-lines': 'error',
'no-new-wrappers': 'error',
'no-restricted-imports': ['error', 'rxjs/Rx'],
'no-shadow': 'off',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unsafe-finally': 'error',
'no-unused-labels': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': 'off',
'prefer-const': 'error',
'quote-props': ['error', 'as-needed'],
radix: 'error',
'space-before-function-paren': ['error', 'never'],
'space-in-parens': ['error', 'never'],
'spaced-comment': ['error', 'always', { markers: ['/'] }],
'use-isnan': 'error',
'valid-typeof': 'error'
}
}
]
root: true,
env: {
browser: true,
es6: true,
node: true,
commonjs: true
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-explicit-any': 0
}
};

@@ -1,1 +0,1 @@

export * from './html2pdf';
export * from './src/html2pdf';

@@ -1,348 +0,2 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(global, function() {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 77:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.PDF_TEMPLATE = exports.HTML2PDF = void 0;
const aws_sdk_1 = __webpack_require__(480);
const handlebars_1 = __webpack_require__(778);
const idea_aws_1 = __webpack_require__(946);
const idea_toolbox_1 = __webpack_require__(81);
/**
* A custom class that takes advantage of the `idea_html2pdf` Lambda function to easily manage the creation of PDFs.
*/
class HTML2PDF {
constructor() {
/**
* The name of the default Lambda function to invoke.
*/
this.LAMBDA_NAME = 'idea_html2pdf:prod';
this.lambda = new aws_sdk_1.Lambda();
this.s3 = new idea_aws_1.S3();
}
/**
* Compile an Handlebars template.
*/
handlebarsCompile(input, options) {
return handlebars_1.compile(input, options);
}
/**
* Return a new safe string for Handlebars templates.
*/
handlebarsSafeString(str) {
return new handlebars_1.SafeString(str);
}
/**
* Register an additional handelbars helper.
*/
handlebarsRegisterHelper(name, func) {
handlebars_1.registerHelper(name, func);
}
/**
* Create a new PDF created by an HTML source.
* @param params the parameters to create the PDF
* @param alternativeLambda an alternative lambda function to use to generate the PDF
* @return the PDF data (buffer)
*/
create(params, alternativeLambda) {
return new Promise((resolve, reject) => {
this.lambda.invoke({
FunctionName: alternativeLambda || this.LAMBDA_NAME,
InvocationType: 'RequestResponse',
Payload: JSON.stringify(params)
}, (err, data) => {
if (err) {
idea_toolbox_1.logger('PDF creation failed', err, alternativeLambda || this.LAMBDA_NAME);
reject(err);
}
else
resolve(Buffer.from(data.Payload, 'base64'));
});
});
}
/**
* Create the signedURL to a new PDF created by an HTML source.
* @param params the parameters to create the PDF
* @param alternativeLambda an alternative lambda function to use to generate the PDF
* @param downloadOptions the parameters create the download link
* @return the URL to download the PDF
*/
createLink(params, alternativeLambda, downloadOptions) {
return new Promise((resolve, reject) => {
this.create(params, alternativeLambda)
.then(pdfData => resolve(this.s3.createDownloadURLFromData(pdfData, downloadOptions)))
.catch(err => reject(err));
});
}
/**
* Helper function to prepare Handlebar's helper for the `PDFTemplateSection` standard.
*/
getHandlebarHelpersForPDFTemplate(language, languages, htmlInnerTemplate, additionalTranslations) {
return {
get: (context, x) => context[x],
getOrDash: (context, x) => (context[x] !== null && context[x] !== undefined ? context[x] : '-'),
doesColumnContainAField: (section, colIndex) => section.doesColumnContainAField(colIndex),
getColumnFieldSize: (section, colIndex) => section.getColumnFieldSize(colIndex),
substituteVars: (data, str) => {
if (!str || !data)
return str || '';
str = String(str);
const matches = str.match(/@\w*/gm);
if (matches)
matches.forEach(attr => {
if (data[attr] !== undefined)
str = str.replace(attr, data[attr] === null ? '' : data[attr]);
});
return str;
},
inception: (_template, _data) => {
const variables = { _template, _data };
return new handlebars_1.SafeString(handlebars_1.compile(htmlInnerTemplate, { compat: true })(variables));
},
isFieldABoolean: (data, value) => typeof data[value] === 'boolean',
isFieldANumber: (data, value) => typeof data[value] === 'number',
ifEqual: (a, b, opt) => (a === b ? opt.fn(this) : opt.inverse(this)),
label: (label) => (label ? label[language] || label[languages.default] : null),
mdToHTML: (s) => (typeof s === 'string' ? new handlebars_1.SafeString(idea_toolbox_1.mdToHtml(s)) : s),
translate: (s) => s && additionalTranslations && additionalTranslations[s] ? additionalTranslations[s] : s
};
}
}
exports.HTML2PDF = HTML2PDF;
exports.PDF_TEMPLATE = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>
PDF template
</title>
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<style>
html,
body {
margin: 0;
padding: 0;
font-size: 10pt;
font-family: 'Lato', Arial, Helvetica, sans-serif;
}
table {
width: 100%;
table-layout: fixed;
font-size: 1rem;
}
table,
tr,
td {
margin: 0;
padding: 0;
border-spacing: 0;
border-collapse: collapse;
vertical-align: middle;
}
.dontBreak {
page-break-inside: avoid !important;
}
.pageBreak {
page-break-after: always;
}
table.border td {
border: 1px solid #eee;
}
td > p {
margin: 0;
padding: 0;
}
.normalRow td {
padding: 6px 8px;
letter-spacing: -0.2px;
}
td .label {
display: block;
font-size: 0.8rem;
font-weight: bold;
color: #555;
}
.headerTable {
margin-top: 20px;
page-break-inside: avoid;
}
.headerTable::after {
/* trick to avoid a page break right after the header */
content: "-";
color: white;
display: block;
height: 150px;
margin-bottom: -150px;
}
.headerTitle {
padding: 4px 8px;
background-color: #444;
border: 1px solid transparent;
border-radius: 5px;
font-size: 0.9rem;
font-weight: 500;
color: white;
}
.numericField {
text-align: right;
}
.checkbox {
width: 12px;
padding-top: 2px;
}
</style>
</head>
<body>
<!-- PDF TEMPLATE BEGIN -->
<div class="pdfTemplate">
{{#each _template as |section|}}
{{! page break }}
{{#ifEqual section.type 0}}
<div class="pageBreak"></div>
{{/ifEqual}}
{{! empty row }}
{{#ifEqual section.type 1}}
<br />
{{/ifEqual}}
{{! row }}
{{#ifEqual section.type 2}}
<table class="normalRow dontBreak {{#if row.border}}border{{/if}}">
<tr>
{{#each section.columns as |content|}}
{{#if content}}
{{#if (doesColumnContainAField section @index)}}{{! field (that may be repeated for more cols) }}
{{#with content as |field|}}
{{! simple field }}
{{#if field.code}}
<td
colspan="{{getColumnFieldSize section @index}}"
class="{{#if (isFieldANumber _data field.code)}}numericField{{/if}}"
>
<span class="label">
{{translate (label field.label)}}&nbsp;
</span>
{{#if (isFieldABoolean _data field.code)}}
{{#if (get _data field.code)}}
<img
class="checkbox"
src="https://s3.eu-west-2.amazonaws.com/scarlett-app/assets/icons/check-true.png"
/>
{{else}}
<img
class="checkbox"
src="https://s3.eu-west-2.amazonaws.com/scarlett-app/assets/icons/check-false.png"
/>
{{/if}}
{{else}}
{{mdToHTML (translate (getOrDash _data field.code))}}
{{/if}}
</td>
{{! complext field }}
{{else}}
<td colspan="{{getColumnFieldSize section @index}}">
{{#ifEqual 12 (getColumnFieldSize section @index)}}
{{! no extra spacing }}
{{else}}
<span class="label">&nbsp;</span>
{{/ifEqual}}
{{mdToHTML (substituteVars _data (translate (label field.content)))}}
</td>
{{/if}}
{{/with}}
{{/if}}
{{else}}
{{! empty col }}
<td colspan="1"></td>
{{/if}}
{{/each}}
</tr>
</table>
{{/ifEqual}}
{{! header }}
{{#ifEqual section.type 3}}
<table class="headerTable">
<tr>
<td class="headerTitle">
{{mdToHTML (substituteVars _data (translate (label section.title)))}}
</td>
</tr>
</table>
{{/ifEqual}}
{{! inner section }}
{{#ifEqual section.type 4}}
{{#if (get _data section.context)}}
{{#if (label section.title)}}
<table class="headerTable">
<tr>
<td class="headerTitle">
{{translate (label section.title)}}
</td>
</tr>
</table>
{{/if}}
{{inception section.innerTemplate (get _data section.context)}}
{{/if}}
{{/ifEqual}}
{{! repeated inner section }}
{{#ifEqual section.type 5}}
{{#with (get _data section.context) as |innerSections|}}
{{#if innerSections.length}}
{{#if (label section.title)}}
<table class="headerTable">
<tr>
<td class="headerTitle">
{{translate (label section.title)}}
</td>
</tr>
</table>
{{/if}}
{{/if}}
{{#each innerSections as |innerSection|}}
{{inception section.innerTemplate innerSection}}
{{/each}}
{{/with}}
{{/ifEqual}}
{{/each}}
</div>
</body>
</html>
`;
/***/ }),
/***/ 341:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -356,70 +10,5 @@ if (k2 === undefined) k2 = k;

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
__exportStar(__webpack_require__(77), exports);
/***/ }),
/***/ 480:
/***/ ((module) => {
module.exports = require("aws-sdk");;
/***/ }),
/***/ 778:
/***/ ((module) => {
module.exports = require("handlebars");;
/***/ }),
/***/ 946:
/***/ ((module) => {
module.exports = require("idea-aws");;
/***/ }),
/***/ 81:
/***/ ((module) => {
module.exports = require("idea-toolbox");;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(341);
/******/ })()
;
});
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./src/html2pdf"), exports);
{
"name": "idea-html2pdf",
"version": "1.0.6",
"version": "1.1.0",
"description": "IDEA helper for generating a PDF from HTML contents",

@@ -11,2 +11,5 @@ "engines": {

"scripts": {
"lint": "eslint --ext .ts",
"compile": "tsc --build",
"docs": "typedoc",
"build": "./build.sh",

@@ -33,22 +36,16 @@ "publishPackage": "./build.sh && npm publish"

"handlebars": "^4.7.7",
"idea-aws": "^3.3.6",
"idea-toolbox": "^6.3.0"
"idea-aws": "^3.7.0",
"idea-toolbox": "^6.4.1"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.19",
"@types/node": "^11.9.5",
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0",
"aws-sdk": "^2.411.0",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.7.9",
"eslint-plugin-prefer-arrow": "^1.2.2",
"ts-loader": "^8.0.14",
"typedoc": "^0.17.8",
"typescript": "^3.9.7",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.1",
"webpack-node-externals": "^2.5.2"
"@tsconfig/node14": "^1.0.0",
"@types/aws-lambda": "^8.10.72",
"@types/node": "^14.14.26",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"aws-sdk": "^2.991.0",
"eslint": "^7.32.0",
"typedoc": "^0.22.4",
"typescript": "^4.4.3"
}
}
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