Socket
Socket
Sign inDemoInstall

node-xlsx

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-xlsx - npm Package Compare versions

Comparing version 0.18.0 to 0.19.0

29

lib/index.d.ts
/// <reference types="node" />
import XLSX, { AOA2SheetOpts, ParsingOptions, Sheet2JSONOpts, WritingOptions } from 'xlsx';
import XLSX, { AOA2SheetOpts, ParsingOptions, Sheet2JSONOpts, WritingOptions, AutoFilterInfo, ColInfo, ProtectInfo, Range, RowInfo } from 'xlsx';
export declare const parse: (mixed: unknown, options?: Sheet2JSONOpts & ParsingOptions) => {

@@ -11,10 +11,25 @@ name: string;

}[];
export declare type WorkSheetOptions = {
/** Column Info */
'!cols'?: ColInfo[];
/** Row Info */
'!rows'?: RowInfo[];
/** Merge Ranges */
'!merges'?: Range[];
/** Worksheet Protection info */
'!protect'?: ProtectInfo;
/** AutoFilter info */
'!autofilter'?: AutoFilterInfo;
};
export declare type WorkSheet<T = unknown> = {
name: string;
data: T[][];
options: AOA2SheetOpts;
options: WorkSheetOptions;
};
export declare const build: (worksheets: WorkSheet[], options?: WritingOptions & {
sheetOptions?: AOA2SheetOpts;
}) => Buffer;
export declare type BuildOptions = WorkSheetOptions & {
parseOptions?: AOA2SheetOpts;
writeOptions?: WritingOptions;
sheetOptions?: WorkSheetOptions;
};
export declare const build: (worksheets: WorkSheet[], { parseOptions, writeOptions, sheetOptions, ...otherOptions }?: BuildOptions) => Buffer;
declare const _default: {

@@ -29,6 +44,4 @@ parse: (mixed: unknown, options?: XLSX.Sheet2JSONOpts & XLSX.ParsingOptions) => {

}[];
build: (worksheets: WorkSheet<unknown>[], options?: XLSX.WritingOptions & {
sheetOptions?: XLSX.AOA2SheetOpts | undefined;
}) => Buffer;
build: (worksheets: WorkSheet<unknown>[], { parseOptions, writeOptions, sheetOptions, ...otherOptions }?: BuildOptions) => Buffer;
};
export default _default;

@@ -56,14 +56,23 @@ "use strict";

exports.parseMetadata = parseMetadata;
const build = (worksheets, options = {}) => {
const { bookType = 'xlsx', bookSST = false, type = 'buffer', sheetOptions = {}, ...otherOptions } = options;
const build = (worksheets, { parseOptions = {}, writeOptions = {}, sheetOptions = {}, ...otherOptions } = {}) => {
const { bookType = 'xlsx', bookSST = false, type = 'buffer', ...otherWriteOptions } = writeOptions;
const legacyOptions = Object.keys(otherOptions).filter((key) => {
if (['!cols', '!rows', '!merges', '!protect', '!autofilter'].includes(key)) {
console.debug(`Deprecated options['${key}'], please use options.sheetOptions['${key}'] instead.`);
return true;
}
console.debug(`Unknown options['${key}'], please use options.parseOptions / options.writeOptions`);
return false;
});
const workBook = worksheets.reduce((soFar, { name, data, options = {} }, index) => {
const sheetName = name || `Sheet_${index}`;
const sheetData = xlsx_1.utils.aoa_to_sheet(data, { ...sheetOptions, ...options });
const sheetData = xlsx_1.utils.aoa_to_sheet(data, parseOptions);
soFar.SheetNames.push(sheetName);
soFar.Sheets[sheetName] = sheetData;
Object.assign(soFar.Sheets[sheetName], legacyOptions, sheetOptions, options);
return soFar;
}, new workbook_1.WorkBook());
return xlsx_1.default.write(workBook, { bookType, bookSST, type, ...otherOptions });
return xlsx_1.default.write(workBook, { bookType, bookSST, type, ...otherWriteOptions });
};
exports.build = build;
exports.default = { parse: exports.parse, parseMetadata: exports.parseMetadata, build: exports.build };
{
"name": "node-xlsx",
"author": "Olivier Louvignes <olivier@mg-crea.com>",
"version": "0.18.0",
"version": "0.19.0",
"description": "NodeJS Excel files parser & builder",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

@@ -78,5 +78,5 @@ <!-- markdownlint-disable no-inline-html -->

];
const options = {'!cols': [{wch: 6}, {wch: 7}, {wch: 10}, {wch: 20}]};
const sheetOptions = {'!cols': [{wch: 6}, {wch: 7}, {wch: 10}, {wch: 20}]};
var buffer = xlsx.build([{name: 'mySheetName', data: data}], options); // Returns a buffer
var buffer = xlsx.build([{name: 'mySheetName', data: data}], {sheetOptions}); // Returns a buffer
```

@@ -83,0 +83,0 @@

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