Skip to content

Commit e542aff

Browse files
committed
Use native padStart over custom impl
1 parent 8eed7b4 commit e542aff

2 files changed

Lines changed: 4 additions & 25 deletions

File tree

addons/addon-serialize/src/SerializeAddon.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -630,20 +630,6 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
630630
}
631631
}
632632

633-
private _padStart(target: string, targetLength: number, padString: string): string {
634-
targetLength = targetLength >> 0;
635-
padString = padString ?? ' ';
636-
if (target.length > targetLength) {
637-
return target;
638-
}
639-
640-
targetLength -= target.length;
641-
if (targetLength > padString.length) {
642-
padString += padString.repeat(targetLength / padString.length);
643-
}
644-
return padString.slice(0, targetLength) + target;
645-
}
646-
647633
protected _beforeSerialize(rows: number, start: number, end: number): void {
648634
this._htmlContent += '<html><body><!--StartFragment--><pre>';
649635

@@ -680,7 +666,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
680666
(color >> 8) & 255,
681667
(color ) & 255
682668
];
683-
return '#' + rgb.map(x => this._padStart(x.toString(16), 2, '0')).join('');
669+
return '#' + rgb.map(x => x.toString(16).padStart(2, '0')).join('');
684670
}
685671
if (isFg ? cell.isFgPalette() : cell.isBgPalette()) {
686672
return this._ansiColors[color].css;
@@ -700,7 +686,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
700686
(color >> 8) & 255,
701687
(color ) & 255
702688
];
703-
return '#' + rgb.map(x => this._padStart(x.toString(16), 2, '0')).join('');
689+
return '#' + rgb.map(x => x.toString(16).padStart(2, '0')).join('');
704690
}
705691
// Palette color
706692
return this._ansiColors[color].css;

src/browser/renderer/dom/DomRendererRowFactory.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export class DomRendererRowFactory {
397397
break;
398398
case Attributes.CM_RGB:
399399
resolvedBg = channels.toColor(bg >> 16, bg >> 8 & 0xFF, bg & 0xFF);
400-
this._addStyle(charElement, `background-color:#${padStart((bg >>> 0).toString(16), '0', 6)}`);
400+
this._addStyle(charElement, `background-color:#${(bg >>> 0).toString(16).padStart(6, '0')}`);
401401
break;
402402
case Attributes.CM_DEFAULT:
403403
default:
@@ -434,7 +434,7 @@ export class DomRendererRowFactory {
434434
(fg ) & 0xFF
435435
);
436436
if (!this._applyMinimumContrast(charElement, resolvedBg, color, cell, bgOverride, fgOverride)) {
437-
this._addStyle(charElement, `color:#${padStart(fg.toString(16), '0', 6)}`);
437+
this._addStyle(charElement, `color:#${fg.toString(16).padStart(6, '0')}`);
438438
}
439439
break;
440440
case Attributes.CM_DEFAULT:
@@ -537,10 +537,3 @@ export class DomRendererRowFactory {
537537
(start[1] < end[1] && y === start[1] && x >= start[0]);
538538
}
539539
}
540-
541-
function padStart(text: string, padChar: string, length: number): string {
542-
while (text.length < length) {
543-
text = padChar + text;
544-
}
545-
return text;
546-
}

0 commit comments

Comments
 (0)