Porting tests over to vitest
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Generate a CV
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, Tab, TabStopPosition, TabStopType, TextRun } from "../build";
|
||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, Tab, TabStopPosition, TabStopType, TextRun } from "docx";
|
||||
|
||||
// tslint:disable:no-shadowed-variable
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Setting styles with JavaScript configuration
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
AlignmentType,
|
||||
@ -16,7 +16,7 @@ import {
|
||||
TabStopPosition,
|
||||
UnderlineType,
|
||||
LevelFormat,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Scaling images
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ImageRun, Packer, Paragraph } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This example shows 3 styles using XML styles
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph } from "docx";
|
||||
|
||||
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
||||
const doc = new Document({
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Page numbers
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Page break before example
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Multiple sections and headers
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, PageNumber, NumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
|
||||
import { Document, Footer, Header, Packer, PageNumber, NumberFormat, PageOrientation, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Footnotes
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, FootnoteReferenceRun, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, FootnoteReferenceRun, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
footnotes: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Insert image from a buffer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ImageRun, Packer, Paragraph } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph } from "docx";
|
||||
|
||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVB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lsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Export to base64 string - Useful in a browser environment.
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Example on how to customize the look at feel using Styles
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph, TextRun, UnderlineType } from "docx";
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add custom borders to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,18 +1,7 @@
|
||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Bookmark,
|
||||
Document,
|
||||
Footer,
|
||||
HeadingLevel,
|
||||
InternalHyperlink,
|
||||
Packer,
|
||||
PageBreak,
|
||||
Paragraph,
|
||||
TextRun,
|
||||
PageReference,
|
||||
} from "../build";
|
||||
import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun, PageReference } from "docx";
|
||||
|
||||
const LOREM_IPSUM =
|
||||
/* cspell:disable-next-line */
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This demo shows right to left for special languages
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This demo adds an image to the Media cache, and then insert to the document afterwards
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ImageRun, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx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e+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add image to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "docx";
|
||||
|
||||
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Creates two paragraphs, one with a border and one without
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Custom styles using JavaScript configuration
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
||||
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Table of contents
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
|
||||
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "docx";
|
||||
|
||||
// WordprocessingML docs for TableOfContents can be found here:
|
||||
// http://officeopenxml.com/WPtableOfContents.php
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Numbered lists
|
||||
// The lists can also be restarted by specifying the instance number
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbering and bullet points example
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertInchesToTwip, Document, Footer, Header, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||
import { AlignmentType, convertInchesToTwip, Document, Footer, Header, HeadingLevel, LevelFormat, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Example of how you would merge cells together (Rows and Columns) and apply shading
|
||||
// Also includes an example on how to center tables
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
AlignmentType,
|
||||
@ -15,7 +15,7 @@ import {
|
||||
TableCell,
|
||||
TableRow,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Sequential Captions
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Example of how you would create a table with float positions
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
@ -14,7 +14,7 @@ import {
|
||||
TableLayoutType,
|
||||
TableRow,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example on how to add hyperlinks to websites
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
footnotes: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add image to table cell in a header and body
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Header, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import { Document, Header, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add images to header and footer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Header, ImageRun, Packer, Paragraph } from "../build";
|
||||
import { Document, Header, ImageRun, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Example of how to "wrap" text around an image
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
// import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
|
||||
// import { Document, Packer, Paragraph } from "docx";
|
||||
import { Document, ImageRun, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example how to display page numbers
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, NumberFormat, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, NumberFormat, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "docx";
|
||||
|
||||
const table = new Table({
|
||||
columnWidths: [3505, 5505],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example demonstrating line numbers.
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
||||
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Multiple cells merging in the same table - Rows and Columns
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Page numbers - Start from 0 on a new section
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add image to table cell
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "docx";
|
||||
|
||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4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fOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Sections with multiple columns
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Highlighting text
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Shading text
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Multiple sections with total number of pages in each section
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, NumberFormat, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, NumberFormat, Paragraph, TextRun } from "docx";
|
||||
|
||||
const header = new Header({
|
||||
children: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of making content of section vertically aligned
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun, Tab } from "../build";
|
||||
import { Document, Packer, Paragraph, VerticalAlign, TextRun, Tab } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Add custom borders and no-borders to the table itself
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
BorderStyle,
|
||||
@ -13,7 +13,7 @@ import {
|
||||
TableRow,
|
||||
TextDirection,
|
||||
VerticalAlign,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Example of how to add images to the document - You can use Buffers, UInt8Arrays or Base64 strings
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
@ -10,7 +10,7 @@ import {
|
||||
Paragraph,
|
||||
VerticalPositionAlign,
|
||||
VerticalPositionRelativeFrom,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The demo on the README.md
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build";
|
||||
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "docx";
|
||||
|
||||
const table = new Table({
|
||||
rows: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Custom character styles using JavaScript configuration
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Japanese text - Need to use a Japanese font
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -5,9 +5,8 @@
|
||||
|
||||
// Note that if the OS have not install `KaiTi` font, this demo doesn't work.
|
||||
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -3,9 +3,8 @@
|
||||
// to the document in Word after the document has been generated. Standard properties (such as creator, title
|
||||
// and subject) cover typical use cases, but sometimes custom properties are required.
|
||||
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer } from "../build";
|
||||
import { Document, Packer } from "docx";
|
||||
|
||||
const doc = new Document(
|
||||
// Standard properties
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
@ -21,7 +21,7 @@ import {
|
||||
Packer,
|
||||
Paragraph,
|
||||
TextRun,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Change background colour of whole document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
background: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbered lists - Add parent number in sub number
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Usage of different Section Types
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun, SectionType } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun, SectionType } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Move + offset header and footer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
||||
import { Document, Footer, Header, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how to change page borders
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Tab, TextRun } from "../build";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Tab, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Track Revisions aka. "Track Changes"
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
AlignmentType,
|
||||
@ -14,7 +14,7 @@ import {
|
||||
ShadingType,
|
||||
Tab,
|
||||
TextRun,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
/*
|
||||
For reference, see
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Text Frame (Text Box) example
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
BorderStyle,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, LineRuleType, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, LineRuleType, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Move + offset header and footer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, PageBreak, Paragraph, TextRun } from "../build";
|
||||
import { Document, Footer, Header, Packer, PageBreak, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
evenAndOddHeaderAndFooters: true,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Numbered lists - With complex number text
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, LevelFormat } from "../build";
|
||||
import { Document, Packer, Paragraph, LevelFormat } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Example of how to set the document page sizes
|
||||
// Reference from https://papersizes.io/a/a3
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { convertMillimetersToTwip, Document, Packer, PageOrientation, Paragraph } from "../build";
|
||||
import { convertMillimetersToTwip, Document, Packer, PageOrientation, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Use fields to include dynamic text
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "../build";
|
||||
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Me",
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Section with 2 columns including a column break
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, ColumnBreak, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, ColumnBreak, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, LevelFormat } from "../build";
|
||||
import { Document, Packer, Paragraph, LevelFormat } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
numbering: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Sections with multiple columns
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Column, Document, Packer, Paragraph } from "../build";
|
||||
import { Column, Document, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how to set the document to landscape
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
||||
import { Document, Packer, PageOrientation, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example demonstrating line numbers with suppression.
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
||||
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example demonstrating page borders with style, colors and size
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, TextRun, Paragraph, BorderStyle, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder } from "../build";
|
||||
import { Document, Packer, TextRun, Paragraph, BorderStyle, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example on how to preserve word wrap text. Works with all languages.
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun, SpaceType } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun, SpaceType } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add comments to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEnd, CommentReference } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEnd, CommentReference } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
comments: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Exporting the document as a stream
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Tab, TextRun } from "docx";
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Example of using tab stops
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "docx";
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add compatibility options
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
compatibility: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Exporting the document as a stream
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, WidthType } from "../build";
|
||||
import { Document, Packer, Paragraph, Table, TableBorders, TableCell, TableRow, WidthType } from "docx";
|
||||
|
||||
const table1 = new Table({
|
||||
columnWidths: [3505, 5505],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Example of how you would create a table and add data to it from a data source
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
@ -13,7 +13,7 @@ import {
|
||||
TextDirection,
|
||||
TextRun,
|
||||
WidthType,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
interface StockPrice {
|
||||
readonly date: Date;
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add text to header and footer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
||||
import { Document, Footer, Header, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { AlignmentType, convertMillimetersToTwip, Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of a continuous header
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Creator",
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of using headers and footers in a new section
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "../build";
|
||||
import { Document, Footer, Header, Packer, Paragraph, SectionType, Tab, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
creator: "Creator",
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Simple example to add text to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph } from "../build";
|
||||
import { Document, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Simple example apply positional tabs to a document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
Document,
|
||||
@ -11,7 +11,7 @@ import {
|
||||
PositionalTabAlignment,
|
||||
PositionalTabRelativeTo,
|
||||
PositionalTabLeader,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
ExternalHyperlink,
|
||||
@ -14,7 +14,7 @@ import {
|
||||
TextDirection,
|
||||
TextRun,
|
||||
VerticalAlign,
|
||||
} from "../build";
|
||||
} from "docx";
|
||||
|
||||
patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
|
||||
patches: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Generate a template document
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { patchDocument, PatchType, TextRun } from "../build";
|
||||
import { patchDocument, PatchType, TextRun } from "docx";
|
||||
|
||||
patchDocument(fs.readFileSync("demo/assets/simple-template-2.docx"), {
|
||||
patches: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
|
||||
import { IPatch, patchDocument, PatchType, TextRun } from "docx";
|
||||
|
||||
export const font = "Trebuchet MS";
|
||||
export const getPatches = (fields: { [key: string]: string }) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Patch a document with patches
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { IPatch, patchDocument, PatchType, TextRun } from "../build";
|
||||
import { IPatch, patchDocument, PatchType, TextRun } from "docx";
|
||||
|
||||
export const font = "Trebuchet MS";
|
||||
export const getPatches = (fields: { [key: string]: string }) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Add images to header and footer
|
||||
// Import from 'docx' rather than '../build' if you install from npm
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "../build";
|
||||
import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
|
999
package-lock.json
generated
999
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -22,8 +22,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc && vite build",
|
||||
"pretest": "rimraf ./build",
|
||||
"test": "mocha --config=.mocharc.json",
|
||||
"test": "vitest",
|
||||
"test.coverage": "nyc npm test",
|
||||
"test.watch": "npm test -- --watch",
|
||||
"prepublishOnly": "npm run build --omit=dev",
|
||||
@ -124,6 +123,7 @@
|
||||
"vite-plugin-dts": "^2.3.0",
|
||||
"vite-plugin-node-polyfills": "^0.8.2",
|
||||
"vite-tsconfig-paths": "^4.2.0",
|
||||
"vitest": "^0.31.4",
|
||||
"webpack": "^5.28.0",
|
||||
"webpack-cli": "^5.0.0"
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { assert, expect } from "chai";
|
||||
import { assert, beforeEach, describe, expect, it } from "vitest";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Media } from "@file/media";
|
||||
|
||||
|
@ -1,180 +1,189 @@
|
||||
// /* tslint:disable:typedef space-before-function-paren */
|
||||
// import { expect } from "chai";
|
||||
// import * as sinon from "sinon";
|
||||
/* tslint:disable:typedef space-before-function-paren */
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
// import { File } from "@file/file";
|
||||
// import { Footer, Header } from "@file/header";
|
||||
// import { ImageRun, Paragraph } from "@file/paragraph";
|
||||
// import * as convenienceFunctions from "@util/convenience-functions";
|
||||
import { File } from "@file/file";
|
||||
import { Footer, Header } from "@file/header";
|
||||
import { ImageRun, Paragraph } from "@file/paragraph";
|
||||
import * as convenienceFunctions from "@util/convenience-functions";
|
||||
|
||||
// import { Compiler } from "./next-compiler";
|
||||
import { Compiler } from "./next-compiler";
|
||||
|
||||
// describe("Compiler", () => {
|
||||
// let compiler: Compiler;
|
||||
describe("Compiler", () => {
|
||||
let compiler: Compiler;
|
||||
|
||||
// beforeEach(() => {
|
||||
// compiler = new Compiler();
|
||||
// });
|
||||
beforeEach(() => {
|
||||
compiler = new Compiler();
|
||||
});
|
||||
|
||||
// before(() => {
|
||||
// sinon.stub(convenienceFunctions, "uniqueId").callsFake(() => "test");
|
||||
// });
|
||||
beforeAll(() => {
|
||||
vi.spyOn(convenienceFunctions, "uniqueId").mockReturnValue("test");
|
||||
});
|
||||
|
||||
// after(() => {
|
||||
// (convenienceFunctions.uniqueId as sinon.SinonStub).restore();
|
||||
// });
|
||||
afterAll(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
// describe("#compile()", () => {
|
||||
// it("should pack all the content", async function () {
|
||||
// this.timeout(99999999);
|
||||
// const file = new File({
|
||||
// sections: [],
|
||||
// comments: {
|
||||
// children: [],
|
||||
// },
|
||||
// });
|
||||
// const zipFile = await compiler.compile(file);
|
||||
// const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
describe("#compile()", () => {
|
||||
it(
|
||||
"should pack all the content",
|
||||
async () => {
|
||||
const file = new File({
|
||||
sections: [],
|
||||
comments: {
|
||||
children: [],
|
||||
},
|
||||
});
|
||||
const zipFile = await compiler.compile(file);
|
||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
|
||||
// expect(fileNames).is.an.instanceof(Array);
|
||||
// expect(fileNames).has.length(17);
|
||||
// expect(fileNames).to.include("word/document.xml");
|
||||
// expect(fileNames).to.include("word/styles.xml");
|
||||
// expect(fileNames).to.include("docProps/core.xml");
|
||||
// expect(fileNames).to.include("docProps/custom.xml");
|
||||
// expect(fileNames).to.include("docProps/app.xml");
|
||||
// expect(fileNames).to.include("word/numbering.xml");
|
||||
// expect(fileNames).to.include("word/footnotes.xml");
|
||||
// expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
|
||||
// expect(fileNames).to.include("word/settings.xml");
|
||||
// expect(fileNames).to.include("word/comments.xml");
|
||||
// expect(fileNames).to.include("word/_rels/document.xml.rels");
|
||||
// expect(fileNames).to.include("[Content_Types].xml");
|
||||
// expect(fileNames).to.include("_rels/.rels");
|
||||
// });
|
||||
expect(fileNames).is.an.instanceof(Array);
|
||||
expect(fileNames).has.length(17);
|
||||
expect(fileNames).to.include("word/document.xml");
|
||||
expect(fileNames).to.include("word/styles.xml");
|
||||
expect(fileNames).to.include("docProps/core.xml");
|
||||
expect(fileNames).to.include("docProps/custom.xml");
|
||||
expect(fileNames).to.include("docProps/app.xml");
|
||||
expect(fileNames).to.include("word/numbering.xml");
|
||||
expect(fileNames).to.include("word/footnotes.xml");
|
||||
expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
|
||||
expect(fileNames).to.include("word/settings.xml");
|
||||
expect(fileNames).to.include("word/comments.xml");
|
||||
expect(fileNames).to.include("word/_rels/document.xml.rels");
|
||||
expect(fileNames).to.include("[Content_Types].xml");
|
||||
expect(fileNames).to.include("_rels/.rels");
|
||||
},
|
||||
{
|
||||
timeout: 99999999,
|
||||
},
|
||||
);
|
||||
|
||||
// it("should pack all additional headers and footers", function () {
|
||||
// const file = new File({
|
||||
// sections: [
|
||||
// {
|
||||
// headers: {
|
||||
// default: new Header({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// footers: {
|
||||
// default: new Footer({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// children: [],
|
||||
// },
|
||||
// {
|
||||
// headers: {
|
||||
// default: new Header({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// footers: {
|
||||
// default: new Footer({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// children: [],
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
it(
|
||||
"should pack all additional headers and footers",
|
||||
() => {
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// this.timeout(99999999);
|
||||
const zipFile = compiler.compile(file);
|
||||
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
|
||||
// const zipFile = compiler.compile(file);
|
||||
// const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
|
||||
expect(fileNames).is.an.instanceof(Array);
|
||||
expect(fileNames).has.length(25);
|
||||
|
||||
// expect(fileNames).is.an.instanceof(Array);
|
||||
// expect(fileNames).has.length(25);
|
||||
expect(fileNames).to.include("word/header1.xml");
|
||||
expect(fileNames).to.include("word/_rels/header1.xml.rels");
|
||||
expect(fileNames).to.include("word/header2.xml");
|
||||
expect(fileNames).to.include("word/_rels/header2.xml.rels");
|
||||
expect(fileNames).to.include("word/footer1.xml");
|
||||
expect(fileNames).to.include("word/_rels/footer1.xml.rels");
|
||||
expect(fileNames).to.include("word/footer2.xml");
|
||||
expect(fileNames).to.include("word/_rels/footer2.xml.rels");
|
||||
},
|
||||
{
|
||||
timeout: 99999999,
|
||||
},
|
||||
);
|
||||
|
||||
// expect(fileNames).to.include("word/header1.xml");
|
||||
// expect(fileNames).to.include("word/_rels/header1.xml.rels");
|
||||
// expect(fileNames).to.include("word/header2.xml");
|
||||
// expect(fileNames).to.include("word/_rels/header2.xml.rels");
|
||||
// expect(fileNames).to.include("word/footer1.xml");
|
||||
// expect(fileNames).to.include("word/_rels/footer1.xml.rels");
|
||||
// expect(fileNames).to.include("word/footer2.xml");
|
||||
// expect(fileNames).to.include("word/_rels/footer2.xml.rels");
|
||||
// });
|
||||
it("should call the format method X times equalling X files to be formatted", () => {
|
||||
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
const paragraph = new Paragraph("");
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: [paragraph],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// it("should call the format method X times equalling X files to be formatted", () => {
|
||||
// // This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// // This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
// const paragraph = new Paragraph("");
|
||||
// const file = new File({
|
||||
// sections: [
|
||||
// {
|
||||
// properties: {},
|
||||
// children: [paragraph],
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
// tslint:disable-next-line: no-string-literal
|
||||
const spy = sinon.spy(compiler["formatter"], "format");
|
||||
|
||||
// // tslint:disable-next-line: no-string-literal
|
||||
// const spy = sinon.spy(compiler["formatter"], "format");
|
||||
compiler.compile(file);
|
||||
expect(spy.callCount).to.equal(13);
|
||||
});
|
||||
|
||||
// compiler.compile(file);
|
||||
// expect(spy.callCount).to.equal(13);
|
||||
// });
|
||||
it("should work with media datas", () => {
|
||||
// This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
const file = new File({
|
||||
sections: [
|
||||
{
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [new Paragraph("test")],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: Buffer.from("", "base64"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// it("should work with media datas", () => {
|
||||
// // This test is required because before, there was a case where Document was formatted twice, which was inefficient
|
||||
// // This also caused issues such as running prepForXml multiple times as format() was ran multiple times.
|
||||
// const file = new File({
|
||||
// sections: [
|
||||
// {
|
||||
// headers: {
|
||||
// default: new Header({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// footers: {
|
||||
// default: new Footer({
|
||||
// children: [new Paragraph("test")],
|
||||
// }),
|
||||
// },
|
||||
// children: [
|
||||
// new Paragraph({
|
||||
// children: [
|
||||
// new ImageRun({
|
||||
// data: Buffer.from("", "base64"),
|
||||
// transformation: {
|
||||
// width: 100,
|
||||
// height: 100,
|
||||
// },
|
||||
// }),
|
||||
// ],
|
||||
// }),
|
||||
// ],
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
// tslint:disable-next-line: no-string-literal
|
||||
sinon.stub(compiler["imageReplacer"], "getMediaData").returns([
|
||||
{
|
||||
stream: Buffer.from(""),
|
||||
fileName: "test",
|
||||
transformation: {
|
||||
pixels: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
emus: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
// // tslint:disable-next-line: no-string-literal
|
||||
// sinon.stub(compiler["imageReplacer"], "getMediaData").returns([
|
||||
// {
|
||||
// stream: Buffer.from(""),
|
||||
// fileName: "test",
|
||||
// transformation: {
|
||||
// pixels: {
|
||||
// x: 100,
|
||||
// y: 100,
|
||||
// },
|
||||
// emus: {
|
||||
// x: 100,
|
||||
// y: 100,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// ]);
|
||||
|
||||
// compiler.compile(file);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
compiler.compile(file);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,4 @@
|
||||
/* tslint:disable:typedef space-before-function-paren */
|
||||
import { assert } from "chai";
|
||||
import { mock, stub } from "sinon";
|
||||
import { afterEach, assert, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { File } from "@file/file";
|
||||
import { HeadingLevel, Paragraph } from "@file/paragraph";
|
||||
@ -46,62 +44,71 @@ describe("Packer", () => {
|
||||
});
|
||||
|
||||
describe("#toBuffer()", () => {
|
||||
it("should create a standard docx file", async function () {
|
||||
this.timeout(99999999);
|
||||
const buffer = await Packer.toBuffer(file);
|
||||
it(
|
||||
"should create a standard docx file",
|
||||
async () => {
|
||||
const buffer = await Packer.toBuffer(file);
|
||||
|
||||
assert.isDefined(buffer);
|
||||
assert.isTrue(buffer.byteLength > 0);
|
||||
});
|
||||
assert.isDefined(buffer);
|
||||
assert.isTrue(buffer.byteLength > 0);
|
||||
},
|
||||
{
|
||||
timeout: 99999999,
|
||||
},
|
||||
);
|
||||
|
||||
it("should handle exception if it throws any", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const compiler = stub((Packer as any).compiler, "compile");
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
compiler.throwsException();
|
||||
return Packer.toBuffer(file).catch((error) => {
|
||||
assert.isDefined(error);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Packer as any).compiler.compile.restore();
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#toBase64String()", () => {
|
||||
it("should create a standard docx file", async function () {
|
||||
this.timeout(99999999);
|
||||
const str = await Packer.toBase64String(file);
|
||||
|
||||
assert.isDefined(str);
|
||||
assert.isTrue(str.length > 0);
|
||||
});
|
||||
it(
|
||||
"should create a standard docx file",
|
||||
async () => {
|
||||
const str = await Packer.toBase64String(file);
|
||||
expect(str).toBeDefined();
|
||||
expect(str.length).toBeGreaterThan(0);
|
||||
},
|
||||
{
|
||||
timeout: 99999999,
|
||||
},
|
||||
);
|
||||
|
||||
it("should handle exception if it throws any", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const compiler = stub((Packer as any).compiler, "compile");
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
compiler.throwsException();
|
||||
return Packer.toBase64String(file).catch((error) => {
|
||||
assert.isDefined(error);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Packer as any).compiler.compile.restore();
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#toBlob()", () => {
|
||||
it("should create a standard docx file", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockReturnValue({
|
||||
// tslint:disable-next-line: no-empty
|
||||
generateAsync: () => mock({}),
|
||||
}));
|
||||
generateAsync: () => vi.fn(),
|
||||
});
|
||||
const str = await Packer.toBlob(file);
|
||||
|
||||
assert.isDefined(str);
|
||||
@ -109,35 +116,27 @@ describe("Packer", () => {
|
||||
|
||||
it("should handle exception if it throws any", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const compiler = stub((Packer as any).compiler, "compile");
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
compiler.throwsException();
|
||||
return Packer.toBlob(file).catch((error) => {
|
||||
assert.isDefined(error);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Packer as any).compiler.compile.restore();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#toStream()", () => {
|
||||
it("should create a standard docx file", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||
// tslint:disable-next-line: no-empty
|
||||
generateNodeStream: () => ({
|
||||
on: (event: string, cb: () => void) => {
|
||||
if (event === "end") {
|
||||
cb();
|
||||
}
|
||||
},
|
||||
}),
|
||||
}));
|
||||
const stream = await Packer.toStream(file);
|
||||
return new Promise((resolve, reject) => {
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockReturnValue(Promise.resolve(new Uint8Array(255)));
|
||||
const stream = Packer.toStream(file);
|
||||
|
||||
const p = new Promise<void>((resolve, reject) => {
|
||||
stream.on("error", () => {
|
||||
reject(new Error());
|
||||
});
|
||||
@ -146,20 +145,15 @@ describe("Packer", () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await p;
|
||||
});
|
||||
|
||||
it("should handle exception if it throws any", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const compiler = stub((Packer as any).compiler, "compile").callsFake(() => ({
|
||||
// tslint:disable-next-line: no-empty
|
||||
on: (event: string, cb: () => void) => {
|
||||
if (event === "error") {
|
||||
cb();
|
||||
}
|
||||
},
|
||||
}));
|
||||
vi.spyOn((Packer as any).compiler, "compile").mockImplementation(() => {
|
||||
throw new Error();
|
||||
});
|
||||
|
||||
compiler.throwsException();
|
||||
try {
|
||||
Packer.toStream(file);
|
||||
} catch (error) {
|
||||
@ -168,8 +162,7 @@ describe("Packer", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(Packer as any).compiler.compile.restore();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -51,15 +51,12 @@ export class Packer {
|
||||
|
||||
public static toStream(file: File, prettify?: boolean | PrettifyType): Stream {
|
||||
const zip = this.compiler.compile(file, prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify);
|
||||
|
||||
const stream = new Stream();
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
stream.pipe = (dest) => {
|
||||
zip.then((z) => {
|
||||
dest.write(z);
|
||||
});
|
||||
return dest;
|
||||
};
|
||||
|
||||
zip.then((z) => {
|
||||
stream.emit("data", z);
|
||||
stream.emit("end");
|
||||
});
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
import { BorderStyle } from "@file/border";
|
||||
|
@ -1,6 +1,6 @@
|
||||
// tslint:disable:no-string-literal
|
||||
|
||||
import { expect } from "chai";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect } from "chai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { DocumentWrapper } from "./document-wrapper";
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user