@zola_do/docx 0.2.8 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/package.json +70 -70
package/README.md
CHANGED
|
@@ -60,8 +60,8 @@ Best regards,
|
|
|
60
60
|
### 2. Register Module
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
import { Module } from
|
|
64
|
-
import { DocxModule } from
|
|
63
|
+
import { Module } from '@nestjs/common';
|
|
64
|
+
import { DocxModule } from '@zola_do/docx';
|
|
65
65
|
|
|
66
66
|
@Module({
|
|
67
67
|
imports: [DocxModule],
|
|
@@ -72,15 +72,15 @@ export class AppModule {}
|
|
|
72
72
|
### 3. Generate Document
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
|
-
import { Injectable } from
|
|
76
|
-
import { DocxService } from
|
|
75
|
+
import { Injectable } from '@nestjs/common';
|
|
76
|
+
import { DocxService } from '@zola_do/docx';
|
|
77
77
|
|
|
78
78
|
@Injectable()
|
|
79
79
|
export class ReportService {
|
|
80
80
|
constructor(private readonly docxService: DocxService) {}
|
|
81
81
|
|
|
82
82
|
async generateInvoice(order: Order) {
|
|
83
|
-
const templateBuffer = await this.loadTemplate(
|
|
83
|
+
const templateBuffer = await this.loadTemplate('invoice.docx');
|
|
84
84
|
|
|
85
85
|
const result = await this.docxService.generateDocx(templateBuffer, {
|
|
86
86
|
name: order.customerName,
|
|
@@ -88,7 +88,7 @@ export class ReportService {
|
|
|
88
88
|
items: order.items,
|
|
89
89
|
total: order.total,
|
|
90
90
|
isPremium: order.customer.isPremium,
|
|
91
|
-
companyName:
|
|
91
|
+
companyName: 'My Company',
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
return result; // Buffer of filled DOCX
|
|
@@ -154,7 +154,7 @@ The package uses [docx-templates](https://github.com/guigrpa/docx-templates) for
|
|
|
154
154
|
```handlebars
|
|
155
155
|
{{uppercase name}}
|
|
156
156
|
{{lowercase email}}
|
|
157
|
-
{{formatDate date
|
|
157
|
+
{{formatDate date 'MMMM YYYY'}}
|
|
158
158
|
{{currency amount}}
|
|
159
159
|
```
|
|
160
160
|
|
|
@@ -340,15 +340,15 @@ async generateCertificate(userId: string, courseId: string): Promise<Buffer> {
|
|
|
340
340
|
|
|
341
341
|
```typescript
|
|
342
342
|
const testData = {
|
|
343
|
-
name:
|
|
344
|
-
orderNumber:
|
|
343
|
+
name: 'Test User',
|
|
344
|
+
orderNumber: 'ORD-001',
|
|
345
345
|
items: [
|
|
346
|
-
{ name:
|
|
347
|
-
{ name:
|
|
346
|
+
{ name: 'Product A', price: 10 },
|
|
347
|
+
{ name: 'Product B', price: 20 },
|
|
348
348
|
],
|
|
349
349
|
total: 30,
|
|
350
350
|
isPremium: false,
|
|
351
|
-
companyName:
|
|
351
|
+
companyName: 'Test Company',
|
|
352
352
|
};
|
|
353
353
|
|
|
354
354
|
const result = await docxService.generateDocx(templateBuffer, testData);
|
|
@@ -398,10 +398,10 @@ Ensure data is an array:
|
|
|
398
398
|
|
|
399
399
|
```typescript
|
|
400
400
|
// ❌ Won't iterate
|
|
401
|
-
items:
|
|
401
|
+
items: 'not an array';
|
|
402
402
|
|
|
403
403
|
// ✅ Will iterate
|
|
404
|
-
items: [{ name:
|
|
404
|
+
items: [{ name: 'A' }, { name: 'B' }];
|
|
405
405
|
```
|
|
406
406
|
|
|
407
407
|
### Q: Image not displaying?
|
|
@@ -420,7 +420,7 @@ Ensure condition is boolean:
|
|
|
420
420
|
|
|
421
421
|
```typescript
|
|
422
422
|
// ❌ String
|
|
423
|
-
isPremium:
|
|
423
|
+
isPremium: 'true';
|
|
424
424
|
|
|
425
425
|
// ✅ Boolean
|
|
426
426
|
isPremium: true;
|
package/package.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zola_do/docx",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "DOCX template processing for NestJS",
|
|
5
|
-
"author": "zolaDO",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"sideEffects": false,
|
|
8
|
-
"engines": {
|
|
9
|
-
"node": ">=20.0.0"
|
|
10
|
-
},
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
|
-
},
|
|
14
|
-
"main": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
|
-
"require": "./dist/index.js",
|
|
20
|
-
"default": "./dist/index.js"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist",
|
|
25
|
-
"README.md"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"clean": "rimraf dist",
|
|
29
|
-
"typecheck": "tsc --noEmit",
|
|
30
|
-
"build": "npm run clean && tsc",
|
|
31
|
-
"prepublishOnly": "npm run build"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
35
|
-
"reflect-metadata": "^0.1.0 || ^0.2.0",
|
|
36
|
-
"rxjs": "^7.0.0 || ^8.0.0"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"docx-templates": "^4.14.1"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"rimraf": "^6.1.3",
|
|
43
|
-
"typescript": "^5.9.3"
|
|
44
|
-
},
|
|
45
|
-
"repository": {
|
|
46
|
-
"directory": "packages/docx",
|
|
47
|
-
"type": "git",
|
|
48
|
-
"url": "https://github.com/zola0031/zola-nestjs-shared.git"
|
|
49
|
-
},
|
|
50
|
-
"homepage": "https://github.com/zola0031/zola-nestjs-shared#readme",
|
|
51
|
-
"bugs": {
|
|
52
|
-
"url": "https://github.com/zola0031/zola-nestjs-shared/issues"
|
|
53
|
-
},
|
|
54
|
-
"funding": {
|
|
55
|
-
"type": "github",
|
|
56
|
-
"url": "https://github.com/sponsors/zola0031"
|
|
57
|
-
},
|
|
58
|
-
"keywords": [
|
|
59
|
-
"nestjs",
|
|
60
|
-
"typescript",
|
|
61
|
-
"library",
|
|
62
|
-
"shared",
|
|
63
|
-
"monorepo",
|
|
64
|
-
"zola_do",
|
|
65
|
-
"docx",
|
|
66
|
-
"template",
|
|
67
|
-
"documents",
|
|
68
|
-
"nestjs-shared"
|
|
69
|
-
]
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@zola_do/docx",
|
|
3
|
+
"version": "0.2.12",
|
|
4
|
+
"description": "DOCX template processing for NestJS",
|
|
5
|
+
"author": "zolaDO",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20.0.0"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"require": "./dist/index.js",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"clean": "rimraf dist",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"build": "npm run clean && tsc",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
35
|
+
"reflect-metadata": "^0.1.0 || ^0.2.0",
|
|
36
|
+
"rxjs": "^7.0.0 || ^8.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"docx-templates": "^4.14.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"rimraf": "^6.1.3",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"directory": "packages/docx",
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/zola0031/zola-nestjs-shared.git"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/zola0031/zola-nestjs-shared#readme",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/zola0031/zola-nestjs-shared/issues"
|
|
53
|
+
},
|
|
54
|
+
"funding": {
|
|
55
|
+
"type": "github",
|
|
56
|
+
"url": "https://github.com/sponsors/zola0031"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"nestjs",
|
|
60
|
+
"typescript",
|
|
61
|
+
"library",
|
|
62
|
+
"shared",
|
|
63
|
+
"monorepo",
|
|
64
|
+
"zola_do",
|
|
65
|
+
"docx",
|
|
66
|
+
"template",
|
|
67
|
+
"documents",
|
|
68
|
+
"nestjs-shared"
|
|
69
|
+
]
|
|
70
|
+
}
|