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

extem

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extem - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

9

lib/Cell.d.ts

@@ -12,12 +12,9 @@ import { NodeAttributes } from './XMLUtil';

ref: () => string;
setRef: (ref: any) => any;
setRef: (ref: string) => string;
type: () => string;
style: () => number;
getValue: () => string;
setValue: (value: any) => any;
setValue: (value: string) => string;
formula: () => string;
address: () => {
c: number;
r: number;
};
address: () => XLSX.CellAddress;
moveTo: (to: string) => void;

@@ -24,0 +21,0 @@ moveBy: (a: XLSX.CellAddress) => void;

@@ -1,15 +0,15 @@

export declare const keys: (obj: any) => string[];
export declare const values: (obj: any) => any[];
export declare const not: (predicate: any) => (value: any) => boolean;
export declare const contains: (arr: any, value: any) => boolean;
export declare function readZip(xlsPath: any): Promise<{}>;
export declare function writeZip(xlsPath: any, zip: any): Promise<{}>;
export declare const keys: (obj: Object) => string[];
export declare const values: (obj: Object) => any[];
export declare const not: (predicate: Function) => (value: any) => boolean;
export declare const contains: <T>(arr: T[], value: T) => boolean;
export declare function readZipFile(xlsPath: string): Promise<{}>;
export declare function readData(data: any): Promise<any>;
export declare function writeZipFile(xlsPath: string, zip: any): Promise<{}>;
export declare function writeStream(zip: any): any;
export declare const getValueOld: (obj: any, path: any) => any;
export declare const getValue: (obj: any, path: any) => any;
export declare function templateType(str: any): "scalar" | "column" | "row" | null;
export declare const parseTemplate: (str: any) => {
export declare const getValue: (obj: any, path: string) => any;
export declare function templateType(str: string): "scalar" | "column" | "row" | null;
export declare const parseTemplate: (str: string) => {
type: string | null;
path: any;
path: string;
};
export declare const matchRangeTemplate: (str: any) => any;
export declare const matchRangeTemplate: (str: string) => "" | RegExpMatchArray | null;

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

//zip file access
function readZip(xlsPath) {
function readZipFile(xlsPath) {
return new Promise(function (resolve, reject) {

@@ -25,4 +25,8 @@ fs.readFile(xlsPath, 'binary', function (err, res) {

}
exports.readZip = readZip;
function writeZip(xlsPath, zip) {
exports.readZipFile = readZipFile;
function readData(data) {
return Promise.resolve(JSZip.loadAsync(data));
}
exports.readData = readData;
function writeZipFile(xlsPath, zip) {
return new Promise(function (resolve, reject) {

@@ -35,3 +39,3 @@ zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })

}
exports.writeZip = writeZip;
exports.writeZipFile = writeZipFile;
function writeStream(zip) {

@@ -41,14 +45,2 @@ return zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true });

exports.writeStream = writeStream;
//gets a value from an object
exports.getValueOld = function (obj, path) {
if (!(obj && path)) {
return obj;
}
var parts = path.split('.');
var value = obj[parts.shift() || ''];
while (parts.length && value) {
value = value[parts.shift() || ''];
}
return value;
};
function formatDate(date, format) {

@@ -87,4 +79,4 @@ if (format === void 0) { format = 'yyyy-mm-dd'; }

var type = templateType(str);
var path = str.match(/^[\$\|_]\{(.*?)\}$/)[1];
return { type: type, path: path };
var match = str.match(/^[\$\|_]\{(.*?)\}$/);
return { type: type, path: (match && match[1]) || '' };
};

@@ -91,0 +83,0 @@ exports.matchRangeTemplate = function (str) {

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

/// <reference types="node" />
import WorkSheet from './WorkSheet';
import Scope from './Scope';
import Styles from './Styles';
import Cell from './Cell';
export declare const parseScopeCell: (sheet: any) => (cell: Cell) => Scope;
export declare const parseScopeRange: (sheet: any) => (cell: Cell) => Scope;
export default class Workbook {
private filename;
private zip;

@@ -18,8 +14,11 @@ private sheets;

private rootScope;
constructor(filename: string);
read(): Promise<this>;
write(filename: any): Promise<{}>;
writeStream(): any;
constructor();
private readZip;
readFile(filename: string): Promise<this>;
read(data: any): Promise<this>;
private writeZip();
writeFile(filename: any): Promise<{}>;
writeStream(): NodeJS.WriteStream;
evaluate: (context: any) => void;
renameSheet: (from: any, to: any) => void;
renameSheet: (from: string, to: string) => void;
sheetNames: () => string[];

@@ -30,3 +29,3 @@ getSheet: (name: string) => WorkSheet;

private getRel;
getString: (index: any) => {};
getString: (index: number) => {};
private getRangeScopes;

@@ -45,3 +44,4 @@ private getCellScopes;

private writeXML;
static read(filename: any): Promise<Workbook>;
static readFile(filename: string): Promise<Workbook>;
static read(data: Buffer): Promise<Workbook>;
}

@@ -48,7 +48,7 @@ "use strict";

//not really sure where to keep this
exports.parseScopeCell = function (sheet) { return function (cell) {
var parseScopeCell = function (sheet) { return function (cell) {
var ref = cell.ref();
return new Scope_1.default(ref + ":" + ref, sheet, cell.getValue(), types_1.TYPE_CELL);
}; };
exports.parseScopeRange = function (sheet) { return function (cell) {
var parseScopeRange = function (sheet) { return function (cell) {
var match = Util_1.matchRangeTemplate(cell.formula());

@@ -61,5 +61,45 @@ //should always match as we only accept range scope cells here

var Workbook = /** @class */ (function () {
function Workbook(filename) {
function Workbook() {
var _this = this;
this.filename = filename;
this.readZip = function (zip) { return __awaiter(_this, void 0, void 0, function () {
var _this = this;
var _a, _b, _c, _d, _e, _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
this.zip = zip;
//parse workbook, sheets and strings
_a = this;
return [4 /*yield*/, this.readXML('_rels/workbook.xml.rels')];
case 1:
//parse workbook, sheets and strings
_a.rels = _g.sent();
_b = this;
return [4 /*yield*/, this.readXML('workbook.xml')];
case 2:
_b.workbook = _g.sent();
_c = this;
return [4 /*yield*/, this.readXML('sharedStrings.xml')];
case 3:
_c.strings = _g.sent();
_d = this;
return [4 /*yield*/, Promise.all(this.sheetPaths().map(this.readXML))];
case 4:
_d.sheets = _g.sent();
this.worksheets = this.sheetNames().map(function (name, index) {
return new WorkSheet_1.default(_this.sheets[index], _this, name);
});
_e = this;
_f = Styles_1.default.bind;
return [4 /*yield*/, this.readXML('styles.xml')];
case 5:
_e.styles = new (_f.apply(Styles_1.default, [void 0, _g.sent(), this]))();
//get the ranges and remove them from the sheet
this.scopes = Array().concat(this.getRangeScopes(), this.getCellScopes());
// console.log(this.scopes);
this.rootScope = this.createScopeTree(this.scopes);
return [2 /*return*/, this];
}
});
}); };
this.evaluate = function (context) { return _this.rootScope.getChildren().forEach(_this.interpolate(context)); };

@@ -91,3 +131,3 @@ //sheet operations

var scopeRanges = _this.getSheet(sheet).getScopeRanges();
return scopes.concat(scopeRanges.map(exports.parseScopeRange(sheet)));
return scopes.concat(scopeRanges.map(parseScopeRange(sheet)));
}, Array());

@@ -98,3 +138,3 @@ };

var scopeCells = _this.getSheet(sheet).getScopeCells();
return scopes.concat(scopeCells.map(exports.parseScopeCell(sheet)));
return scopes.concat(scopeCells.map(parseScopeCell(sheet)));
}, Array());

@@ -254,44 +294,11 @@ };

//read and write
Workbook.prototype.read = function () {
Workbook.prototype.readFile = function (filename) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
switch (_h.label) {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, Util_1.readZip(this.filename)];
case 1:
_a.zip = _h.sent();
//parse workbook, sheets and strings
_b = this;
return [4 /*yield*/, this.readXML('_rels/workbook.xml.rels')];
case 2:
//parse workbook, sheets and strings
_b.rels = _h.sent();
_c = this;
return [4 /*yield*/, this.readXML('workbook.xml')];
case 3:
_c.workbook = _h.sent();
_d = this;
return [4 /*yield*/, this.readXML('sharedStrings.xml')];
case 4:
_d.strings = _h.sent();
_e = this;
return [4 /*yield*/, Promise.all(this.sheetPaths().map(this.readXML))];
case 5:
_e.sheets = _h.sent();
this.worksheets = this.sheetNames().map(function (name, index) {
return new WorkSheet_1.default(_this.sheets[index], _this, name);
});
_f = this;
_g = Styles_1.default.bind;
return [4 /*yield*/, this.readXML('styles.xml')];
case 6:
_f.styles = new (_g.apply(Styles_1.default, [void 0, _h.sent(), this]))();
//get the ranges and remove them from the sheet
this.scopes = Array().concat(this.getRangeScopes(), this.getCellScopes());
// console.log(this.scopes);
this.rootScope = this.createScopeTree(this.scopes);
return [2 /*return*/, this];
_a = this.readZip;
return [4 /*yield*/, Util_1.readZipFile(filename)];
case 1: return [2 /*return*/, _a.apply(this, [_b.sent()])];
}

@@ -301,3 +308,16 @@ });

};
Workbook.prototype.write = function (filename) {
Workbook.prototype.read = function (data) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.readZip;
return [4 /*yield*/, Util_1.readData(data)];
case 1: return [2 /*return*/, _a.apply(this, [_b.sent()])];
}
});
});
};
Workbook.prototype.writeZip = function () {
var _this = this;

@@ -309,18 +329,18 @@ //write back workbook, sheets and strings

this.sheetPaths().forEach(function (path, index) { return _this.writeXML(path, _this.worksheets[index]._writeSheetData()); });
return Util_1.writeZip(filename, this.zip);
return this.zip;
};
Workbook.prototype.writeFile = function (filename) {
return Util_1.writeZipFile(filename, this.writeZip());
};
Workbook.prototype.writeStream = function () {
var _this = this;
//write back workbook, sheets and strings
this.writeXML('workbook.xml', this.workbook);
this.writeXML('sharedStrings.xml', this.strings);
// this.sheetPaths().forEach((path, index) => this.writeXML(path, this.sheets[index]));
this.sheetPaths().forEach(function (path, index) { return _this.writeXML(path, _this.worksheets[index]._writeSheetData()); });
return Util_1.writeStream(this.zip);
return Util_1.writeStream(this.writeZip());
};
Workbook.read = function (filename) {
return new Workbook(filename).read();
Workbook.readFile = function (filename) {
return new Workbook().readFile(filename);
};
Workbook.read = function (data) {
return new Workbook().read(data);
};
return Workbook;
}());
exports.default = Workbook;

@@ -30,3 +30,3 @@ import * as XLSX from './XLSXUtil';

getName: () => string;
insertCellMoveDim: (ref: any, direction: XLSX.Direction) => void;
insertCellMoveDim: (ref: string, direction: XLSX.Direction) => void;
getScopeRanges: () => Cell[];

@@ -33,0 +33,0 @@ getScopeCells: () => Cell[];

@@ -11,36 +11,21 @@ export declare const VERTICAL = "r";

export declare type RangeRef = string;
export declare const relAddress: (offset: number, direction: Direction) => {
c: number;
r: number;
};
export declare const relAddress: (offset: number, direction: Direction) => CellAddress;
export declare const decodeRow: (str: string) => number;
export declare const encodeRow: (row: number) => string;
export declare const decodeCol: (str: string) => number;
export declare const encodeCol: (col: any) => string;
export declare const encodeCol: (col: number) => string;
export declare const getCellRef: ({c, r}: CellAddress) => string;
export declare const getCellRel: (a: CellAddress, ref: any) => string;
export declare const getCellAddress: (ref: any) => {
c: number;
r: number;
};
export declare const getCellOffset: (offset: number, direction: Direction, ref: any) => string;
export declare const getCellRel: (a: CellAddress, ref: string) => string;
export declare const getCellAddress: (ref: any) => CellAddress;
export declare const getCellOffset: (offset: number, direction: Direction, ref: string) => string;
export declare const splitRange: (ref: string) => string[];
export declare const getRangeAddress: (ref: string) => {
c: number;
r: number;
}[];
export declare const getRangeAddress: (ref: string) => CellAddress[];
export declare const getRangeRef: (address: CellAddress[]) => string;
export declare const getRangeDim: (ref: string, direction: Direction) => number;
export declare const inRange: (range: any) => (ref: any) => boolean;
export declare const getRangeCells: (range: any) => string[];
export declare const addAddress: (aa: any, ab: any) => {
c: any;
r: any;
};
export declare const subtractAddress: (aa: any, ab: any) => {
c: number;
r: number;
};
export declare const inRange: (range: string) => (ref: string) => boolean;
export declare const getRangeCells: (range: string) => string[];
export declare const addAddress: (aa: CellAddress, ab: CellAddress) => CellAddress;
export declare const subtractAddress: (aa: CellAddress, ab: CellAddress) => CellAddress;
export declare const cellAtOrAfterDim: (aa: CellAddress, ab: CellAddress, direction: Direction) => boolean;
export declare const rangeAfterCellDim: (ca: CellAddress, ra: CellAddress[], direction: Direction) => boolean;
export declare const cellAtOrAfterRangeDim: (ca: CellAddress, ra: CellAddress[], direction: Direction) => boolean;
{
"name": "extem",
"version": "1.1.1",
"version": "2.0.0",
"description": "",

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

@@ -21,6 +21,6 @@ # Extem

Extem.read('./template.xlsx').then((template) => {
Extem.readFile('./template.xlsx').then((template) => {
template.evaluate(myData);
return template.write('./generated.xlsx').then(() => {
return template.writeFile('./generated.xlsx').then(() => {
console.log('written');

@@ -27,0 +27,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