mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Change isNodeJS
from a function to a constant
Given that this shouldn't change after the `pdf.js`/`pdf.worker.js` files have been loaded, it doesn't seems necessary to keep this as a function.
This commit is contained in:
parent
2817121bc1
commit
74e00ed93c
16 changed files with 49 additions and 50 deletions
|
@ -581,7 +581,7 @@ function isMessagePort(maybePort) {
|
|||
}
|
||||
|
||||
// Worker thread (and not node.js)?
|
||||
if (typeof window === 'undefined' && !isNodeJS() &&
|
||||
if (typeof window === 'undefined' && !isNodeJS &&
|
||||
typeof self !== 'undefined' && isMessagePort(self)) {
|
||||
WorkerMessageHandler.initializeFromPort(self);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||
// Support: Node.js
|
||||
(function checkFontFaceAndImage() {
|
||||
// Node.js is missing native support for `@font-face` and `Image`.
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
compatibilityParams.disableFontFace = true;
|
||||
compatibilityParams.nativeImageDecoderSupport = 'none';
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ const convertImgDataToPng = (function() {
|
|||
* http://www.libpng.org/pub/png/spec/1.2/PNG-Compression.html
|
||||
*/
|
||||
function deflateSync(literals) {
|
||||
if (!isNodeJS()) {
|
||||
if (!isNodeJS) {
|
||||
// zlib is certainly not available outside of Node.js. We can either use
|
||||
// the pako library for client-side DEFLATE compression, or use the canvas
|
||||
// API of the browser to obtain a more optimal PNG file.
|
||||
|
|
|
@ -32,7 +32,7 @@ let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
|||
|
||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||
const { isNodeJS, } = require('./shared/is_node.js');
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||
return new PDFNodeStream(params);
|
||||
|
|
|
@ -28,7 +28,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||
|
||||
// Support: Node.js
|
||||
(function checkNodeBtoa() {
|
||||
if (globalScope.btoa || !isNodeJS()) {
|
||||
if (globalScope.btoa || !isNodeJS) {
|
||||
return;
|
||||
}
|
||||
globalScope.btoa = function(chars) {
|
||||
|
@ -39,7 +39,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||
|
||||
// Support: Node.js
|
||||
(function checkNodeAtob() {
|
||||
if (globalScope.atob || !isNodeJS()) {
|
||||
if (globalScope.atob || !isNodeJS) {
|
||||
return;
|
||||
}
|
||||
globalScope.atob = function(input) {
|
||||
|
@ -69,7 +69,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||
// one parameter, in legacy browsers.
|
||||
// Support: IE
|
||||
(function checkDOMTokenListAddRemove() {
|
||||
if (!hasDOM || isNodeJS()) {
|
||||
if (!hasDOM || isNodeJS) {
|
||||
return;
|
||||
}
|
||||
const div = document.createElement('div');
|
||||
|
@ -98,7 +98,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||
// "force" parameter, in legacy browsers.
|
||||
// Support: IE
|
||||
(function checkDOMTokenListToggle() {
|
||||
if (!hasDOM || isNodeJS()) {
|
||||
if (!hasDOM || isNodeJS) {
|
||||
return;
|
||||
}
|
||||
const div = document.createElement('div');
|
||||
|
|
|
@ -14,14 +14,13 @@
|
|||
*/
|
||||
/* globals process */
|
||||
|
||||
function isNodeJS() {
|
||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
|
||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
|
||||
// https://electronjs.org/docs/api/process#processversionselectron
|
||||
return typeof process === 'object' &&
|
||||
process + '' === '[object process]' &&
|
||||
!process.versions['nw'] && !process.versions['electron'];
|
||||
}
|
||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
|
||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
|
||||
// https://electronjs.org/docs/api/process#processversionselectron
|
||||
const isNodeJS =
|
||||
typeof process === 'object' &&
|
||||
process + '' === '[object process]' &&
|
||||
!process.versions['nw'] && !process.versions['electron'];
|
||||
|
||||
export {
|
||||
isNodeJS,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue