diff --git a/lib/core/streams/aes-crypto-stream.js b/lib/core/streams/aes-crypto-stream.js index 530a0b85..78eed6e8 100644 --- a/lib/core/streams/aes-crypto-stream.js +++ b/lib/core/streams/aes-crypto-stream.js @@ -29,7 +29,7 @@ /* global crypto, TransformStream */ // deno-lint-ignore-file no-this-alias -import { UNDEFINED_VALUE } from "../constants.js"; +import { UNDEFINED_VALUE, UNDEFINED_TYPE, FUNCTION_TYPE } from "../constants.js"; import { encodeText } from "./../util/encode-text.js"; import { cipher, @@ -56,8 +56,6 @@ const SALT_LENGTH = [8, 12, 16]; const KEY_LENGTH = [16, 24, 32]; const SIGNATURE_LENGTH = 10; const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0]; -const UNDEFINED_TYPE = "undefined"; -const FUNCTION_TYPE = "function"; // deno-lint-ignore valid-typeof const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE; const subtle = CRYPTO_API_SUPPORTED && crypto.subtle; diff --git a/lib/core/streams/common-crypto.js b/lib/core/streams/common-crypto.js index 27a4d8f1..6fa6730b 100644 --- a/lib/core/streams/common-crypto.js +++ b/lib/core/streams/common-crypto.js @@ -28,11 +28,12 @@ /* global crypto */ +import { FUNCTION_TYPE, UNDEFINED_TYPE } from "../constants.js"; import { random } from "./codecs/sjcl.js"; -const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != "undefined" && typeof crypto.getRandomValues == "function"; +const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE; const ERR_INVALID_PASSWORD = "Invalid password"; const ERR_INVALID_SIGNATURE = "Invalid signature"; diff --git a/lib/core/util/stream-codec-shim.js b/lib/core/util/stream-codec-shim.js index 2e63be99..e505b0a3 100644 --- a/lib/core/util/stream-codec-shim.js +++ b/lib/core/util/stream-codec-shim.js @@ -29,6 +29,8 @@ // deno-lint-ignore-file no-this-alias +import { FUNCTION_TYPE, UNDEFINED_VALUE } from "../constants.js"; + export { initShimAsyncCodec }; @@ -42,7 +44,7 @@ function initShimAsyncCodec(library, options = {}, registerDataHandler) { function objectHasOwn(object, propertyName) { // eslint-disable-next-line no-prototype-builtins - return typeof Object.hasOwn === "function" ? Object.hasOwn(object, propertyName) : object.hasOwnProperty(propertyName); + return typeof Object.hasOwn === FUNCTION_TYPE ? Object.hasOwn(object, propertyName) : object.hasOwnProperty(propertyName); } function createCodecClass(constructor, constructorOptions, registerDataHandler) { @@ -61,7 +63,7 @@ function createCodecClass(constructor, constructorOptions, registerDataHandler) codecAdapter.pendingData = new Uint8Array(data); } }; - if (objectHasOwn(options, "level") && options.level === undefined) { + if (objectHasOwn(options, "level") && options.level === UNDEFINED_VALUE) { delete options.level; } codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options)); diff --git a/lib/core/zip-fs-core.js b/lib/core/zip-fs-core.js index 1ef53182..98d6fd42 100644 --- a/lib/core/zip-fs-core.js +++ b/lib/core/zip-fs-core.js @@ -52,6 +52,7 @@ import { import { Entry } from "./zip-entry.js"; +import { UNDEFINED_VALUE } from "./constants.js"; class ZipEntry { @@ -433,7 +434,7 @@ class ZipDirectoryEntry extends ZipEntry { async exportZip(writer, options) { const zipEntry = this; - if (options.bufferedWrite === undefined) { + if (options.bufferedWrite === UNDEFINED_VALUE) { options.bufferedWrite = true; } await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]); diff --git a/lib/core/zip-reader.js b/lib/core/zip-reader.js index 203cebf9..8d76bcbb 100644 --- a/lib/core/zip-reader.js +++ b/lib/core/zip-reader.js @@ -455,7 +455,7 @@ class ZipEntry { await writable.getWriter().close(); } } - return checkPasswordOnly ? undefined : writer.getData ? writer.getData() : writable; + return checkPasswordOnly ? UNDEFINED_VALUE : writer.getData ? writer.getData() : writable; } } diff --git a/lib/z-worker-bootstrap-fflate.js b/lib/z-worker-bootstrap-fflate.js index 35641bec..592401fe 100644 --- a/lib/z-worker-bootstrap-fflate.js +++ b/lib/z-worker-bootstrap-fflate.js @@ -31,9 +31,10 @@ import "./core/z-worker-core.js"; import { initShimAsyncCodec } from "./core/util/stream-codec-shim.js"; +import { UNDEFINED_VALUE } from "./core/constants.js"; self.initCodec = () => { - const { Deflate, Inflate } = initShimAsyncCodec(fflate, undefined, (codec, onData) => codec.ondata = onData); + const { Deflate, Inflate } = initShimAsyncCodec(fflate, UNDEFINED_VALUE, (codec, onData) => codec.ondata = onData); self.Deflate = Deflate; self.Inflate = Inflate; }; \ No newline at end of file diff --git a/lib/zip-fflate-shim.js b/lib/zip-fflate-shim.js index 07e63b8d..efe8b735 100644 --- a/lib/zip-fflate-shim.js +++ b/lib/zip-fflate-shim.js @@ -31,5 +31,7 @@ import { Inflate as FflateInflate } from "fflate"; import { initShimAsyncCodec } from "./core/util/stream-codec-shim.js"; -const { Deflate, Inflate } = initShimAsyncCodec({ Deflate: FflateDeflate, Inflate: FflateInflate }, undefined, (codec, onData) => codec.ondata = onData); +import { UNDEFINED_VALUE } from "./core/constants.js"; + +const { Deflate, Inflate } = initShimAsyncCodec({ Deflate: FflateDeflate, Inflate: FflateInflate }, UNDEFINED_VALUE, (codec, onData) => codec.ondata = onData); export { Deflate, Inflate }; \ No newline at end of file