1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Remove the isString helper function

The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls. Note that in the `src/`-folder we already had more `typeof`-cases than `isString`-calls.
This commit is contained in:
Jonas Jenwald 2022-02-23 17:02:19 +01:00
parent 6bd4e0f5af
commit 99cd24ce3e
9 changed files with 47 additions and 75 deletions

View file

@ -24,7 +24,6 @@ import {
escapeString,
getModificationDate,
isAscii,
isString,
OPS,
RenderingIntentFlag,
shadow,
@ -542,9 +541,8 @@ class Annotation {
* annotation was last modified
*/
setModificationDate(modificationDate) {
this.modificationDate = isString(modificationDate)
? modificationDate
: null;
this.modificationDate =
typeof modificationDate === "string" ? modificationDate : null;
}
/**
@ -1121,7 +1119,7 @@ class MarkupAnnotation extends Annotation {
* annotation was originally created
*/
setCreationDate(creationDate) {
this.creationDate = isString(creationDate) ? creationDate : null;
this.creationDate = typeof creationDate === "string" ? creationDate : null;
}
_setDefaultAppearance({
@ -1258,9 +1256,8 @@ class WidgetAnnotation extends Annotation {
const defaultAppearance =
getInheritableProperty({ dict, key: "DA" }) || params.acroForm.get("DA");
this._defaultAppearance = isString(defaultAppearance)
? defaultAppearance
: "";
this._defaultAppearance =
typeof defaultAppearance === "string" ? defaultAppearance : "";
data.defaultAppearanceData = parseDefaultAppearance(
this._defaultAppearance
);
@ -1305,11 +1302,11 @@ class WidgetAnnotation extends Annotation {
_decodeFormValue(formValue) {
if (Array.isArray(formValue)) {
return formValue
.filter(item => isString(item))
.filter(item => typeof item === "string")
.map(item => stringToPDFString(item));
} else if (formValue instanceof Name) {
return stringToPDFString(formValue.name);
} else if (isString(formValue)) {
} else if (typeof formValue === "string") {
return stringToPDFString(formValue);
}
return null;
@ -1788,7 +1785,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
const dict = params.dict;
// The field value is always a string.
if (!isString(this.data.fieldValue)) {
if (typeof this.data.fieldValue !== "string") {
this.data.fieldValue = "";
}
@ -2452,7 +2449,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
// item is selected or an array of strings if multiple items are selected.
// For consistency in the API and convenience in the display layer, we
// always make the field value an array with zero, one or multiple items.
if (isString(this.data.fieldValue)) {
if (typeof this.data.fieldValue === "string") {
this.data.fieldValue = [this.data.fieldValue];
} else if (!this.data.fieldValue) {
this.data.fieldValue = [];