Skip to content

Commit

Permalink
refactor!: use object spread instead of Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Feb 7, 2021
1 parent eeac740 commit 22681f0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
10 changes: 6 additions & 4 deletions command/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ export class Command<O = any, A extends Array<any> = any> {
this._versionOption?.flags || "-V, --version",
this._versionOption?.desc ||
"Show the version number for this program.",
Object.assign({
{
standalone: true,
prepend: true,
action: async function (this: Command) {
Expand All @@ -758,23 +758,25 @@ export class Command<O = any, A extends Array<any> = any> {
);
Deno.exit(0);
},
}, this._versionOption?.opts ?? {}),
...(this._versionOption?.opts ?? {}),
},
);
}

if (this._helpOption !== false) {
this.option(
this._helpOption?.flags || "-h, --help",
this._helpOption?.desc || "Show this help.",
Object.assign({
{
standalone: true,
global: true,
prepend: true,
action: function (this: Command) {
this.showHelp();
Deno.exit(0);
},
}, this._helpOption?.opts ?? {}),
...(this._helpOption?.opts ?? {}),
},
);
}

Expand Down
5 changes: 3 additions & 2 deletions command/help/_help_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export class HelpGenerator {
}

private constructor(private cmd: Command, options: HelpOptions = {}) {
this.options = Object.assign({
this.options = {
types: false,
hints: true,
}, options);
...options,
};
}

private generate(): string {
Expand Down
4 changes: 2 additions & 2 deletions table/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Cell {
public static from(value: ICell): Cell {
const cell = new this(value);
if (value instanceof Cell) {
cell.options = Object.assign({}, value.options);
cell.options = { ...value.options };
}
return cell;
}
Expand Down Expand Up @@ -57,7 +57,7 @@ export class Cell {
*/
public clone(value?: ICell): Cell {
const cell = new Cell(value ?? this);
cell.options = Object.assign({}, this.options);
cell.options = { ...this.options };
return cell;
}

Expand Down
4 changes: 2 additions & 2 deletions table/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Row<T extends ICell = ICell> extends Array<T> {
public static from<T extends ICell = ICell>(cells: IRow<T>): Row<T> {
const row = new this(...cells);
if (cells instanceof Row) {
row.options = Object.assign({}, cells.options);
row.options = { ...cells.options };
}
return row;
}
Expand All @@ -35,7 +35,7 @@ export class Row<T extends ICell = ICell> extends Array<T> {
const row = new Row(
...this.map((cell: T) => cell instanceof Cell ? cell.clone() : cell),
);
row.options = Object.assign({}, this.options);
row.options = { ...this.options };
return row;
}

Expand Down
8 changes: 4 additions & 4 deletions table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export type ITable<T extends IRow = IRow> = T[] | Table<T>;

/** Table representation. */
export class Table<T extends IRow = IRow> extends Array<T> {
protected static _chars: IBorder = Object.assign({}, border);
protected static _chars: IBorder = { ...border };
protected options: ITableSettings = {
indent: 0,
border: false,
maxColWidth: Infinity,
minColWidth: 0,
padding: 1,
chars: Object.assign({}, Table._chars),
chars: { ...Table._chars },
};
private headerRow?: Row;

Expand All @@ -45,7 +45,7 @@ export class Table<T extends IRow = IRow> extends Array<T> {
public static from<T extends IRow>(rows: ITable<T>): Table<T> {
const table = new this(...rows);
if (rows instanceof Table) {
table.options = Object.assign({}, rows.options);
table.options = { ...rows.options };
table.headerRow = rows.headerRow ? Row.from(rows.headerRow) : undefined;
}
return table;
Expand Down Expand Up @@ -114,7 +114,7 @@ export class Table<T extends IRow = IRow> extends Array<T> {
row instanceof Row ? row.clone() : Row.from(row).clone()
),
);
table.options = Object.assign({}, this.options);
table.options = { ...this.options };
table.headerRow = this.headerRow?.clone();
return table;
}
Expand Down

0 comments on commit 22681f0

Please sign in to comment.