Skip to content

Commit

Permalink
Move the regular expression caching into the PDFDateString class
Browse files Browse the repository at this point in the history
This code is old enough that it pre-dates availability of private class fields, hence why this wasn't done originally.
  • Loading branch information
Snuffleupagus committed Oct 11, 2024
1 parent c6d01ca commit 8afc542
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,9 @@ function deprecated(details) {
console.log("Deprecated API usage: " + details);
}

let pdfDateStringRegex;

class PDFDateString {
static #regex;

/**
* Convert a PDF date string to a JavaScript `Date` object.
*
Expand All @@ -960,7 +960,7 @@ class PDFDateString {
}

// Lazily initialize the regular expression.
pdfDateStringRegex ||= new RegExp(
this.#regex ||= new RegExp(
"^D:" + // Prefix (required)
"(\\d{4})" + // Year (required)
"(\\d{2})?" + // Month (optional)
Expand All @@ -978,7 +978,7 @@ class PDFDateString {
// Optional fields that don't satisfy the requirements from the regular
// expression (such as incorrect digit counts or numbers that are out of
// range) will fall back the defaults from the specification.
const matches = pdfDateStringRegex.exec(input);
const matches = this.#regex.exec(input);
if (!matches) {
return null;
}
Expand Down

0 comments on commit 8afc542

Please sign in to comment.