Poor man's rightPad

This commit is contained in:
Jordan Eldredge 2018-01-31 21:12:35 -08:00
parent 01afc1c067
commit df81666b1d

View file

@ -4,10 +4,20 @@ import { connect } from "react-redux";
import CharacterString from "../CharacterString";
import { getRunningTimeMessage } from "../../selectors";
// While all the browsers I care about support String.prototype.padEnd,
// Not all node versions do, and I want tests to pass in Jest...
// Sigh.
function rightPad(str, len, fillChar) {
while (str.length < len) {
str += fillChar;
}
return str;
}
const RunningTimeDisplay = props => (
<div className="playlist-running-time-display draggable">
<CharacterString>
{props.runningTimeMessage.padEnd(18, " ")}
{rightPad(props.runningTimeMessage, 18, " ")}
</CharacterString>
</div>
);