From 59e139c1ad9f16bdcc2699de441af4f3acc047ec Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Thu, 28 Jul 2022 20:26:21 -0700 Subject: [PATCH] Remove examples that suggest getting type from `field.constructor.name` It is not safe/stable to rely on `.constructor.name` in general because minification will mangle the names of constructor functions (to make them as short as possible). This has confused several folks before, as seen in these issues: https://github.com/Hopding/pdf-lib/issues/736 https://github.com/Hopding/pdf-lib/issues/755 https://github.com/Hopding/pdf-lib/issues/933 https://github.com/Hopding/pdf-lib/issues/1089 As such, I think we should remove these examples from the codebase. --- src/api/PDFDocument.ts | 3 +-- src/api/form/PDFForm.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/api/PDFDocument.ts b/src/api/PDFDocument.ts index e102368e2..7b2d7d655 100644 --- a/src/api/PDFDocument.ts +++ b/src/api/PDFDocument.ts @@ -244,9 +244,8 @@ export default class PDFDocument { * const form = pdfDoc.getForm() * const fields = form.getFields() * fields.forEach(field => { - * const type = field.constructor.name * const name = field.getName() - * console.log(`${type}: ${name}`) + * console.log(`fieldName: ${name}`) * }) * ``` * @returns The form for this document. diff --git a/src/api/form/PDFForm.ts b/src/api/form/PDFForm.ts index e92c833fc..4dabf326c 100644 --- a/src/api/form/PDFForm.ts +++ b/src/api/form/PDFForm.ts @@ -131,9 +131,8 @@ export default class PDFForm { * const form = pdfDoc.getForm() * const fields = form.getFields() * fields.forEach(field => { - * const type = field.constructor.name * const name = field.getName() - * console.log(`${type}: ${name}`) + * console.log(`fieldName: ${name}`) * }) * ``` * @returns An array of all fields in this form.