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.0.\n * Original file: /npm/istextorbinary-ilkkah@6.0.1/edition-browsers/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* eslint no-use-before-define:0 */\nimport * as pathUtil from 'path';\nimport textExtensions from 'textextensions';\nimport binaryExtensions from 'binaryextensions';\n/**\n * Determine if the filename and/or buffer is text.\n * Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection.\n * This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16.\n * The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions\n * @param filename The filename for the file/buffer if available\n * @param buffer The buffer for the file if available\n * @returns Will be `null` if neither `filename` nor `buffer` were provided. Otherwise will be a boolean value with the detection result.\n */\nexport function isText(filename, buffer) {\n    // Test extensions\n    if (filename) {\n        // Extract filename\n        const parts = pathUtil.basename(filename).split('.').reverse();\n        // Cycle extensions\n        for (const extension of parts) {\n            if (textExtensions.indexOf(extension) !== -1) {\n                return true;\n            }\n            if (binaryExtensions.indexOf(extension) !== -1) {\n                return false;\n            }\n        }\n    }\n    // Fallback to encoding if extension check was not enough\n    if (buffer) {\n        return getEncoding(buffer) === 'utf8';\n    }\n    // No buffer was provided\n    return null;\n}\n/**\n * Determine if the filename and/or buffer is binary.\n * Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection.\n * This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16.\n * The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions\n * @param filename The filename for the file/buffer if available\n * @param buffer The buffer for the file if available\n * @returns Will be `null` if neither `filename` nor `buffer` were provided. Otherwise will be a boolean value with the detection result.\n */\nexport function isBinary(filename, buffer) {\n    const text = isText(filename, buffer);\n    if (text == null)\n        return null;\n    return !text;\n}\n/**\n * Get the encoding of a buffer.\n * Checks the start, middle, and end of the buffer for characters that are unrecognized within UTF8 encoding.\n * History has shown that inspection at all three locations is necessary.\n * @returns Will be `null` if `buffer` was not provided. Otherwise will be either `'utf8'` or `'binary'`\n */\nexport function getEncoding(buffer, opts) {\n    // Check\n    if (!buffer)\n        return null;\n    // Prepare\n    const textEncoding = 'utf8';\n    const binaryEncoding = 'binary';\n    const chunkLength = opts?.chunkLength ?? 24;\n    let chunkBegin = opts?.chunkBegin ?? 0;\n    // Discover\n    if (opts?.chunkBegin == null) {\n        // Start\n        let encoding = getEncoding(buffer, { chunkLength, chunkBegin });\n        if (encoding === textEncoding) {\n            // Middle\n            chunkBegin = Math.max(0, Math.floor(buffer.length / 2) - chunkLength);\n            encoding = getEncoding(buffer, {\n                chunkLength,\n                chunkBegin,\n            });\n            if (encoding === textEncoding) {\n                // End\n                chunkBegin = Math.max(0, buffer.length - chunkLength);\n                encoding = getEncoding(buffer, {\n                    chunkLength,\n                    chunkBegin,\n                });\n            }\n        }\n        // Return\n        return encoding;\n    }\n    else {\n        // Extract\n        chunkBegin = getChunkBegin(buffer, chunkBegin);\n        if (chunkBegin === -1) {\n            return binaryEncoding;\n        }\n        const chunkEnd = getChunkEnd(buffer, Math.min(buffer.length, chunkBegin + chunkLength));\n        if (chunkEnd > buffer.length) {\n            return binaryEncoding;\n        }\n        const contentChunkUTF8 = buffer.toString(textEncoding, chunkBegin, chunkEnd);\n        // Detect encoding\n        for (let i = 0; i < contentChunkUTF8.length; ++i) {\n            const charCode = contentChunkUTF8.charCodeAt(i);\n            if (charCode === 65533 || charCode <= 8) {\n                // 8 and below are control characters (e.g. backspace, null, eof, etc.)\n                // 65533 is the unknown character\n                // console.log(charCode, contentChunkUTF8[i])\n                return binaryEncoding;\n            }\n        }\n        // Return\n        return textEncoding;\n    }\n}\n// ====================================\n// The functions below are created to handle multibyte utf8 characters.\n// To understand how the encoding works, check this article: https://en.wikipedia.org/wiki/UTF-8#Encoding\n// @todo add documentation for these\nfunction getChunkBegin(buf, chunkBegin) {\n    // If it's the beginning, just return.\n    if (chunkBegin === 0) {\n        return 0;\n    }\n    if (!isLaterByteOfUtf8(buf[chunkBegin])) {\n        return chunkBegin;\n    }\n    let begin = chunkBegin - 3;\n    if (begin >= 0) {\n        if (isFirstByteOf4ByteChar(buf[begin])) {\n            return begin;\n        }\n    }\n    begin = chunkBegin - 2;\n    if (begin >= 0) {\n        if (isFirstByteOf4ByteChar(buf[begin]) ||\n            isFirstByteOf3ByteChar(buf[begin])) {\n            return begin;\n        }\n    }\n    begin = chunkBegin - 1;\n    if (begin >= 0) {\n        // Is it a 4-byte, 3-byte utf8 character?\n        if (isFirstByteOf4ByteChar(buf[begin]) ||\n            isFirstByteOf3ByteChar(buf[begin]) ||\n            isFirstByteOf2ByteChar(buf[begin])) {\n            return begin;\n        }\n    }\n    return -1;\n}\nfunction getChunkEnd(buf, chunkEnd) {\n    // If it's the end, just return.\n    if (chunkEnd === buf.length) {\n        return chunkEnd;\n    }\n    let index = chunkEnd - 3;\n    if (index >= 0) {\n        if (isFirstByteOf4ByteChar(buf[index])) {\n            return chunkEnd + 1;\n        }\n    }\n    index = chunkEnd - 2;\n    if (index >= 0) {\n        if (isFirstByteOf4ByteChar(buf[index])) {\n            return chunkEnd + 2;\n        }\n        if (isFirstByteOf3ByteChar(buf[index])) {\n            return chunkEnd + 1;\n        }\n    }\n    index = chunkEnd - 1;\n    if (index >= 0) {\n        if (isFirstByteOf4ByteChar(buf[index])) {\n            return chunkEnd + 3;\n        }\n        if (isFirstByteOf3ByteChar(buf[index])) {\n            return chunkEnd + 2;\n        }\n        if (isFirstByteOf2ByteChar(buf[index])) {\n            return chunkEnd + 1;\n        }\n    }\n    return chunkEnd;\n}\nfunction isFirstByteOf4ByteChar(byte) {\n    // eslint-disable-next-line no-bitwise\n    return byte >> 3 === 30; // 11110xxx?\n}\nfunction isFirstByteOf3ByteChar(byte) {\n    // eslint-disable-next-line no-bitwise\n    return byte >> 4 === 14; // 1110xxxx?\n}\nfunction isFirstByteOf2ByteChar(byte) {\n    // eslint-disable-next-line no-bitwise\n    return byte >> 5 === 6; // 110xxxxx?\n}\nfunction isLaterByteOfUtf8(byte) {\n    // eslint-disable-next-line no-bitwise\n    return byte >> 6 === 2; // 10xxxxxx?\n}\n"]}