fix RangeError
This commit is contained in:
parent
cedaa11b30
commit
3d9c6a95ad
1 changed files with 23 additions and 0 deletions
23
format.js
Normal file
23
format.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
module.exports = format
|
||||
|
||||
function format (string, _with = []) {
|
||||
try {
|
||||
let i = 0
|
||||
|
||||
return string.replace(/%(?:(\d+)\$)?(s|%)/g, (g0, g1) => {
|
||||
if (g0 === '%%') {
|
||||
return '%'
|
||||
} else {
|
||||
const idx = g1 ? parseInt(g1) - 1 : i++
|
||||
if (_with[idx] !== undefined && _with[idx].length !== undefined) {
|
||||
if (_with[idx].length > 5000) return;
|
||||
};
|
||||
if (_with[idx] !== undefined) {
|
||||
return _with[idx]
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) { console.log(error); return; };
|
||||
}
|
Loading…
Reference in a new issue