Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/code_samples/v2_classification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const params = {
// Set Classification parameters
const modelParams = {
modelId: modelId,
};

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/code_samples/v2_crop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const productParams = {
// Set Crop parameters
const modelParams = {
modelId: modelId,
};

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/code_samples/v2_extraction.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/code_samples/v2_ocr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const productParams = {
// Set Raw OCR parameters
const modelParams = {
modelId: modelId,
};

Expand All @@ -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;
8 changes: 4 additions & 4 deletions docs/code_samples/v2_split.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const productParams = {
// Set Split parameters
const modelParams = {
modelId: modelId,
};

Expand All @@ -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;
28 changes: 17 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -40,40 +41,44 @@ 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",
"jsdoc/check-types": "error",
"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",

"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",
Expand All @@ -84,20 +89,21 @@ 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": ["../*"],
"message": "Import can be shortened. Please use the @/ path alias instead of relative parent paths.",
}],
}],

"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,
Expand Down
2 changes: 1 addition & 1 deletion src/input/urlInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/parsing/baseLocalResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/v1/parsing/common/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/v1/parsing/common/summaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
export function cleanOutString(outStr: string): string {
const lines = / \n/gm;
return outStr.replace(lines, "\n");
return outStr.replaceAll(lines, "\n");
}

/**
Expand All @@ -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");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/input/sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/extraction/invoiceSplitter.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/v1/extraction/invoiceSplitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/extraction/multiReceipts.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
10 changes: 5 additions & 5 deletions tests/v1/extraction/multiReceipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
});
Expand All @@ -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++;
}
});
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/extras/extras.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/input/sources.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/input/urlInputSource.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/v1/parsing/localResponse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/workflows/workflow.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/client/client.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/v2/client/foreignDispatcher.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading