diff --git a/docs/code_samples/v2_classification.txt b/docs/code_samples/v2_classification.txt index b9b3650a..c2b96050 100644 --- a/docs/code_samples/v2_classification.txt +++ b/docs/code_samples/v2_classification.txt @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client( { apiKey: apiKey } ); -// Set product parameters -const params = { +// Set Classification parameters +const modelParams = { modelId: modelId, }; @@ -25,7 +25,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath }); const response = await mindeeClient.enqueueAndGetResult( mindee.product.Classification, inputSource, - params, + modelParams, ); // print a string summary diff --git a/docs/code_samples/v2_crop.txt b/docs/code_samples/v2_crop.txt index aa81a02d..4d10433a 100644 --- a/docs/code_samples/v2_crop.txt +++ b/docs/code_samples/v2_crop.txt @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client( { apiKey: apiKey } ); -// Set product parameters -const productParams = { +// Set Crop parameters +const modelParams = { modelId: modelId, }; @@ -25,7 +25,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath }); const response = await mindeeClient.enqueueAndGetResult( mindee.product.Crop, inputSource, - productParams, + modelParams, ); // print a string summary diff --git a/docs/code_samples/v2_extraction.txt b/docs/code_samples/v2_extraction.txt index 9cc50028..0324cfe9 100644 --- a/docs/code_samples/v2_extraction.txt +++ b/docs/code_samples/v2_extraction.txt @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client( { apiKey: apiKey } ); -// Set product parameters -const productParams = { +// Set Extraction parameters +const modelParams = { modelId: modelId, // Options: set to `true` or `false` to override defaults @@ -37,7 +37,7 @@ const inputSource = new mindee.PathInput({ inputPath: filePath }); const response = await mindeeClient.enqueueAndGetResult( mindee.product.Extraction, inputSource, - productParams, + modelParams, ); // print a string summary diff --git a/docs/code_samples/v2_ocr.txt b/docs/code_samples/v2_ocr.txt index 01ec2f03..8d25f2a0 100644 --- a/docs/code_samples/v2_ocr.txt +++ b/docs/code_samples/v2_ocr.txt @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client( { apiKey: apiKey } ); -// Set product parameters -const productParams = { +// Set Raw OCR parameters +const modelParams = { modelId: modelId, }; @@ -25,11 +25,11 @@ const inputSource = new mindee.PathInput({ inputPath: filePath }); const response = await mindeeClient.enqueueAndGetResult( mindee.product.Ocr, inputSource, - productParams, + modelParams, ); // print a string summary console.log(response.inference.toString()); // Access the result OCR pages -const crops = response.inference.result.pages; +const pages = response.inference.result.pages; diff --git a/docs/code_samples/v2_split.txt b/docs/code_samples/v2_split.txt index 3c63ebb6..8592027f 100644 --- a/docs/code_samples/v2_split.txt +++ b/docs/code_samples/v2_split.txt @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client( { apiKey: apiKey } ); -// Set product parameters -const productParams = { +// Set Split parameters +const modelParams = { modelId: modelId, }; @@ -25,11 +25,11 @@ const inputSource = new mindee.PathInput({ inputPath: filePath }); const response = await mindeeClient.enqueueAndGetResult( mindee.product.Split, inputSource, - productParams, + modelParams, ); // print a string summary console.log(response.inference.toString()); // Access the result splits -const crops = response.inference.result.splits; +const splits = response.inference.result.splits; diff --git a/eslint.config.mjs b/eslint.config.mjs index c1716631..be734763 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -29,6 +29,7 @@ export default tseslint.config( parser: tseslint.parser, }, rules: { + // Unicorn rules "unicorn/import-style": "error", "unicorn/prefer-node-protocol": "error", "unicorn/text-encoding-identifier-case": "error", @@ -40,8 +41,10 @@ export default tseslint.config( "unicorn/prefer-set-has": "error", "unicorn/no-lonely-if": "error", "unicorn/prefer-array-some": "error", + "unicorn/numeric-separators-style": "error", + "unicorn/prefer-string-replace-all": "error", - semi: ["error"], + // jsdoc rules "jsdoc/require-asterisk-prefix": "error", "jsdoc/check-alignment": "error", "jsdoc/check-param-names": "error", @@ -49,14 +52,14 @@ export default tseslint.config( "jsdoc/no-undefined-types": "error", "jsdoc/require-jsdoc": "error", + // typescript-eslint rules + // we disable duplicates and always prefer typescript linter "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", @@ -64,16 +67,18 @@ export default tseslint.config( "no-shadow": "off", "@typescript-eslint/no-shadow": "error", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-inferrable-types": "off", + "@typescript-eslint/ban-ts-comment": "error", + "@typescript-eslint/naming-convention": "error", - "@/object-curly-spacing": ["error", "always"], + "@typescript-eslint/no-explicit-any": "off", // necessary evil for now + "@typescript-eslint/no-inferrable-types": "off", // explicitness can help legibility + // base rules + "@/object-curly-spacing": ["error", "always"], quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: false, }], - camelcase: "error", "comma-dangle": ["error", { "arrays": "only-multiline", @@ -84,13 +89,10 @@ export default tseslint.config( }], eqeqeq: "error", "no-else-return": "error", - + semi: "error", "no-eval": "error", "no-unexpected-multiline": "error", "eol-last": "error", - "preserve-caught-error": "off", - "security/detect-non-literal-fs-filename": "off", - "security/detect-object-injection": "off", "no-restricted-imports": ["error", { "patterns": [{ "group": ["../*"], @@ -98,6 +100,10 @@ export default tseslint.config( }], }], + "preserve-caught-error": "off", // incompatible with ES2021 + "security/detect-non-literal-fs-filename": "off", + "security/detect-object-injection": "off", + indent: ["error", 2], "max-len": ["error", { code: 120, diff --git a/src/input/urlInput.ts b/src/input/urlInput.ts index 7ea03146..ca703c65 100644 --- a/src/input/urlInput.ts +++ b/src/input/urlInput.ts @@ -123,7 +123,7 @@ export class UrlInput extends InputSource { private static generateFileName(extension = ".tmp"): string { const randomString = randomBytes(4).toString("hex"); - const timestamp = new Date().toISOString().replace(/[-:]/g, "").split(".")[0]; + const timestamp = new Date().toISOString().replaceAll(/[-:]/g, "").split(".")[0]; return `mindee_temp_${timestamp}_${randomString}${extension}`; } diff --git a/src/parsing/baseLocalResponse.ts b/src/parsing/baseLocalResponse.ts index 09c75baf..5ae28f59 100644 --- a/src/parsing/baseLocalResponse.ts +++ b/src/parsing/baseLocalResponse.ts @@ -52,7 +52,7 @@ export abstract class BaseLocalResponse { fileContents = this.inputHandle; } this.fileBytes = Buffer.from( - fileContents.replace(/\r/g, "").replace(/\n/g, ""), + fileContents.replaceAll("\r", "").replaceAll("\n", ""), "utf8" ); } else { diff --git a/src/v1/parsing/common/inference.ts b/src/v1/parsing/common/inference.ts index e61b39e4..ed6dd37a 100644 --- a/src/v1/parsing/common/inference.ts +++ b/src/v1/parsing/common/inference.ts @@ -109,7 +109,7 @@ ${this.prediction.toString().length === 0 ? "" : this.prediction.toString() + "\ */ static cleanOutString(outStr: string): string { const lines = / \n/gm; - return outStr.replace(lines, "\n"); + return outStr.replaceAll(lines, "\n"); } } diff --git a/src/v1/parsing/common/summaryHelper.ts b/src/v1/parsing/common/summaryHelper.ts index f511190e..da7f21a5 100644 --- a/src/v1/parsing/common/summaryHelper.ts +++ b/src/v1/parsing/common/summaryHelper.ts @@ -4,7 +4,7 @@ */ export function cleanOutString(outStr: string): string { const lines = / \n/gm; - return outStr.replace(lines, "\n"); + return outStr.replaceAll(lines, "\n"); } /** @@ -28,9 +28,9 @@ export function lineSeparator(columnSizes: number[], separator: string) { */ export function cleanSpecialChars(outStr: string) { return outStr - .replace(/\n/g, "\\n") - .replace(/\r/g, "\\r") - .replace(/\t/g, "\\t"); + .replaceAll("\n", "\\n") + .replaceAll("\r", "\\r") + .replaceAll("\t", "\\t"); } /** diff --git a/tests/input/sources.spec.ts b/tests/input/sources.spec.ts index 3ca3f3df..54a6ed29 100644 --- a/tests/input/sources.spec.ts +++ b/tests/input/sources.spec.ts @@ -45,7 +45,7 @@ describe("Input Sources - load different types of input", () => { // of the input file. const expectedString = inputSource.fileObject .toString("base64") - .replace(/(.{76})/gm, "$1\n"); + .replaceAll(/(.{76})/gm, "$1\n"); assert.deepStrictEqual(expectedString, b64String); }); diff --git a/tests/v1/extraction/invoiceSplitter.integration.ts b/tests/v1/extraction/invoiceSplitter.integration.ts index 5da99aca..ca25e96a 100644 --- a/tests/v1/extraction/invoiceSplitter.integration.ts +++ b/tests/v1/extraction/invoiceSplitter.integration.ts @@ -11,7 +11,7 @@ import { hasAllOptionalDependencies } from "../../helpers/optionalDeps.js"; const hasOptionals = hasAllOptionalDependencies(); describe("MindeeV1 - Integration - InvoiceSplitterV1 #OptionalDepsRequired", - { timeout: 80000, skip: !hasOptionals }, () => { + { timeout: 80_000, skip: !hasOptionals }, () => { let client: mindee.v1.Client; beforeEach(() => { diff --git a/tests/v1/extraction/invoiceSplitter.spec.ts b/tests/v1/extraction/invoiceSplitter.spec.ts index ba1d14a4..8b0e73cc 100644 --- a/tests/v1/extraction/invoiceSplitter.spec.ts +++ b/tests/v1/extraction/invoiceSplitter.spec.ts @@ -29,8 +29,8 @@ describe("MindeeV1 - Invoice Splitter Extraction #OptionalDepsRequired", { skip: assert.strictEqual(extractedInvoices[2].pageIdMin, 4); assert.strictEqual(extractedInvoices[2].pageIdMax, 4); for (const extractedInvoice of extractedInvoices) { - assert.ok(Buffer.byteLength(extractedInvoice.asInputSource().fileObject) < 10485760); - assert.ok(Buffer.byteLength(extractedInvoice.asInputSource().fileObject) > 100000); + assert.ok(Buffer.byteLength(extractedInvoice.asInputSource().fileObject) < 10_485_760); + assert.ok(Buffer.byteLength(extractedInvoice.asInputSource().fileObject) > 100_000); } }); diff --git a/tests/v1/extraction/multiReceipts.integration.ts b/tests/v1/extraction/multiReceipts.integration.ts index 35ee2699..f9cb89b5 100644 --- a/tests/v1/extraction/multiReceipts.integration.ts +++ b/tests/v1/extraction/multiReceipts.integration.ts @@ -15,7 +15,7 @@ let client: Client; let sourceDoc: LocalInputSource; describe("MindeeV1 - Integration - Multi-Receipt Extraction #OptionalDepsRequired", - { timeout: 80000, skip: !hasOptionals }, () => { + { timeout: 80_000, skip: !hasOptionals }, () => { describe("A Multi-Receipt PDF", () => { before(async () => { sourceDoc = new PathInput({ diff --git a/tests/v1/extraction/multiReceipts.spec.ts b/tests/v1/extraction/multiReceipts.spec.ts index 045b4975..de554c0f 100644 --- a/tests/v1/extraction/multiReceipts.spec.ts +++ b/tests/v1/extraction/multiReceipts.spec.ts @@ -103,8 +103,8 @@ describe("MindeeV1 - Multi-Receipt Extraction #OptionalDepsRequired", { skip: !h for (const extractedReceipt of extractedReceipts) { assert.strictEqual(extractedReceipt.pageId, 0); assert.strictEqual(extractedReceipt.receiptId, i); - assert.ok(Buffer.byteLength(extractedReceipt.asInputSource().fileObject) < 10485760); - assert.ok(Buffer.byteLength(extractedReceipt.asInputSource().fileObject) > 100000); + assert.ok(Buffer.byteLength(extractedReceipt.asInputSource().fileObject) < 10_485_760); + assert.ok(Buffer.byteLength(extractedReceipt.asInputSource().fileObject) > 100_000); i++; } }); @@ -119,13 +119,13 @@ describe("MindeeV1 - Multi-Receipt Extraction #OptionalDepsRequired", { skip: !h const pdfStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.pdf`)); // Arbitrary to assert noticeable discrepancies between OSes - assert.ok(pdfStat.size > 500000); + assert.ok(pdfStat.size > 500_000); const jpgStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.jpg`)); - assert.ok(jpgStat.size > 40000); + assert.ok(jpgStat.size > 40_000); const pngStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.png`)); - assert.ok(pngStat.size > 290000); + assert.ok(pngStat.size > 290_000); i++; } }); diff --git a/tests/v1/extras/extras.integration.ts b/tests/v1/extras/extras.integration.ts index 1bf44673..933cafbc 100644 --- a/tests/v1/extras/extras.integration.ts +++ b/tests/v1/extras/extras.integration.ts @@ -5,7 +5,7 @@ import path from "node:path"; import { V1_PRODUCT_PATH } from "../../index.js"; -describe("MindeeV1 - Integration - Extras", { timeout: 80000 }, () => { +describe("MindeeV1 - Integration - Extras", { timeout: 80_000 }, () => { let client: mindee.v1.Client; beforeEach(() => { diff --git a/tests/v1/input/sources.integration.ts b/tests/v1/input/sources.integration.ts index d3d7a4d9..e10c9c90 100644 --- a/tests/v1/input/sources.integration.ts +++ b/tests/v1/input/sources.integration.ts @@ -8,7 +8,7 @@ import { InvoiceV4 } from "@/v1/product/index.js"; import { V1_PRODUCT_PATH } from "../../index.js"; import { PathInput, Base64Input, BufferInput, BytesInput } from "@/index.js"; -describe("MindeeV1 - Integration - File Input", { timeout: 80000 }, () => { +describe("MindeeV1 - Integration - File Input", { timeout: 80_000 }, () => { let client: Client; let filePath: string; diff --git a/tests/v1/input/urlInputSource.integration.ts b/tests/v1/input/urlInputSource.integration.ts index 5cef6373..d36361f6 100644 --- a/tests/v1/input/urlInputSource.integration.ts +++ b/tests/v1/input/urlInputSource.integration.ts @@ -5,7 +5,7 @@ import { Client } from "@/v1/index.js"; import { InvoiceV4 } from "@/v1/product/index.js"; import { beforeEach } from "node:test"; -describe("MindeeV1 - Integration - URL Input", { timeout: 80000 }, () => { +describe("MindeeV1 - Integration - URL Input", { timeout: 80_000 }, () => { let client: Client; beforeEach(() => { diff --git a/tests/v1/parsing/localResponse.spec.ts b/tests/v1/parsing/localResponse.spec.ts index a39bc0ea..7eb45ea0 100644 --- a/tests/v1/parsing/localResponse.spec.ts +++ b/tests/v1/parsing/localResponse.spec.ts @@ -43,8 +43,8 @@ describe("MindeeV1 - Load Local Response", () => { it("should load a buffer properly.", async () => { const fileStr = (await fs.readFile(filePath, { encoding: "utf8" })) - .replace(/\r/g, "") - .replace(/\n/g, ""); + .replaceAll("\r", "") + .replaceAll("\n", ""); const fileBuffer = Buffer.from(fileStr, "utf8"); const localResponse = new LocalResponse(fileBuffer); await localResponse.init(); diff --git a/tests/v1/workflows/workflow.integration.ts b/tests/v1/workflows/workflow.integration.ts index ef7aee32..c21f6ea7 100644 --- a/tests/v1/workflows/workflow.integration.ts +++ b/tests/v1/workflows/workflow.integration.ts @@ -9,7 +9,7 @@ import { FinancialDocumentV1 } from "@/v1/product/index.js"; import { RAGExtra } from "@/v1/parsing/common/extras/ragExtra.js"; import { V1_PRODUCT_PATH } from "../../index.js"; -describe("MindeeV1 - Integration - Workflow calls", { timeout: 80000 }, () => { +describe("MindeeV1 - Integration - Workflow calls", { timeout: 80_000 }, () => { let client: mindee.v1.Client; let sample: LocalInputSource; let workflowId: string; diff --git a/tests/v2/client/client.integration.ts b/tests/v2/client/client.integration.ts index 6a64f925..9dc47891 100644 --- a/tests/v2/client/client.integration.ts +++ b/tests/v2/client/client.integration.ts @@ -76,7 +76,7 @@ async function waitForResultUrl( ); } -describe("MindeeV2 – Integration - Client", { timeout: 120000 }, () => { +describe("MindeeV2 – Integration - Client", { timeout: 120_000 }, () => { let client: Client; let modelId: string; diff --git a/tests/v2/client/foreignDispatcher.integration.ts b/tests/v2/client/foreignDispatcher.integration.ts index d4a2fe30..fef4f0fc 100644 --- a/tests/v2/client/foreignDispatcher.integration.ts +++ b/tests/v2/client/foreignDispatcher.integration.ts @@ -6,7 +6,7 @@ import assert from "node:assert/strict"; describe( "MindeeV2 – Integration – foreign global dispatcher", - { timeout: 120000 }, + { timeout: 120_000 }, () => { let apiKey: string; let modelId: string; diff --git a/tests/v2/fileOperations/crop.integration.ts b/tests/v2/fileOperations/crop.integration.ts index c5151b9d..efbd176f 100644 --- a/tests/v2/fileOperations/crop.integration.ts +++ b/tests/v2/fileOperations/crop.integration.ts @@ -23,7 +23,7 @@ function checkFindocReturn(findocResponse: ExtractionResponse) { } describe("MindeeV2 - Integration - FileOperation - Crop #OptionalDepsRequired", - { timeout: 120000, skip: !hasOptionals }, () => { + { timeout: 120_000, skip: !hasOptionals }, () => { let client: Client; let cropModelId: string; let findocModelId: string; @@ -84,12 +84,12 @@ describe("MindeeV2 - Integration - FileOperation - Crop #OptionalDepsRequired", fs.writeFileSync(file2Path, extractedImages[1].buffer); const stat1 = fs.statSync(file1Path); - assert.ok(stat1.size >= 3100000); - assert.ok(stat1.size <= 4000000); + assert.ok(stat1.size >= 3_100_000); + assert.ok(stat1.size <= 4_000_000); const stat2 = fs.statSync(file2Path); - assert.ok(stat2.size >= 3200000); - assert.ok(stat2.size <= 4000000); + assert.ok(stat2.size >= 3_200_000); + assert.ok(stat2.size <= 4_000_000); }); it("filled image – crop and extraction must succeed", async () => { diff --git a/tests/v2/fileOperations/split.integration.ts b/tests/v2/fileOperations/split.integration.ts index 91b40cbb..116f0607 100644 --- a/tests/v2/fileOperations/split.integration.ts +++ b/tests/v2/fileOperations/split.integration.ts @@ -27,7 +27,7 @@ function checkFindocReturn(findocResponse: ExtractionResponse) { } describe("MindeeV2 - Integration - Product - Split #OptionalDepsRequired", - { timeout: 120000, skip: !hasOptionals }, () => { + { timeout: 120_000, skip: !hasOptionals }, () => { let client: Client; let splitModelId: string; let findocModelId: string; diff --git a/tests/v2/parsing/localResponse.spec.ts b/tests/v2/parsing/localResponse.spec.ts index dd7d34f2..f7d16a1c 100644 --- a/tests/v2/parsing/localResponse.spec.ts +++ b/tests/v2/parsing/localResponse.spec.ts @@ -44,7 +44,7 @@ async function assertLocalResponse(localResponse: LocalResponse, fileContent: st assert.strictEqual( localResponse.toString(), - fileContent.replace(/[\r\n]/g, "") + fileContent.replaceAll(/[\r\n]/g, "") ); } @@ -55,7 +55,7 @@ describe("MindeeV2 - Load Local Response", () => { }); it("should load a response from a buffer", async () => { - const fileContent = (await fs.readFile(filePath, { encoding: "utf8" })).replace(/\r/g, "").replace(/\n/g, ""); + const fileContent = (await fs.readFile(filePath, { encoding: "utf8" })).replaceAll("\r", "").replaceAll("\n", ""); const fileBuffer = Buffer.from(fileContent, "utf8"); await assertLocalResponse(new LocalResponse(fileBuffer), fileContent); }); diff --git a/tests/v2/product/extraction/ragDocuments.integration.ts b/tests/v2/product/extraction/ragDocuments.integration.ts index c38bcbbc..f0513cd1 100644 --- a/tests/v2/product/extraction/ragDocuments.integration.ts +++ b/tests/v2/product/extraction/ragDocuments.integration.ts @@ -6,7 +6,7 @@ import { Client, PathInput } from "@/index.js"; import { Extraction } from "@/v2/product/index.js"; -describe("MindeeV2 - Extraction RagDocuments", { timeout: 180000 }, () => { +describe("MindeeV2 - Extraction RagDocuments", { timeout: 180_000 }, () => { let client: Client; let extractionModelId: string; diff --git a/tests/v2/search/modelSearch.integration.ts b/tests/v2/search/modelSearch.integration.ts index 9ed89ea8..6cba074a 100644 --- a/tests/v2/search/modelSearch.integration.ts +++ b/tests/v2/search/modelSearch.integration.ts @@ -5,7 +5,7 @@ import { beforeEach } from "node:test"; import { it } from "node:test"; import { ModelSearch, ModelSearchResponse } from "@/v2/search/index.js"; -describe("MindeeV2 - Integration - Model Search", { timeout: 120000 }, () => { +describe("MindeeV2 - Integration - Model Search", { timeout: 120_000 }, () => { let client: Client; beforeEach(() => { diff --git a/tests/v2/search/ragDocumentSearch.integration.ts b/tests/v2/search/ragDocumentSearch.integration.ts index cc210860..56d87318 100644 --- a/tests/v2/search/ragDocumentSearch.integration.ts +++ b/tests/v2/search/ragDocumentSearch.integration.ts @@ -5,7 +5,7 @@ import { beforeEach } from "node:test"; import { it } from "node:test"; import { RagDocumentSearch, RagDocumentSearchResponse } from "@/v2/search/index.js"; -describe("MindeeV2 - Integration - RAG Document Search", { timeout: 120000 }, () => { +describe("MindeeV2 - Integration - RAG Document Search", { timeout: 120_000 }, () => { let client: Client; let findocModelId: string;