diff --git a/eslint.config.mjs b/eslint.config.mjs index 1abe845a..75dd3867 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,33 +1,22 @@ -import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import js from "@eslint/js"; +import tseslint from "typescript-eslint"; +import tsParser from "@typescript-eslint/parser"; import jsdoc from "eslint-plugin-jsdoc"; import security from "eslint-plugin-security"; import sonarjs from "eslint-plugin-sonarjs"; import unicorn from "eslint-plugin-unicorn"; import globals from "globals"; -import tsParser from "@typescript-eslint/parser"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; -import js from "@eslint/js"; -import { FlatCompat } from "@eslint/eslintrc"; /* eslint-disable @typescript-eslint/naming-convention */ -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all, -}); - -export default [ - { ignores: [] }, - ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), +export default tseslint.config( + { ignores: ["dist/**", "node_modules/**"] }, + js.configs.recommended, + tseslint.configs.recommended, sonarjs.configs.recommended, security.configs.recommended, { plugins: { - "@typescript-eslint": typescriptEslint, jsdoc, security, unicorn, @@ -46,6 +35,12 @@ export default [ "unicorn/text-encoding-identifier-case": "error", "unicorn/explicit-length-check": "error", "unicorn/single-line-block-comment-style": "error", + "unicorn/prevent-abbreviations": "error", + "unicorn/no-keyword-prefix": "error", + "unicorn/prefer-export-from": "error", + "unicorn/prefer-set-has": "error", + "unicorn/no-lonely-if": "error", + "unicorn/prefer-array-some": "error", semi: ["error"], "jsdoc/require-asterisk-prefix": "error", @@ -54,11 +49,25 @@ export default [ "jsdoc/check-types": "error", "jsdoc/no-undefined-types": "error", "jsdoc/require-jsdoc": "error", - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-inferrable-types": "off", + + "sonarjs/no-unused-vars": "off", + "sonarjs/no-dead-store": "off", + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { + argsIgnorePattern: "^_", + }], "@typescript-eslint/ban-ts-comment": "error", "@typescript-eslint/naming-convention": "error", + + "no-unused-expressions": "off", + "@typescript-eslint/no-unused-expressions": "error", + + "no-shadow": "off", + "@typescript-eslint/no-shadow": "error", + + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-inferrable-types": "off", + "@/object-curly-spacing": ["error", "always"], quotes: ["error", "double", { @@ -77,12 +86,6 @@ export default [ eqeqeq: "error", "no-else-return": "error", - "no-unused-vars": ["error", { - argsIgnorePattern: "^_", - }], - - "no-unused-expressions": "error", - "@typescript-eslint/no-unused-expressions": "error", "no-eval": "error", "no-unexpected-multiline": "error", "eol-last": "error", @@ -107,5 +110,5 @@ export default [ rules: { "no-restricted-imports": "off", }, - } -]; + }, +); diff --git a/package-lock.json b/package-lock.json index 4d0ecd02..a48d260e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,12 +20,10 @@ }, "devDependencies": { "@arethetypeswrong/cli": "^0.18.5", - "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^10.0.1", "@secretlint/secretlint-rule-preset-recommend": "^13.0.4", "@types/node": "^20.19.37", "@types/tmp": "^0.2.6", - "@typescript-eslint/eslint-plugin": "^8.57.0", "@typescript-eslint/parser": "^8.58.1", "eslint": "^10.8.1", "eslint-plugin-jsdoc": "^62.7.1", @@ -41,7 +39,8 @@ "tslib": "^2.8.1", "tsx": "^4.21.0", "typedoc": "^0.28.18", - "typescript": "^5.9.3" + "typescript": "^5.9.3", + "typescript-eslint": "^8.70.0" }, "engines": { "node": ">= 20.1" @@ -738,45 +737,6 @@ "node": "^20.19.0 || ^22.13.0 || >=24" } }, - "node_modules/@eslint/config-array/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/@eslint/config-array/node_modules/brace-expansion": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", - "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/@eslint/config-array/node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.8" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@eslint/config-helpers": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.7.0.tgz", @@ -817,43 +777,6 @@ "node": "^20.19.0 || ^22.13.0 || >=24" } }, - "node_modules/@eslint/eslintrc": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.6.tgz", - "integrity": "sha512-l2Ul9PrHsPCKcEY/ac7VgFj9D80C7S68sOKc618SyHDPK36s1XcFebXY0iTzUVn4Yq+YbwvSnDmCz9yxjX+QrA==", - "dev": true, - "license": "MIT", - "dependencies": { - "ajv": "^6.14.0", - "debug": "^4.3.2", - "espree": "^10.0.1", - "globals": "^14.0.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.3.0", - "minimatch": "^3.1.5", - "strip-json-comments": "^3.1.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@eslint/js": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", @@ -2091,17 +2014,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.68.0.tgz", - "integrity": "sha512-WASHDpCm6qO5jj9g1a+8NiW5+GCkAyLReR56/4VruYmNgfUmqpxOfZ2Yfb8xGfJPWv5Qi6LSD8sXdces3vbp/Q==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.70.0.tgz", + "integrity": "sha512-/v8HZt6RlyIZxB3ntehELOcUcfxKPVGWXnQdJuHRmzrqgF8nQypcC/oxGW+Ot4VGKDq81XugPKxx0n5PBtf9PA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.68.0", - "@typescript-eslint/type-utils": "8.68.0", - "@typescript-eslint/utils": "8.68.0", - "@typescript-eslint/visitor-keys": "8.68.0", + "@typescript-eslint/scope-manager": "8.70.0", + "@typescript-eslint/type-utils": "8.70.0", + "@typescript-eslint/utils": "8.70.0", + "@typescript-eslint/visitor-keys": "8.70.0", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" @@ -2114,7 +2037,7 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.68.0", + "@typescript-eslint/parser": "^8.70.0", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } @@ -2130,16 +2053,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.68.0.tgz", - "integrity": "sha512-fHq2VC1kpyYfvEcbiMjOpySY4WS7voEp89yAThrHRX5sm9j2lzYppCb2umFMEed4fWcyeLjHxrz0mpjNBaBxMQ==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.70.0.tgz", + "integrity": "sha512-zYvrmj9Yxd63UGaXw+kdt6A0F0s0qveJyuatIM77bYC2DE4pgmg7a50u8LR7PRtXd0x+h+Tl3eXabGm06SWd3Q==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.68.0", - "@typescript-eslint/types": "8.68.0", - "@typescript-eslint/typescript-estree": "8.68.0", - "@typescript-eslint/visitor-keys": "8.68.0", + "@typescript-eslint/scope-manager": "8.70.0", + "@typescript-eslint/types": "8.70.0", + "@typescript-eslint/typescript-estree": "8.70.0", + "@typescript-eslint/visitor-keys": "8.70.0", "debug": "^4.4.3" }, "engines": { @@ -2155,14 +2078,14 @@ } }, "node_modules/@typescript-eslint/project-service": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.68.0.tgz", - "integrity": "sha512-5GQtWZCXFcFYux955pvoS02WLc49pXNlvIxocKjS0clvwo3in1RdlzVKyiqQH9vE5AKWFLTaUgeQkOrTS+0Qxw==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.70.0.tgz", + "integrity": "sha512-hFHbTNqhU9G+2eKFXCBVb1tjFT/LceiJ4+HfLO4pTpDI0KHi6iajpcFFkaSQ9gXmCh7n82A0PthaayEdN6mspQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.68.0", - "@typescript-eslint/types": "^8.68.0", + "@typescript-eslint/tsconfig-utils": "^8.70.0", + "@typescript-eslint/types": "^8.70.0", "debug": "^4.4.3" }, "engines": { @@ -2177,14 +2100,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.68.0.tgz", - "integrity": "sha512-T5eXpcaJNg8bhjHJ8Rjp68Vq/QBteYtTKY8TZqVNPaUbuz0f6jI9t6aDkylwvalpAB9XTTFeFOjrjXAZ3YvmVA==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.70.0.tgz", + "integrity": "sha512-8nP3Kwh5hlgZ4FicGvmznAmJe8UL4sdU8tLukrPaMuQmDuk4Y8xYfzu/aYZW4xT2JCgc7H/TpDI5cGlxcWJSqQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.68.0", - "@typescript-eslint/visitor-keys": "8.68.0" + "@typescript-eslint/types": "8.70.0", + "@typescript-eslint/visitor-keys": "8.70.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2195,9 +2118,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.68.0.tgz", - "integrity": "sha512-F7zrGQfiJHojPwi8vhxZQC1tWtJzvL74cK/nqri2lk8YUXvYaYwl263xOJ69jDWPUk1hmcdoayFwk9lX09npVw==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.70.0.tgz", + "integrity": "sha512-adnkeeNq9Sq1sUf4+FRVc0KdgYghzsgFpZSQVZVvY0LCuUuN0FnQgyGzCJeC4fW1cdXseBAjU2EOqUIjbNcZUw==", "dev": true, "license": "MIT", "engines": { @@ -2212,15 +2135,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.68.0.tgz", - "integrity": "sha512-X77zqoY1EjeWGs/0JNxeaMfp5C5lIz4Tw8y66F1Ne8Faq6g424sBNYM6xBAqElfGZPLpWS+CZAp0DXyKDzWiHg==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.70.0.tgz", + "integrity": "sha512-NUMKIhYVaVIVLnRL9CRt+VVcuLgSHUCpXn4/+K8wql+vdInUzvx8BjUO1oJ7cG9shjFJKtF8F8Hh2kCh3/KBVw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.68.0", - "@typescript-eslint/typescript-estree": "8.68.0", - "@typescript-eslint/utils": "8.68.0", + "@typescript-eslint/types": "8.70.0", + "@typescript-eslint/typescript-estree": "8.70.0", + "@typescript-eslint/utils": "8.70.0", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, @@ -2237,9 +2160,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.68.0.tgz", - "integrity": "sha512-9RnpsGJjrAllCMefGVVsImJM24YurhC0Q1h4UbvivtvOqXmR/vEJge2OoE++z9m6hyg8T1Q8t5SNT6tHSbrxcg==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.70.0.tgz", + "integrity": "sha512-asTOIYhDg4zdzOScCyaytrsV3cR6B4ecPQlXw/dJIm7J/MZTtCtfVII9JD8Geh4jTCrK/Xe6cg5UevoleMcoJQ==", "dev": true, "license": "MIT", "engines": { @@ -2251,16 +2174,16 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.68.0.tgz", - "integrity": "sha512-OKKsD0tYmoNiU5PW2zehO1yO56jYOm1ShYlxon/Z0SJNidAkdVg86eg9ruRuoXf8xfnuWZGbwDsStkoXbZtIIA==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.70.0.tgz", + "integrity": "sha512-d9NmHMPEKQ7QCLLm1jI3zmoQBwT5KwFYjXBJ9ymZfKCUU+5rmTRykKAFvH5Qn/ZCds3CEAFS9OC9M/jkl0X2bA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.68.0", - "@typescript-eslint/tsconfig-utils": "8.68.0", - "@typescript-eslint/types": "8.68.0", - "@typescript-eslint/visitor-keys": "8.68.0", + "@typescript-eslint/project-service": "8.70.0", + "@typescript-eslint/tsconfig-utils": "8.70.0", + "@typescript-eslint/types": "8.70.0", + "@typescript-eslint/visitor-keys": "8.70.0", "debug": "^4.4.3", "minimatch": "^10.2.2", "semver": "^7.7.3", @@ -2278,56 +2201,17 @@ "typescript": ">=4.8.4 <6.1.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", - "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.8" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@typescript-eslint/utils": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.68.0.tgz", - "integrity": "sha512-PB5gJMMOg0Q5P1tsgWtEAqQacJXq0qEqRHDX/YJ4FaTMLfZPpHB3gjl2EJuiZyPABxmj4ZQYiY9m1bdAJ5y7tQ==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.70.0.tgz", + "integrity": "sha512-oZmtKJz/4fufZ2p3+Cn3ijEojcdfR+1zYDH2xKYrEly0dR/Q/1xUPRCOlKGxod78nWlU2UnDe09GZ3TaknBFGA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.68.0", - "@typescript-eslint/types": "8.68.0", - "@typescript-eslint/typescript-estree": "8.68.0" + "@typescript-eslint/scope-manager": "8.70.0", + "@typescript-eslint/types": "8.70.0", + "@typescript-eslint/typescript-estree": "8.70.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2342,13 +2226,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.68.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.68.0.tgz", - "integrity": "sha512-YR65gGdGvTUAWLldC3xLOvOzamdGzB4A5/N8rehEaHs3Zvoe39BhgY+u0SPch1OvrVTfLcc55wsSgK2NcnTS/A==", + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.70.0.tgz", + "integrity": "sha512-BoC8PiO4Hkdo0TVJh9Ntxr5MxPDI7/oFsrygN5ADelFSeXG/qgNuucIGA+L5Z6JpPTE/uRfcTWtscjbUaufepQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.68.0", + "@typescript-eslint/types": "8.70.0", "eslint-visitor-keys": "^5.0.0" }, "engines": { @@ -2605,14 +2489,26 @@ "license": "BSD-2-Clause" }, "node_modules/brace-expansion": { - "version": "1.1.18", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", - "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", + "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/brace-expansion/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/braces": { @@ -2685,16 +2581,6 @@ "node": ">= 0.8" } }, - "node_modules/callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/camelcase": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", @@ -2979,13 +2865,6 @@ "node": ">= 12.0.0" } }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true, - "license": "MIT" - }, "node_modules/core-js-compat": { "version": "3.50.0", "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.50.0.tgz", @@ -3381,45 +3260,6 @@ "eslint": "^8.0.0 || ^9.0.0 || ^10.0.0" } }, - "node_modules/eslint-plugin-sonarjs/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/eslint-plugin-sonarjs/node_modules/brace-expansion": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", - "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/eslint-plugin-sonarjs/node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.8" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/eslint-plugin-unicorn": { "version": "75.0.0", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-75.0.0.tgz", @@ -3503,29 +3343,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/eslint/node_modules/brace-expansion": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", - "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, "node_modules/eslint/node_modules/eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", @@ -3557,53 +3374,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.8" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/espree": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", - "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "acorn": "^8.15.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.2.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", - "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, "node_modules/esquery": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", @@ -3956,9 +3726,9 @@ } }, "node_modules/glob/node_modules/brace-expansion": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.4.tgz", - "integrity": "sha512-hGfVzPxthbf3+2yjg/RBs60cB0FhqBS/zvdV/4wn4/BmN0bNMMHPc4V/BbFieqf1TKAGGAHnY4eSjajCl0f2Xg==", + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", + "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", "dev": true, "license": "MIT", "dependencies": { @@ -4057,26 +3827,16 @@ } }, "node_modules/hosted-git-info": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.1.3.tgz", - "integrity": "sha512-HVJyzUrLIL1c0QmviVh5E8VGyUS7xCFPS6yydaVd1UegW+ibV/CohqTH9MkOLDp5o+rb82DMo77PTuc9F/8GKw==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-9.0.3.tgz", + "integrity": "sha512-Hc+ghLoSt6QaYZUv0WBiIvmMDZuZZ7oaDvdH8MbfOO4lOsxdXLEvuC6ePoGs9H1X9oCLyq6+NVN0MKqD+ydxyg==", "dev": true, "license": "ISC", "dependencies": { - "lru-cache": "^7.5.1" + "lru-cache": "^11.1.0" }, "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - }, - "node_modules/hosted-git-info/node_modules/lru-cache": { - "version": "7.18.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", - "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=12" + "node": "^20.17.0 || >=22.9.0" } }, "node_modules/html-entities": { @@ -4171,23 +3931,6 @@ "node": ">= 4" } }, - "node_modules/import-fresh": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", - "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "parent-module": "^1.0.0", - "resolve-from": "^4.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -4274,13 +4017,13 @@ } }, "node_modules/is-core-module": { - "version": "2.16.2", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", - "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==", + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.17.0.tgz", + "integrity": "sha512-J/vG0zBCbIKOQFfufSwyXdMrsohyJIUNkrnmo6WZGzoM7tr/lsbfW5b2BvisL6zsyMzK9UxV9L6c7AoFbyXHOA==", "dev": true, "license": "MIT", "dependencies": { - "hasown": "^2.0.3" + "hasown": "^2.0.4" }, "engines": { "node": ">= 0.4" @@ -4751,16 +4494,19 @@ } }, "node_modules/minimatch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", - "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", + "version": "10.2.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", + "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", "dev": true, - "license": "ISC", + "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^1.1.7" + "brace-expansion": "^5.0.8" }, "engines": { - "node": "*" + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/minipass": { @@ -4943,6 +4689,29 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/normalize-package-data/node_modules/hosted-git-info": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.1.3.tgz", + "integrity": "sha512-HVJyzUrLIL1c0QmviVh5E8VGyUS7xCFPS6yydaVd1UegW+ibV/CohqTH9MkOLDp5o+rb82DMo77PTuc9F/8GKw==", + "dev": true, + "license": "ISC", + "dependencies": { + "lru-cache": "^7.5.1" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/normalize-package-data/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=12" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -5074,19 +4843,6 @@ "license": "(MIT AND Zlib)", "optional": true }, - "node_modules/parent-module": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", - "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, - "license": "MIT", - "dependencies": { - "callsites": "^3.0.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/parse-imports-exports": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/parse-imports-exports/-/parse-imports-exports-0.2.4.tgz", @@ -5436,19 +5192,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/read-pkg/node_modules/hosted-git-info": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-9.0.3.tgz", - "integrity": "sha512-Hc+ghLoSt6QaYZUv0WBiIvmMDZuZZ7oaDvdH8MbfOO4lOsxdXLEvuC6ePoGs9H1X9oCLyq6+NVN0MKqD+ydxyg==", - "dev": true, - "license": "ISC", - "dependencies": { - "lru-cache": "^11.1.0" - }, - "engines": { - "node": "^20.17.0 || >=22.9.0" - } - }, "node_modules/read-pkg/node_modules/normalize-package-data": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-8.0.0.tgz", @@ -5573,16 +5316,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/resolve-from": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, "node_modules/resolve-pkg-maps": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", @@ -6089,19 +5822,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/strtok3": { "version": "10.3.5", "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.3.5.tgz", @@ -6563,45 +6283,6 @@ "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" } }, - "node_modules/typedoc/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/typedoc/node_modules/brace-expansion": { - "version": "5.0.9", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", - "integrity": "sha512-ScQ4IuvIEF1TMlP7Zt+vjJ//9zlPb2SDcxWxM3bk8s6t6GGdJ7KO1dCcTidOPJKePW30LE/2cT7wCyPho9/Wxg==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, - "node_modules/typedoc/node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.8" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", @@ -6616,6 +6297,30 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "8.70.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.70.0.tgz", + "integrity": "sha512-P/W5cz70/cQAuKfY3xwQMWWTV7BvJ0mAQmi+9mBcsVPaBUpd6Ohpa+fECv9rBFrQcig86jAiNBFNWUqnTjr4pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/eslint-plugin": "8.70.0", + "@typescript-eslint/parser": "8.70.0", + "@typescript-eslint/typescript-estree": "8.70.0", + "@typescript-eslint/utils": "8.70.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, "node_modules/uc.micro": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", diff --git a/package.json b/package.json index d0a822b1..42e90808 100644 --- a/package.json +++ b/package.json @@ -73,12 +73,10 @@ }, "devDependencies": { "@arethetypeswrong/cli": "^0.18.5", - "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^10.0.1", "@secretlint/secretlint-rule-preset-recommend": "^13.0.4", "@types/node": "^20.19.37", "@types/tmp": "^0.2.6", - "@typescript-eslint/eslint-plugin": "^8.57.0", "@typescript-eslint/parser": "^8.58.1", "eslint": "^10.8.1", "eslint-plugin-jsdoc": "^62.7.1", @@ -94,7 +92,8 @@ "tslib": "^2.8.1", "tsx": "^4.21.0", "typedoc": "^0.28.18", - "typescript": "^5.9.3" + "typescript": "^5.9.3", + "typescript-eslint": "^8.70.0" }, "keywords": [ "typescript", diff --git a/src/geometry/boundingBoxUtils.ts b/src/geometry/boundingBoxUtils.ts index 30bead8f..4a8d320c 100644 --- a/src/geometry/boundingBoxUtils.ts +++ b/src/geometry/boundingBoxUtils.ts @@ -2,14 +2,6 @@ import { BoundingBox } from "./boundingBox.js"; import { BBox } from "./bbox.js"; import { Polygon } from "./polygon.js"; -/** - * Given a Polygon, calculate a polygon that encompasses all points. - */ -export function getBoundingBox(polygon: Polygon): BoundingBox { - const bbox = getBbox(polygon); - return getBoundingBoxFromBBox(bbox); -} - /** * Given a BBox, generate the associated bounding box. */ @@ -61,3 +53,11 @@ export function getBBoxForPolygons(polygons: Polygon[]): BBox { Math.max(...allY), ); } + +/** + * Given a Polygon, calculate a polygon that encompasses all points. + */ +export function getBoundingBox(polygon: Polygon): BoundingBox { + const bbox = getBbox(polygon); + return getBoundingBoxFromBBox(bbox); +} diff --git a/src/image/imageExtractor.ts b/src/image/imageExtractor.ts index df4690b7..5dee9c76 100644 --- a/src/image/imageExtractor.ts +++ b/src/image/imageExtractor.ts @@ -60,7 +60,7 @@ export async function extractImagesFromPolygon( * Helper function to handle the drawing math and orientation. */ function drawOrientedPage( - pdfLib: any, + currentPdfLib: any, samplePage: pdfLibTypes.PDFPage, cropped: pdfLibTypes.PDFEmbeddedPage, orientation: number, @@ -80,7 +80,7 @@ function drawOrientedPage( y: finalHeight, width: scaledWidth, height: scaledHeight, - rotate: pdfLib.degrees(270), + rotate: currentPdfLib.degrees(270), }); } else if (orientation === 180) { samplePage.drawPage(cropped, { @@ -88,7 +88,7 @@ function drawOrientedPage( y: finalHeight, width: scaledWidth, height: scaledHeight, - rotate: pdfLib.degrees(180), + rotate: currentPdfLib.degrees(180), }); } else if (orientation === 270) { samplePage.drawPage(cropped, { @@ -96,7 +96,7 @@ function drawOrientedPage( y: 0, width: scaledWidth, height: scaledHeight, - rotate: pdfLib.degrees(90), + rotate: currentPdfLib.degrees(90), }); } } @@ -114,7 +114,7 @@ export async function extractFromPage( asImage: boolean = false, quality?: number, ) { - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); const { width, height } = pdfPage.getSize(); const extractedElements: Uint8Array[] = []; if (quality !== undefined) { @@ -135,7 +135,7 @@ export async function extractFromPage( for (const origPolygon of polygons) { logger.debug(`Extracting image with polygon: ${origPolygon.toString()}`); - const tempPdf = await pdfLib.PDFDocument.create(); + const tempPdf = await currentPdfLib.PDFDocument.create(); const [copiedPage] = await tempPdf.copyPages(sourceDoc, [pageIndex]); const polygon = adjustForRotation(origPolygon, orientation); @@ -144,8 +144,8 @@ export async function extractFromPage( const minY = getMinMaxY(polygon).min; const maxY = getMinMaxY(polygon).max; - const newWidth = width * (maxX - minX); - const newHeight = height * (maxY - minY); + const imgWidth = width * (maxX - minX); + const imgHeight = height * (maxY - minY); const cropped = await tempPdf.embedPage(copiedPage, { left: minX * width, @@ -155,23 +155,23 @@ export async function extractFromPage( }); const isVertical = orientation === 90 || orientation === 270; - const finalWidth = (isVertical ? newHeight : newWidth) * qualityScale; - const finalHeight = (isVertical ? newWidth : newHeight) * qualityScale; + const finalWidth = (isVertical ? imgHeight : imgWidth) * qualityScale; + const finalHeight = (isVertical ? imgWidth : imgHeight) * qualityScale; const samplePage = tempPdf.addPage([finalWidth, finalHeight]); samplePage.drawRectangle({ - x: 0, y: 0, width: finalWidth, height: finalHeight, color: pdfLib.rgb(1, 1, 1), + x: 0, y: 0, width: finalWidth, height: finalHeight, color: currentPdfLib.rgb(1, 1, 1), }); drawOrientedPage( - pdfLib, + currentPdfLib, samplePage, cropped, orientation, finalWidth, finalHeight, - newWidth * qualityScale, - newHeight * qualityScale + imgWidth * qualityScale, + imgHeight * qualityScale ); const pdfBuffer = Buffer.from(await tempPdf.save()); diff --git a/src/pdf/pdfCompressor.ts b/src/pdf/pdfCompressor.ts index 37919dcd..8e5574b1 100644 --- a/src/pdf/pdfCompressor.ts +++ b/src/pdf/pdfCompressor.ts @@ -127,8 +127,8 @@ async function compressPagesWithQuality( disableSourceText: boolean, extractedText: ExtractedPdfInfo | null ): Promise { - const pdfLib = await getPdfLib(); - const pdfDoc = await pdfLib.PDFDocument.load(pdfData, { + const currentPdfLib = await getPdfLib(); + const pdfDoc = await currentPdfLib.PDFDocument.load(pdfData, { ignoreEncryption: true, password: "" }); @@ -185,13 +185,13 @@ function isCompressionSuccessful( * @returns A Promise resolving to the new PDF as a Buffer. */ async function createNewPdfFromCompressedPages(compressedPages: Buffer[]): Promise { - const pdfLib = await getPdfLib(); - const newPdfDoc = await pdfLib.PDFDocument.create(); + const currentPdfLib = await getPdfLib(); + const pdfDocument = await currentPdfLib.PDFDocument.create(); for (const compressedPage of compressedPages) { - const image = await newPdfDoc.embedJpg(compressedPage); - const newPage = newPdfDoc.addPage([image.width, image.height]); - newPage.drawImage(image, { + const image = await pdfDocument.embedJpg(compressedPage); + const pdfPage = pdfDocument.addPage([image.width, image.height]); + pdfPage.drawImage(image, { x: 0, y: 0, width: image.width, @@ -199,7 +199,7 @@ async function createNewPdfFromCompressedPages(compressedPages: Buffer[]): Promi }); } - const compressedPdfBytes = await newPdfDoc.save(); + const compressedPdfBytes = await pdfDocument.save(); return Buffer.from(compressedPdfBytes); } @@ -215,14 +215,14 @@ async function addTextToPdfPage( if (textInfo === null) { return; } - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); for (const textPages of textInfo.pages) { for (const textPage of textPages.content) { page.drawText(textPage.str, { x: textPage.x, y: textPage.y, size: textPage.height, - color: pdfLib.rgb(0, 0, 0), + color: currentPdfLib.rgb(0, 0, 0), font: await getFontFromName(textPage.fontName) }); } @@ -234,15 +234,15 @@ async function addTextToPdfPage( * @param fontName The name of the font to get. */ async function getFontFromName(fontName: string): Promise { - const pdfLib = await getPdfLib(); - const pdfDoc = await pdfLib.PDFDocument.create(); + const currentPdfLib = await getPdfLib(); + const pdfDoc = await currentPdfLib.PDFDocument.create(); let font: pdfLibTypes.PDFFont; - const standardFontValues = Object.values(pdfLib.StandardFonts) as string[]; + const standardFontValues = Object.values(currentPdfLib.StandardFonts) as string[]; if (standardFontValues.includes(fontName)) { font = await pdfDoc.embedFont(fontName); } else { - font = await pdfDoc.embedFont(pdfLib.StandardFonts.Helvetica); + font = await pdfDoc.embedFont(currentPdfLib.StandardFonts.Helvetica); } return font; diff --git a/src/pdf/pdfOperation.ts b/src/pdf/pdfOperation.ts index 320c2ad6..12bfdfe5 100644 --- a/src/pdf/pdfOperation.ts +++ b/src/pdf/pdfOperation.ts @@ -46,14 +46,13 @@ export async function extractPages( file: Buffer, pageOptions: PageOptions ): Promise { - const pdfLib = await getPdfLib(); - const currentPdf = await pdfLib.PDFDocument.load(file, { + const currentPdfLib = await getPdfLib(); + const currentPdf = await currentPdfLib.PDFDocument.load(file, { ignoreEncryption: true, password: "" }); - const newPdf = await pdfLib.PDFDocument.create(); - + const pdfDocument = await currentPdfLib.PDFDocument.create(); const pageCount = currentPdf.getPageCount(); if (pageCount < pageOptions.onMinPages) { @@ -92,23 +91,23 @@ export async function extractPages( } if (pageOptions.operation === PageOptionsOperation.KeepOnly) { - const keptPages = await newPdf.copyPages(currentPdf, pageIndexes); + const keptPages = await pdfDocument.copyPages(currentPdf, pageIndexes); keptPages.forEach((keptPage: pdfLibTypes.PDFPage) => { - newPdf.addPage(keptPage); + pdfDocument.addPage(keptPage); }); } else if (pageOptions.operation === PageOptionsOperation.Remove) { const pagesToKeep = currentPdf .getPageIndices() .filter((v:number) => !pageIndexes.includes(v)); - const keptPages = await newPdf.copyPages(currentPdf, pagesToKeep); + const keptPages = await pdfDocument.copyPages(currentPdf, pagesToKeep); keptPages.forEach((keptPage: pdfLibTypes.PDFPage) => { - newPdf.addPage(keptPage); + pdfDocument.addPage(keptPage); }); } else { throw new Error(`The operation ${pageOptions.operation} is not available.`); } - const sumRemovedPages = pageCount - newPdf.getPageCount(); - const fileBuffer = Buffer.from(await newPdf.save()); + const sumRemovedPages = pageCount - pdfDocument.getPageCount(); + const fileBuffer = Buffer.from(await pdfDocument.save()); return { file: fileBuffer, totalPagesRemoved: sumRemovedPages }; } @@ -118,8 +117,8 @@ export async function extractPages( * @returns the number of pages in the file. */ export async function countPages(file: Buffer): Promise { - const pdfLib = await getPdfLib(); - const currentPdf = await pdfLib.PDFDocument.load(file, { + const currentPdfLib = await getPdfLib(); + const currentPdf = await currentPdfLib.PDFDocument.load(file, { ignoreEncryption: true, password: "" }); @@ -131,7 +130,7 @@ export async function countPages(file: Buffer): Promise { * @param inputSource The input source to create a PDF from. */ export async function createPdfFromInputSource(inputSource: LocalInputSource) { - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); let pdfDoc: pdfLibTypes.PDFDocument; if (!["image/jpeg", "image/jpg", "image/png", "application/pdf"].includes(inputSource.mimeType)) { throw new MindeeInputSourceError( @@ -140,12 +139,12 @@ export async function createPdfFromInputSource(inputSource: LocalInputSource) { '" Currently supported types are .png, .jpg and .pdf' ); } else if (inputSource.isPdf()) { - pdfDoc = await pdfLib.PDFDocument.load(inputSource.fileObject, { + pdfDoc = await currentPdfLib.PDFDocument.load(inputSource.fileObject, { ignoreEncryption: true, password: "" }); } else { - pdfDoc = await pdfLib.PDFDocument.create(); + pdfDoc = await currentPdfLib.PDFDocument.create(); let image: pdfLibTypes.PDFImage; if (inputSource.mimeType === "image/png") { image = await pdfDoc.embedPng(inputSource.fileObject); diff --git a/src/v1/client.ts b/src/v1/client.ts index 10a7628f..fce530d6 100644 --- a/src/v1/client.ts +++ b/src/v1/client.ts @@ -359,21 +359,21 @@ export class Client { const minDelaySec = 1; const minInitialDelay = 1; const minRetries = 2; - const newAsyncParams = { ...asyncParams }; - newAsyncParams.delaySec ??= 1.5; - newAsyncParams.initialDelaySec ??= 2; - newAsyncParams.maxRetries ??= 80; + const asyncParamsInstance = { ...asyncParams }; + asyncParamsInstance.delaySec ??= 1.5; + asyncParamsInstance.initialDelaySec ??= 2; + asyncParamsInstance.maxRetries ??= 80; - if (newAsyncParams.delaySec < minDelaySec) { + if (asyncParamsInstance.delaySec < minDelaySec) { throw Error(`Cannot set auto-parsing delay to less than ${minDelaySec} second(s).`); } - if (newAsyncParams.initialDelaySec < minInitialDelay) { + if (asyncParamsInstance.initialDelaySec < minInitialDelay) { throw Error(`Cannot set initial parsing delay to less than ${minInitialDelay} second(s).`); } - if (newAsyncParams.maxRetries < minRetries) { + if (asyncParamsInstance.maxRetries < minRetries) { throw Error(`Cannot set retry to less than ${minRetries}.`); } - return newAsyncParams as AsyncOptions; + return asyncParamsInstance as AsyncOptions; } /** diff --git a/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.ts b/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.ts index 8c6dc8ba..1e3b6e21 100644 --- a/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.ts +++ b/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.ts @@ -30,13 +30,13 @@ async function getPdfLib(): Promise { async function splitPdf( pdfDoc: pdfLibTypes.PDFDocument, invoicePageGroups: number[][]): Promise { - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); if (invoicePageGroups.length === 0) { return []; } const generatedPdfs: ExtractedInvoiceSplitterImage[] = []; for (let i = 0; i < invoicePageGroups.length; i++) { - const subdocument = await pdfLib.PDFDocument.create(); + const subdocument = await currentPdfLib.PDFDocument.create(); const fullIndexes = []; for (let j = invoicePageGroups[i][0]; j <= invoicePageGroups[i][invoicePageGroups[i].length - 1]; j++) { fullIndexes.push(j); @@ -61,7 +61,7 @@ async function splitPdf( * @returns PDF document. */ async function getPdfDoc(inputFile: LocalInputSource): Promise { - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); await inputFile.init(); if (!inputFile.isPdf()) { throw new MindeeInputSourceError( @@ -69,7 +69,7 @@ async function getPdfDoc(inputFile: LocalInputSource): Promise { - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); const images: ExtractedMultiReceiptImage[] = []; if (!inference.prediction.receipts) { throw new MindeeError("No possible receipts candidates found for MultiReceipts extraction."); @@ -66,7 +66,7 @@ export async function extractReceipts( const pdfDoc = await createPdfFromInputSource(inputFile); for (let pageId = 0; pageId < pdfDoc.getPageCount(); pageId++) { const page = pdfDoc.getPage(pageId); - page.setRotation(pdfLib.degrees(inference.pages[pageId].orientation?.value ?? 0)); + page.setRotation(currentPdfLib.degrees(inference.pages[pageId].orientation?.value ?? 0)); const receiptPositions = inference.pages[pageId].prediction.receipts.map( (receipt: PositionField) => receipt.boundingBox ); diff --git a/src/v1/parsing/generated/generatedObject.ts b/src/v1/parsing/generated/generatedObject.ts index 83ec6f56..c65318da 100644 --- a/src/v1/parsing/generated/generatedObject.ts +++ b/src/v1/parsing/generated/generatedObject.ts @@ -135,7 +135,7 @@ export class GeneratedObjectField { * @param strDict input dictionary to check. */ export function isGeneratedObject(strDict: StringDict): boolean { - const commonKeys = [ + const commonKeys = new Set([ "value", "polygon", "rectangle", @@ -144,10 +144,10 @@ export function isGeneratedObject(strDict: StringDict): boolean { "quadrangle", "values", "raw_value", - ]; + ]); for (const key in strDict) { - if (Object.prototype.hasOwnProperty.call(strDict, key) && !commonKeys.includes(key)) { + if (Object.prototype.hasOwnProperty.call(strDict, key) && !commonKeys.has(key)) { return true; } } diff --git a/tests/pdf/pdfOperation.spec.ts b/tests/pdf/pdfOperation.spec.ts index 365a7cfc..558b1c1b 100644 --- a/tests/pdf/pdfOperation.spec.ts +++ b/tests/pdf/pdfOperation.spec.ts @@ -144,9 +144,9 @@ describe("Test PDF operation #OptionalDepsRequired", { skip: !hasOptionals }, () operation: PageOptionsOperation.KeepOnly, onMinPages: 0, }; - const newPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - assert.strictEqual(newPdf.totalPagesRemoved, 9); - assert.strictEqual(await pdf.countPages(newPdf.file), 3); + const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); + assert.strictEqual(splitPdf.totalPagesRemoved, 9); + assert.strictEqual(await pdf.countPages(splitPdf.file), 3); // This is how the length of the word is set in the // raw PDF file. @@ -157,7 +157,7 @@ describe("Test PDF operation #OptionalDepsRequired", { skip: !hasOptionals }, () "utf8" ); - inputSource.fileObject = Buffer.from(newPdf.file); + inputSource.fileObject = Buffer.from(splitPdf.file); const expectedLengths = expectedResult.match(lengthRE); const inputDocLengths = inputSource.fileObject.toString("utf8").match(lengthRE) || []; diff --git a/tests/v2/fileOperations/crop.spec.ts b/tests/v2/fileOperations/crop.spec.ts index 8237b082..55081a4d 100644 --- a/tests/v2/fileOperations/crop.spec.ts +++ b/tests/v2/fileOperations/crop.spec.ts @@ -43,9 +43,9 @@ async function loadV2Crop(resourcePath: string): Promise { */ async function getFileDimensions(buffer: Buffer, sharpInstance: any) { const isPdf = buffer.subarray(0, 4).toString("ascii") === "%PDF"; - const pdfLib = await getPdfLib(); + const currentPdfLib = await getPdfLib(); if (isPdf) { - const pdfDoc = await pdfLib.PDFDocument.load(buffer); + const pdfDoc = await currentPdfLib.PDFDocument.load(buffer); const page = pdfDoc.getPage(0); const { width, height } = page.getSize(); diff --git a/tsconfig.json b/tsconfig.json index 901284d8..9c53af32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "baseUrl": "./", + "rootDir": "./", "declaration": true, "importHelpers": false, "esModuleInterop": true, @@ -15,14 +16,19 @@ "outDir": "dist", "paths": { "@/*": [ - "src/*" + "./src/*" ] }, + "types": [ + "node" + ], "resolveJsonModule": true, "skipLibCheck": false, "sourceMap": false, "strict": true, - "target": "ES2020", + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "target": "ES2020" }, "include": ["./src/**/*", "./bin/**/*"], "exclude": ["./node_modules/", "./dist/", "./tests/"]