Skip to content

Commit

Permalink
refactor: rename props to opts (#96)
Browse files Browse the repository at this point in the history
* rename ColProps to ColOpts

* rename RowProps to RowOpts

* rename WorksheetProps to WorksheetOpts
  • Loading branch information
motinados authored Mar 30, 2024
1 parent 0b5115c commit 8241cf9
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 131 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import { Workbook } from "xlsx-kaku";
const wb = new Workbook();
const ws = wb.addWorksheet("Sheet1");

ws.setColProps({
ws.setColOpts({
index: 0,
width: 12,
style: { fill: { patternType: "solid", fgColor: "FFFFFF00" } },
Expand All @@ -169,9 +169,9 @@ import { Workbook } from "xlsx-kaku";
const wb = new Workbook();
const ws = wb.addWorksheet("Sheet1");

// Currently, RowProps do not work without a value in the cell.
// Currently, RowOpts do not work without a value in the cell.
ws.setCell(0, 0, { type: "number", value: 1 });
ws.setRowProps({
ws.setRowOpts({
index: 0,
height: 20,
style: { fill: { patternType: "solid", fgColor: "FFFFFF00" } },
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { NumberFormat } from "./numberFormats";
import { Cell, NullableCell, RowData, SheetData } from "./sheetData";
import { Workbook, WorkbookS } from "./workbook";
import {
ColProps,
ColOpts,
Worksheet,
WorksheetS,
MergeCell,
FreezePane,
RowProps,
RowOpts,
ConditionalFormatting,
} from "./worksheet";
import { genXlsx, genXlsxSync } from "./writer";
Expand All @@ -22,12 +22,12 @@ export { NumberFormat };
export { Cell, NullableCell, RowData, SheetData };
export { Workbook, WorkbookS };
export {
ColProps,
ColOpts,
Worksheet,
WorksheetS,
MergeCell,
FreezePane,
RowProps,
RowOpts,
ConditionalFormatting,
};
export { genXlsx, genXlsxSync };
10 changes: 5 additions & 5 deletions src/workbook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { genXlsx, genXlsxSync } from "./writer";
import {
Worksheet,
WorksheetProps,
WorksheetOpts,
WorksheetS,
WorksheetType,
} from "./worksheet";
Expand All @@ -14,12 +14,12 @@ export class Workbook {
private _worksheets: WorksheetType[] = [];
private _imageStore: ImageStore = new ImageStore();

addWorksheet(sheetName: string, props?: WorksheetProps) {
addWorksheet(sheetName: string, opts?: WorksheetOpts) {
if (this._worksheets.some((ws) => ws.name === sheetName)) {
throw new Error(`Worksheet name "${sheetName}" is already used.`);
}

const ws = new Worksheet(sheetName, this._imageStore, props);
const ws = new Worksheet(sheetName, this._imageStore, opts);
this._worksheets.push(ws);
return ws;
}
Expand All @@ -43,12 +43,12 @@ export class Workbook {
export class WorkbookS {
private _worksheets: WorksheetType[] = [];

addWorksheet(sheetName: string, props?: WorksheetProps) {
addWorksheet(sheetName: string, opts?: WorksheetOpts) {
if (this._worksheets.some((ws) => ws.name === sheetName)) {
throw new Error(`Worksheet name "${sheetName}" is already used.`);
}

const ws = new WorksheetS(sheetName, props);
const ws = new WorksheetS(sheetName, opts);
this._worksheets.push(ws);
return ws;
}
Expand Down
86 changes: 43 additions & 43 deletions src/worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { CellStyle, NullableCell, SheetData } from "./sheetData";
export const DEFAULT_COL_WIDTH = 9;
export const DEFAULT_ROW_HEIGHT = 13.5;

export type ColProps = {
export type ColOpts = {
index: number;
width?: number;
style?: CellStyle;
};

export type RowProps = {
export type RowOpts = {
index: number;
height?: number;
style?: CellStyle;
Expand Down Expand Up @@ -159,19 +159,19 @@ export type Image = {

export type ImageInfo = Omit<Image, "data">;

export type WorksheetProps = {
export type WorksheetOpts = {
defaultColWidth?: number;
defaultRowHeight?: number;
};

type RequiredWorksheetProps = Required<WorksheetProps>;
type RequiredWorksheetOpts = Required<WorksheetOpts>;

export type WorksheetType = {
name: string;
props: RequiredWorksheetProps;
opts: RequiredWorksheetOpts;
sheetData: SheetData;
cols: Map<number, ColProps>;
rows: Map<number, RowProps>;
colOptsMap: Map<number, ColOpts>;
rowOptsMap: Map<number, RowOpts>;
mergeCells: MergeCell[];
freezePane: FreezePane | null;
mergeCellsModule: MergeCellsModule | null;
Expand All @@ -181,8 +181,8 @@ export type WorksheetType = {
imageModule: ImageModule | null;
getCell(rowIndex: number, colIndex: number): NullableCell;
setCell(rowIndex: number, colIndex: number, cell: NullableCell): void;
setColProps(col: ColProps): void;
setRowProps(row: RowProps): void;
setColOpts(col: ColOpts): void;
setRowOpts(row: RowOpts): void;
setFreezePane(freezePane: FreezePane): void;
};

Expand All @@ -191,10 +191,10 @@ export type WorksheetType = {
*/
export class Worksheet implements WorksheetType {
private _name: string;
private _props: RequiredWorksheetProps;
private _opts: RequiredWorksheetOpts;
private _sheetData: SheetData = [];
private _cols = new Map<number, ColProps>();
private _rows = new Map<number, RowProps>();
private _colOptsMap = new Map<number, ColOpts>();
private _rowOptsMap = new Map<number, RowOpts>();
private _mergeCellsModule: MergeCellsModule = mergeCellsModule();
private _freezePane: FreezePane | null = null;
private _conditionalFormattingModule: ConditionalFormattingModule =
Expand All @@ -206,13 +206,13 @@ export class Worksheet implements WorksheetType {
constructor(
name: string,
imageStore?: ImageStore,
props: WorksheetProps | undefined = {}
opts: WorksheetOpts | undefined = {}
) {
this._name = name;

this._props = {
defaultColWidth: props.defaultColWidth ?? DEFAULT_COL_WIDTH,
defaultRowHeight: props.defaultRowHeight ?? DEFAULT_ROW_HEIGHT,
this._opts = {
defaultColWidth: opts.defaultColWidth ?? DEFAULT_COL_WIDTH,
defaultRowHeight: opts.defaultRowHeight ?? DEFAULT_ROW_HEIGHT,
};

this._imageStore = imageStore || new ImageStore();
Expand All @@ -222,8 +222,8 @@ export class Worksheet implements WorksheetType {
return this._name;
}

get props() {
return this._props;
get opts() {
return this._opts;
}

set sheetData(sheetData: SheetData) {
Expand All @@ -234,12 +234,12 @@ export class Worksheet implements WorksheetType {
return this._sheetData;
}

get cols() {
return this._cols;
get colOptsMap() {
return this._colOptsMap;
}

get rows() {
return this._rows;
get rowOptsMap() {
return this._rowOptsMap;
}

get mergeCells() {
Expand Down Expand Up @@ -304,12 +304,12 @@ export class Worksheet implements WorksheetType {
rows[colIndex] = cell;
}

setColProps(colProps: ColProps) {
this._cols.set(colProps.index, colProps);
setColOpts(colOpts: ColOpts) {
this._colOptsMap.set(colOpts.index, colOpts);
}

setRowProps(row: RowProps) {
this._rows.set(row.index, row);
setRowOpts(rowOpts: RowOpts) {
this._rowOptsMap.set(rowOpts.index, rowOpts);
}

setMergeCell(mergeCell: MergeCell) {
Expand All @@ -335,32 +335,32 @@ export class Worksheet implements WorksheetType {
*/
export class WorksheetS implements WorksheetType {
private _name: string;
private _props: RequiredWorksheetProps;
private _opts: RequiredWorksheetOpts;
private _sheetData: SheetData = [];
private _cols = new Map<number, ColProps>();
private _rows = new Map<number, RowProps>();
private _colOptsMap = new Map<number, ColOpts>();
private _rowOptsMap = new Map<number, RowOpts>();
private _mergeCellsModule = null;
private _freezePane: FreezePane | null = null;
private _conditionalFormattingModule = null;

private _imageStore = null;
private _imageModule = null;

constructor(name: string, props: WorksheetProps | undefined = {}) {
constructor(name: string, opts: WorksheetOpts | undefined = {}) {
this._name = name;

this._props = {
defaultColWidth: props.defaultColWidth ?? DEFAULT_COL_WIDTH,
defaultRowHeight: props.defaultRowHeight ?? DEFAULT_ROW_HEIGHT,
this._opts = {
defaultColWidth: opts.defaultColWidth ?? DEFAULT_COL_WIDTH,
defaultRowHeight: opts.defaultRowHeight ?? DEFAULT_ROW_HEIGHT,
};
}

get name() {
return this._name;
}

get props() {
return this._props;
get opts() {
return this._opts;
}

set sheetData(sheetData: SheetData) {
Expand All @@ -371,12 +371,12 @@ export class WorksheetS implements WorksheetType {
return this._sheetData;
}

get cols() {
return this._cols;
get colOptsMap() {
return this._colOptsMap;
}

get rows() {
return this._rows;
get rowOptsMap() {
return this._rowOptsMap;
}

get mergeCells() {
Expand Down Expand Up @@ -441,12 +441,12 @@ export class WorksheetS implements WorksheetType {
rows[colIndex] = cell;
}

setColProps(colProps: ColProps) {
this._cols.set(colProps.index, colProps);
setColOpts(colOpts: ColOpts) {
this._colOptsMap.set(colOpts.index, colOpts);
}

setRowProps(row: RowProps) {
this._rows.set(row.index, row);
setRowOpts(rowOpts: RowOpts) {
this._rowOptsMap.set(rowOpts.index, rowOpts);
}

setFreezePane(freezePane: FreezePane) {
Expand Down
Loading

0 comments on commit 8241cf9

Please sign in to comment.