Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,22 @@ function oneOf(expected, thing) {
}
}

function addNumericalSeparator(val) {
let res = val[val.length - 1];
let count = 0;
for (let i = val.length - 2; i >= 0; i--) {
count++;
if (val[i] === '.') {
return val;
}
if (count % 3 === 0 && i !== val.length && val[i] !== '-') {
res = `_${res}`;
}
res = `${val[i]}${res}`;
}
return res;
}

module.exports = {
addCodeToName, // Exported for NghttpError
codes,
Expand Down Expand Up @@ -1001,12 +1017,12 @@ E('ERR_OUT_OF_RANGE',
`The value of "${str}" is out of range.`;
let received;
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
received = String(input).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1_');
received = addNumericalSeparator(String(input));
// eslint-disable-next-line valid-typeof
} else if (typeof input === 'bigint') {
received = String(input);
if (input > 2n ** 32n || input < -(2n ** 32n)) {
received = received.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1_');
received = addNumericalSeparator(received);
}
received += 'n';
} else {
Expand Down