New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

docx-templates

Package Overview
Dependencies
Maintainers
2
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docx-templates - npm Package Compare versions

Comparing version 4.10.0 to 4.11.0

4

CHANGELOG.md

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

## 4.11.0 (2023-03-02)
- [Issue #143](https://github.com/guigrpa/docx-templates/issues/143): Add optional `processLineBreaksAsNewText` toggle which provides an alternative way of inserting line breaks from commands into the docx XML. This should improve rendering of newlines in a few docx readers, like LibreOffice. ([MR #182](https://github.com/guigrpa/docx-templates/pull/182)). Thanks @khaled-iva-docs !
- Updated dependencies.
## 4.10.0 (2023-02-03)

@@ -2,0 +6,0 @@ - [Issue #194](https://github.com/guigrpa/docx-templates/issues/194): add ability to provide captions for images ([MR #286](https://github.com/guigrpa/docx-templates/pull/286)).

30

lib/bundled.d.ts

@@ -13,4 +13,4 @@ type Buffer = ArrayBufferLike;

declare type Node = TextNode | NonTextNode;
declare type BaseNode = {
type Node = TextNode | NonTextNode;
type BaseNode = {
_parent?: Node;

@@ -20,7 +20,7 @@ _children: Array<Node>;

};
declare type TextNode = BaseNode & {
type TextNode = BaseNode & {
_fTextNode: true;
_text: string;
};
declare type NonTextNode = BaseNode & {
type NonTextNode = BaseNode & {
_fTextNode: false;

@@ -36,6 +36,6 @@ _tag: string;

};
declare type ReportData = any;
declare type QueryResolver = (query: string | undefined, queryVars: any) => ReportData | Promise<ReportData>;
declare type ErrorHandler = (e: Error, raw_code?: string) => any;
declare type RunJSFunc = (o: {
type ReportData = any;
type QueryResolver = (query: string | undefined, queryVars: any) => ReportData | Promise<ReportData>;
type ErrorHandler = (e: Error, raw_code?: string) => any;
type RunJSFunc = (o: {
sandbox: Object;

@@ -47,3 +47,3 @@ ctx: Object;

};
declare type UserOptions = {
type UserOptions = {
/**

@@ -66,3 +66,3 @@ * Docx file template as a NodeJS Buffer or Buffer-like object in Browsers.

/**
* Can be used to change the delimiter in generated XML.
* The delimiter that's used to indicate literal XML that should be inserted into the docx XML tree as-is. Defaults to `||`.
*/

@@ -115,4 +115,10 @@ literalXmlDelimiter?: string;

fixSmartQuotes?: boolean;
/**
* Use the new way of injecting line breaks from command results (only applies when `processLineBreaks` is `true`)
* which has better results in LibreOffice and Google Drive.
* (Default: false)
*/
processLineBreaksAsNewText?: boolean;
};
declare type CommandSummary = {
type CommandSummary = {
raw: string;

@@ -122,3 +128,3 @@ type: BuiltInCommand;

};
declare type BuiltInCommand = typeof BUILT_IN_COMMANDS[number];
type BuiltInCommand = (typeof BUILT_IN_COMMANDS)[number];
declare const BUILT_IN_COMMANDS: readonly ["QUERY", "CMD_NODE", "ALIAS", "FOR", "END-FOR", "IF", "END-IF", "INS", "EXEC", "IMAGE", "LINK", "HTML"];

@@ -125,0 +131,0 @@

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

declare type LogSink = (message?: string, ...optionalParams: unknown[]) => void;
type LogSink = (message?: string, ...optionalParams: unknown[]) => void;
export declare const logger: {

@@ -3,0 +3,0 @@ debug: LogSink;

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value];

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -171,2 +171,5 @@ if (y = 0, t) op = [op[0] & 2, t.value];

fixSmartQuotes: options.fixSmartQuotes == null ? false : options.fixSmartQuotes,
processLineBreaksAsNewText: options.processLineBreaksAsNewText == null
? false
: options.processLineBreaksAsNewText,
};

@@ -342,2 +345,3 @@ xmlOptions = { literalXmlDelimiter: literalXmlDelimiter };

fixSmartQuotes: false,
processLineBreaksAsNewText: false,
};

@@ -344,0 +348,0 @@ return [4 /*yield*/, parseTemplate(template)];

import { Node, ReportData, Context, CreateReportOptions, Images, Links, Htmls } from './types';
export declare function newContext(options: CreateReportOptions, imageId?: number): Context;
export declare function extractQuery(template: Node, options: CreateReportOptions): Promise<string | undefined>;
declare type ReportOutput = {
type ReportOutput = {
status: 'success';

@@ -17,3 +17,3 @@ report: Node;

export declare function walkTemplate(data: ReportData | undefined, template: Node, ctx: Context, processor: CommandProcessor): Promise<ReportOutput>;
declare type CommandProcessor = (data: ReportData | undefined, node: Node, ctx: Context) => Promise<undefined | string | Error>;
type CommandProcessor = (data: ReportData | undefined, node: Node, ctx: Context) => Promise<undefined | string | Error>;
export declare function getCommand(command: string, shorthands: Context['shorthands'], fixSmartQuotes: boolean): string;

@@ -20,0 +20,0 @@ export declare function splitCommand(cmd: string): {

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -477,3 +477,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var processCmd = function (data, node, ctx) { return __awaiter(void 0, void 0, void 0, function () {
var cmd, _a, cmdName, cmdRest, aliasMatch, aliasName, fullCmd, result, nerr, str, literalXmlDelimiter, img, pars, html, err_1;
var cmd, _a, cmdName, cmdRest, aliasMatch, aliasName, fullCmd, result, nerr, str, literalXmlDelimiter, splitByLineBreak, LINE_BREAK, END_OF_TEXT, START_OF_TEXT, img, pars, html, err_1;
return __generator(this, function (_b) {

@@ -539,3 +539,12 @@ switch (_b.label) {

literalXmlDelimiter = ctx.options.literalXmlDelimiter;
str = str.replace(/\n/g, "".concat(literalXmlDelimiter, "<w:br/>").concat(literalXmlDelimiter));
if (ctx.options.processLineBreaksAsNewText) {
splitByLineBreak = str.split('\n');
LINE_BREAK = "".concat(literalXmlDelimiter, "<w:br/>").concat(literalXmlDelimiter);
END_OF_TEXT = "".concat(literalXmlDelimiter, "</w:t>").concat(literalXmlDelimiter);
START_OF_TEXT = "".concat(literalXmlDelimiter, "<w:t xml:space=\"preserve\">").concat(literalXmlDelimiter);
str = splitByLineBreak.join("".concat(END_OF_TEXT).concat(LINE_BREAK).concat(START_OF_TEXT));
}
else {
str = str.replace(/\n/g, "".concat(literalXmlDelimiter, "<w:br/>").concat(literalXmlDelimiter));
}
}

@@ -542,0 +551,0 @@ return [2 /*return*/, str];

/// <reference types="node" />
import { QualifiedAttribute } from 'sax';
export declare type Node = TextNode | NonTextNode;
declare type BaseNode = {
export type Node = TextNode | NonTextNode;
type BaseNode = {
_parent?: Node;

@@ -9,7 +9,7 @@ _children: Array<Node>;

};
export declare type TextNode = BaseNode & {
export type TextNode = BaseNode & {
_fTextNode: true;
_text: string;
};
export declare type NonTextNode = BaseNode & {
export type NonTextNode = BaseNode & {
_fTextNode: false;

@@ -25,6 +25,6 @@ _tag: string;

};
export declare type ReportData = any;
export declare type QueryResolver = (query: string | undefined, queryVars: any) => ReportData | Promise<ReportData>;
declare type ErrorHandler = (e: Error, raw_code?: string) => any;
declare type RunJSFunc = (o: {
export type ReportData = any;
export type QueryResolver = (query: string | undefined, queryVars: any) => ReportData | Promise<ReportData>;
type ErrorHandler = (e: Error, raw_code?: string) => any;
type RunJSFunc = (o: {
sandbox: Object;

@@ -36,3 +36,3 @@ ctx: Object;

};
export declare type UserOptions = {
export type UserOptions = {
/**

@@ -55,3 +55,3 @@ * Docx file template as a NodeJS Buffer or Buffer-like object in Browsers.

/**
* Can be used to change the delimiter in generated XML.
* The delimiter that's used to indicate literal XML that should be inserted into the docx XML tree as-is. Defaults to `||`.
*/

@@ -104,4 +104,10 @@ literalXmlDelimiter?: string;

fixSmartQuotes?: boolean;
/**
* Use the new way of injecting line breaks from command results (only applies when `processLineBreaks` is `true`)
* which has better results in LibreOffice and Google Drive.
* (Default: false)
*/
processLineBreaksAsNewText?: boolean;
};
export declare type CreateReportOptions = {
export type CreateReportOptions = {
cmdDelimiter: [string, string];

@@ -117,4 +123,5 @@ literalXmlDelimiter: string;

fixSmartQuotes: boolean;
processLineBreaksAsNewText: boolean;
};
export declare type Context = {
export type Context = {
gCntIf: number;

@@ -154,21 +161,21 @@ level: number;

};
export declare type Images = {
export type Images = {
[id: string]: Image;
};
export declare const ImageExtensions: readonly [".png", ".gif", ".jpg", ".jpeg", ".svg"];
declare type ImageExtension = typeof ImageExtensions[number];
export declare type Image = {
type ImageExtension = (typeof ImageExtensions)[number];
export type Image = {
extension: ImageExtension;
data: Buffer | ArrayBuffer | string;
};
export declare type Links = {
export type Links = {
[id: string]: Link;
};
declare type Link = {
type Link = {
url: string;
};
export declare type Htmls = {
export type Htmls = {
[id: string]: string;
};
declare type BufferStatus = {
type BufferStatus = {
text: string;

@@ -178,4 +185,4 @@ cmds: string;

};
declare type VarValue = unknown;
export declare type LoopStatus = {
type VarValue = unknown;
export type LoopStatus = {
refNode: Node;

@@ -188,3 +195,3 @@ refNodeLevel: number;

};
export declare type ImagePars = {
export type ImagePars = {
/**

@@ -223,7 +230,7 @@ * Desired width of the image in centimeters.

};
export declare type LinkPars = {
export type LinkPars = {
url: string;
label?: string;
};
export declare type CommandSummary = {
export type CommandSummary = {
raw: string;

@@ -233,4 +240,4 @@ type: BuiltInCommand;

};
export declare type BuiltInCommand = typeof BUILT_IN_COMMANDS[number];
export type BuiltInCommand = (typeof BUILT_IN_COMMANDS)[number];
export declare const BUILT_IN_COMMANDS: readonly ["QUERY", "CMD_NODE", "ALIAS", "FOR", "END-FOR", "IF", "END-IF", "INS", "EXEC", "IMAGE", "LINK", "HTML"];
export {};
import { Node } from './types';
declare const parseXml: (templateXml: string) => Promise<Node>;
declare type XmlOptions = {
type XmlOptions = {
literalXmlDelimiter: string;

@@ -5,0 +5,0 @@ };

{
"name": "docx-templates",
"version": "4.10.0",
"version": "4.11.0",
"description": "Template-based docx report creation",

@@ -51,22 +51,22 @@ "main": "lib/index.js",

"@rollup/plugin-replace": "^3.0.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.10",
"@types/qrcode": "1.4.2",
"@types/jest": "^29.4.0",
"@types/node": "^18.14.4",
"@types/qrcode": "1.5.0",
"@types/sax": "^1.2.4",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"buffer": "^6.0.3",
"coveralls": "^3.0.13",
"esbuild": "^0.14.11",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^25.7.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"events": "^3.3.0",
"jest": "^27.4.7",
"jest": "^29.4.3",
"mockdate": "^3.0.2",
"nyc": "^15.0.1",
"prettier": "^2.5.1",
"qrcode": "1.4.4",
"prettier": "^2.8.4",
"qrcode": "1.5.1",
"rimraf": "^3.0.2",

@@ -77,5 +77,5 @@ "rollup": "^2.64.0",

"stream-browserify": "^3.0.0",
"ts-jest": "^27.1.3",
"ts-jest": "^29.0.5",
"typescript": "^4.5.4",
"util": "^0.12.4",
"util": "^0.12.5",
"vm-browserify": "^1.1.2"

@@ -82,0 +82,0 @@ },

@@ -45,2 +45,3 @@ # Docx-templates [![Build Status](https://travis-ci.org/guigrpa/docx-templates.svg)](https://travis-ci.org/guigrpa/docx-templates) [![Coverage Status](https://coveralls.io/repos/github/guigrpa/docx-templates/badge.svg?branch=master)](https://coveralls.io/github/guigrpa/docx-templates?branch=master) [![npm version](https://img.shields.io/npm/v/docx-templates.svg)](https://www.npmjs.com/package/docx-templates)

- [`ALIAS` (and alias resolution with `*`)](#alias-and-alias-resolution-with-)
- [Inserting literal XML](#inserting-literal-xml)
- [Error handling](#error-handling)

@@ -517,2 +518,20 @@ - [Error types](#error-types)

## Inserting literal XML
You can also directly insert Office Open XML markup into the document using the `literalXmlDelimiter`, which is by default set to `||`.
E.g. if you have a template like this:
```
+++INS text+++
```
```js
await createReport({
template,
data: { text: 'foo||<w:br/>||bar' },
}
```
See http://officeopenxml.com/anatomyofOOXML.php for a good reference of the internal XML structure of a docx file.
# Error handling

@@ -519,0 +538,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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