mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Enable the unicorn/prefer-string-replace-all
ESLint plugin rule
Note that the `replaceAll` method still requires that a *global* regular expression is used, however by using this method it's immediately obvious when looking at the code that all occurrences will be replaced; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#parameters Please find additional details at https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md
This commit is contained in:
parent
5f64621d46
commit
1fc09f0235
26 changed files with 58 additions and 56 deletions
|
@ -60,7 +60,7 @@ class AForm {
|
|||
if (!actions) {
|
||||
actions = [];
|
||||
this._dateActionsCache.set(cFormat, actions);
|
||||
cFormat.replace(
|
||||
cFormat.replaceAll(
|
||||
/(d+)|(m+)|(y+)|(H+)|(M+)|(s+)/g,
|
||||
function (match, d, m, y, H, M, s) {
|
||||
if (d) {
|
||||
|
|
|
@ -65,7 +65,7 @@ class Util extends PDFObject {
|
|||
const ZERO = 4;
|
||||
const HASH = 8;
|
||||
let i = 0;
|
||||
return args[0].replace(
|
||||
return args[0].replaceAll(
|
||||
pattern,
|
||||
function (match, nDecSep, cFlags, nWidth, nPrecision, cConvChar) {
|
||||
// cConvChar must be one of d, f, s, x
|
||||
|
@ -287,7 +287,7 @@ class Util extends PDFObject {
|
|||
|
||||
const patterns =
|
||||
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t|\\.)/g;
|
||||
return cFormat.replace(patterns, function (match, pattern) {
|
||||
return cFormat.replaceAll(patterns, function (match, pattern) {
|
||||
if (pattern in handlers) {
|
||||
return handlers[pattern](data);
|
||||
}
|
||||
|
@ -523,12 +523,12 @@ class Util extends PDFObject {
|
|||
};
|
||||
|
||||
// escape the string
|
||||
const escapedFormat = cFormat.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
||||
const escapedFormat = cFormat.replaceAll(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
||||
const patterns =
|
||||
/(mmmm|mmm|mm|m|dddd|ddd|dd|d|yyyy|yy|HH|H|hh|h|MM|M|ss|s|tt|t)/g;
|
||||
const actions = [];
|
||||
|
||||
const re = escapedFormat.replace(
|
||||
const re = escapedFormat.replaceAll(
|
||||
patterns,
|
||||
function (match, patternElement) {
|
||||
const { pattern, action } = handlers[patternElement];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue