Move the getModificationDate helper function into src/core/core_utils.js

Given that this function is only ever used in `src/core/` code, let's avoid a little bit of dead code in the *built* `pdf.mjs` file.

Also, place the `AnnotationPrefix` and `AnnotationEditorPrefix` constants together in `src/shared/util.js` since that should aid readability.
This commit is contained in:
Jonas Jenwald 2026-05-11 14:06:51 +02:00
parent 702d60aa18
commit aecb571ea6
6 changed files with 30 additions and 34 deletions

View File

@ -26,7 +26,6 @@ import {
BBOX_INIT,
F32_BBOX_INIT,
FeatureTest,
getModificationDate,
info,
isArrayEqual,
LINE_DESCENT_FACTOR,
@ -43,6 +42,7 @@ import {
collectActions,
escapeString,
getInheritableProperty,
getModificationDate,
getParentToUpdate,
getRotationMatrix,
IDENTITY_MATRIX,

View File

@ -716,6 +716,22 @@ function stringToUTF16String(str, bigEndian = false) {
return buf.join("");
}
function getModificationDate(date = new Date()) {
if (!(date instanceof Date)) {
date = new Date(date);
}
const buffer = [
date.getUTCFullYear().toString(),
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
date.getUTCDate().toString().padStart(2, "0"),
date.getUTCHours().toString().padStart(2, "0"),
date.getUTCMinutes().toString().padStart(2, "0"),
date.getUTCSeconds().toString().padStart(2, "0"),
];
return buffer.join("");
}
function getRotationMatrix(rotation, width, height) {
switch (rotation) {
case 90:
@ -753,6 +769,7 @@ export {
fetchBinaryData,
getInheritableProperty,
getLookupTableFactory,
getModificationDate,
getNewAnnotationsMap,
getParentToUpdate,
getRotationMatrix,

View File

@ -23,17 +23,14 @@
import {
deepCompare,
getInheritableProperty,
getModificationDate,
getNewAnnotationsMap,
stringToAsciiOrUTF16BE,
} from "../core_utils.js";
import { Dict, isName, Name, Ref, RefSet, RefSetCache } from "../primitives.js";
import {
getModificationDate,
stringToBytes,
stringToPDFString,
} from "../../shared/util.js";
import { incrementalUpdate, writeValue } from "../writer.js";
import { NameTree, NumberTree } from "../name_number_tree.js";
import { stringToBytes, stringToPDFString } from "../../shared/util.js";
import { AnnotationFactory } from "../annotation.js";
import { BaseStream } from "../base_stream.js";
import { StringStream } from "../stream.js";

View File

@ -69,6 +69,7 @@ const AnnotationMode = {
ENABLE_STORAGE: 3,
};
const AnnotationPrefix = "pdfjs_internal_id_";
const AnnotationEditorPrefix = "pdfjs_internal_editor_";
const AnnotationEditorType = {
@ -1122,22 +1123,6 @@ function isArrayEqual(arr1, arr2) {
return true;
}
function getModificationDate(date = new Date()) {
if (!(date instanceof Date)) {
date = new Date(date);
}
const buffer = [
date.getUTCFullYear().toString(),
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
date.getUTCDate().toString().padStart(2, "0"),
date.getUTCHours().toString().padStart(2, "0"),
date.getUTCMinutes().toString().padStart(2, "0"),
date.getUTCSeconds().toString().padStart(2, "0"),
];
return buffer.join("");
}
let NormalizeRegex = null;
let NormalizationMap = null;
function normalizeUnicode(str) {
@ -1169,8 +1154,6 @@ function getUuid() {
return bytesToString(buf);
}
const AnnotationPrefix = "pdfjs_internal_id_";
function _isValidExplicitDest(validRef, validName, dest) {
if (!Array.isArray(dest) || dest.length < 2) {
return false;
@ -1273,7 +1256,6 @@ export {
FeatureTest,
FONT_IDENTITY_MATRIX,
FormatError,
getModificationDate,
getUuid,
getVerbosityLevel,
ImageKind,

View File

@ -20,6 +20,7 @@ import {
escapePDFName,
escapeString,
getInheritableProperty,
getModificationDate,
getSizeInBytes,
isAscii,
isWhiteSpace,
@ -557,6 +558,14 @@ describe("core_utils", function () {
});
});
describe("getModificationDate", function () {
it("should get a correctly formatted date", function () {
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
expect(getModificationDate(date)).toEqual("31410609020653");
expect(getModificationDate(date.toString())).toEqual("31410609020653");
});
});
describe("getSizeInBytes", function () {
it("should get the size in bytes to use to represent a positive integer", function () {
expect(getSizeInBytes(0)).toEqual(0);

View File

@ -17,7 +17,6 @@ import {
BaseException,
bytesToString,
createValidAbsoluteUrl,
getModificationDate,
getUuid,
stringToBytes,
stringToPDFString,
@ -210,14 +209,6 @@ describe("util", function () {
});
});
describe("getModificationDate", function () {
it("should get a correctly formatted date", function () {
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
expect(getModificationDate(date)).toEqual("31410609020653");
expect(getModificationDate(date.toString())).toEqual("31410609020653");
});
});
describe("getUuid", function () {
it("should get uuid string", function () {
const uuid = getUuid();