Skip to content

Commit 3347080

Browse files
committed
Do not use String#padStart()
It might not be available on older NodeJS and browsers. It can't be added by the Babel runtime because it is an instance function. Only Babel polyfill can add such functions and we can't use plyfill because it changes the global scope.
1 parent b88af7f commit 3347080

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/v1/internal/temporal-util.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,13 @@ function formatNumber(num, stringLength = undefined) {
383383
if (isNegative) {
384384
num = num.negate();
385385
}
386-
const numString = num.toString();
387-
const paddedNumString = stringLength ? numString.padStart(stringLength, '0') : numString;
388-
return isNegative ? '-' + paddedNumString : paddedNumString;
386+
387+
let numString = num.toString();
388+
if (stringLength) {
389+
// left pad the string with zeroes
390+
while (numString.length < stringLength) {
391+
numString = '0' + numString;
392+
}
393+
}
394+
return isNegative ? '-' + numString : numString;
389395
}

0 commit comments

Comments
 (0)