1.0.45 • Published 10 months ago

@rainbow-o23/n6 v1.0.45

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Static Badge

ExcelJS CSV for Node.js

Module Formats

o23/n6

o23/n6 provides

  • A pipeline step that converts csv templates to csv, implemented based on CSV-Parse and CSV-stringify,
  • A pipeline step that converts excel template to excel, implemented base on ExcelJS.

CSV Generate Step

Environment Parameters

NameTypeDefault ValueComments
print.csv.temporary.file.keepbooleanfalseOnly for debug purpose, never turn on in production.
print.csv.temporary.file.usebooleanfalseUse temporary file or not.
print.csv.temporary.lines.freshnumber100How many lines to fresh to temporary file.
print.csv.temporary.dirstring.csv-temporary-filesTemporary file directory.

Constructor Parameters

NameTypeDefault ValueComments
delimiterstring,
escapeCharstring"
useTempFileboolean

Request and Response

export interface PrintCsvPipelineStepInFragment {
	template: Buffer | string;
	data: any;
}

export interface PrintCsvPipelineStepOutFragment {
	file: Buffer;
}

An Example

Data

const data = {
	type: 'Test CSV',
	information: [
		{name: 'John', age: 25, birthday: '1998-03-27', addresses: ['address line 1', 'address line 2']},
		{name: 'Jane', age: 27, birthday: '1996-08-12', addresses: ['address line 3']},
		{name: 'Mike', age: 21, birthday: '2002-11-20'}
	],
	policy: [
		{id: 1000001, productName: 'PRDT-001', productInfo: 'PRDT-001-INFO'},
		{id: 1000002, productName: 'PRDT-002', productInfo: 'PRDT-002-INFO'}
	]
};

Template

column1,column2
$type
Name,Age,Birthday
$information.start
$name,$age,$birthday
$addresses.start
$.$
$addresses.end
$information.end
Id,Product Name,Product Info
$policy.start
$id,$productName,$productInfo
$policy.end
  • Supports nested loops,
  • $information.start, $addresses.start, $policy.start represent loop start,
  • $addresses.end, $information.end, $policy.end represent loop end,
  • $name, $age, $birthday represent property, - Supports multi-level property names, connected by .. For example, $person.name represents that person is an object and name is a property under person,
  • $.$ represents use loop array itself, in this example, addresses array is a string array,
  • All properties are relative paths, calculated relative to their parent node. Therefore, within a loop, only the values of each element can be accessed.

Output

column1,column2
Test CSV
Name,Age,Birthday
John,25,1998-03-27
address line 1
address line 2
Jane,27,1996-08-12
address line 3
Mike,21,2002-11-20
Id,Product Name,Product Info
1000001,PRDT-001,PRDT-001-INFO
1000002,PRDT-002,PRDT-002-INFO

Performance Benchmark

This benchmark was conducted on the following hardware and environment:

  • CPU: 2.6 GHz 6-Core Intel Core i7,
  • Memory: 64 GB 2667 MHz DDR4,
  • OS: macOS Sonoma 14.2.1,
  • MySQL: 8.2.0,
  • NodeJS: v18.19.0,
  • NPM: v10.2.3.

With scenario:

  • Flow: - Load template from database, - Print file, - Write printed file to database, - Return to client,
  • Template size: 0.4kb, 4 lines * 30 columns,
  • Output size: 5.8mb, 10001 lines * 30 columns.
#ItemMax CPU UsageMax Memory UsageAvg. Response Time (ms)
1100 iterations, single thread120%600M471
2100 iterations, 4 concurrent threads150%700M1444
3100 iterations, 8 concurrent threads160%750M2917

Excel Generate Step

Environment Parameters

NameTypeDefault ValueComments
print.excel.temporary.file.keepbooleanfalseOnly for debug purpose, never turn on in production.
print.excel.temporary.dirstring.excel-temporary-filesTemporary file directory.

Request and Response

export interface PrintExcelPipelineStepInFragment {
	/** it is an Excel file, after 2007 */
	template: Buffer;
	data: any;
}

export interface PrintExcelPipelineStepOutFragment {
	file: Buffer;
}

Syntax

Find template and unit test in /test folder, syntax for using an Excel template is as follows:

  • Supports nested loops,
  • $xxx.start represents loop start,
  • $xxx.end represents loop end,
  • Loop flag needs to be defined in the note of the cell and occupy a separate line,
  • Loop flag must be defined in first column,
  • $xxx represents property, - Supports multi-level property names, connected by .. For example, $person.name represents that person is an object and name is a property under person,
  • $.$ represents use loop array itself,
  • All properties are relative paths, calculated relative to their parent node. Therefore, within a loop, only the values of each element can be accessed.

Known Issues

  • Cannot apply auto filter into merged cells correctly, each cell will display a filter, which should only be displayed on the last cell.
  • Cannot copy theme correctly, please use the specified color and do not choose from the suggested theme colors provided by Excel.
  • ExcelJS does not read the note data of empty cells. Therefore, when the loop flag appears on an empty cell, it needs to be specially marked with the $.$del flag.

Performance Benchmark

This benchmark was conducted on the following hardware and environment:

  • CPU: 2.6 GHz 6-Core Intel Core i7,
  • Memory: 64 GB 2667 MHz DDR4,
  • OS: macOS Sonoma 14.2.1,
  • MySQL: 8.2.0,
  • NodeJS: v18.19.0,
  • NPM: v10.2.3.

With scenario:

  • Flow: - Load template from database, - Print file, - Write printed file to database, - Return to client,
  • Template size: 12kb, 2 lines * 30 columns,
  • Output size: 4.1mb, 10001 lines * 30 columns.
#ItemMax CPU UsageMax Memory UsageAvg. Response Time (ms)
1100 iterations, single thread120%550M945
2100 iterations, 4 concurrent threads150%850M2878
3100 iterations, 8 concurrent threads170%1000M5718
1.0.45

10 months ago

1.0.44

11 months ago

1.0.37

1 year ago

1.0.39

12 months ago

1.0.38

12 months ago

1.0.40

12 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.36

1 year ago

1.0.33

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

0.1.21

1 year ago

0.1.21-alpha.2

1 year ago

0.1.21-alpha.1

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.15

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.9

1 year ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.2-alpha.3

2 years ago

0.1.2-alpha.2

2 years ago

0.1.2-alpha

2 years ago

0.1.1

2 years ago