mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[api-minor] Move removeNullCharacters
into the viewer
This helper function has never been used in e.g. the worker-thread, hence its placement in `src/shared/util.js` led to a *small* amount of unnecessary duplication. After the previous patches this helper function is now *only* used in the viewer, hence it no longer seems necessary to expose it through the official API. *Please note:* It seems somewhat unlikely that third-party users were relying *directly* on this helper function, which is why it's not being exported as part of the viewer components. (If necessary, we can always change this later on.)
This commit is contained in:
parent
00aa9811e6
commit
7b8794b37e
7 changed files with 46 additions and 48 deletions
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { removeNullCharacters } from "pdfjs-lib";
|
||||
import { removeNullCharacters } from "./ui_utils.js";
|
||||
|
||||
const TREEITEM_OFFSET_TOP = -100; // px
|
||||
const TREEITEM_SELECTED_CLASS = "selected";
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
/** @typedef {import("./event_utils").EventBus} EventBus */
|
||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
||||
|
||||
import { parseQueryString } from "./ui_utils.js";
|
||||
import { removeNullCharacters } from "pdfjs-lib";
|
||||
import { parseQueryString, removeNullCharacters } from "./ui_utils.js";
|
||||
|
||||
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
||||
|
||||
|
|
|
@ -200,6 +200,24 @@ function parseQueryString(query) {
|
|||
return params;
|
||||
}
|
||||
|
||||
const NullCharactersRegExp = /\x00/g;
|
||||
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @param {boolean} [replaceInvisible]
|
||||
*/
|
||||
function removeNullCharacters(str, replaceInvisible = false) {
|
||||
if (typeof str !== "string") {
|
||||
console.error(`The argument must be a string.`);
|
||||
return str;
|
||||
}
|
||||
if (replaceInvisible) {
|
||||
str = str.replace(InvisibleCharactersRegExp, " ");
|
||||
}
|
||||
return str.replace(NullCharactersRegExp, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Use binary search to find the index of the first item in a given array which
|
||||
* passes a given condition. The items are expected to be sorted in the sense
|
||||
|
@ -838,6 +856,7 @@ export {
|
|||
parseQueryString,
|
||||
PresentationModeState,
|
||||
ProgressBar,
|
||||
removeNullCharacters,
|
||||
RendererType,
|
||||
RenderingStates,
|
||||
roundToDivide,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue