diff --git a/src/autoTable.ts b/src/autoTable.ts index d3131a34..33e748ed 100644 --- a/src/autoTable.ts +++ b/src/autoTable.ts @@ -2,16 +2,11 @@ import { DocHandler, jsPDFDocument } from './documentHandler' import { parseInput } from './inputParser' import { calculateWidths } from './widthCalculator' import { drawTable } from './tableDrawer' -import { ColumnOption, RowInput, UserOptions } from './config' +import { UserOptions } from './config' -// First definition is deprecated -export function autoTable( - columns: ColumnOption[], - data: RowInput[], - options: UserOptions -): jsPDFDocument export function autoTable(options: UserOptions): jsPDFDocument -export function autoTable(this: jsPDFDocument) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function autoTable(this: jsPDFDocument, ...args: any) { const doc = new DocHandler(this) let win: Window | undefined @@ -20,7 +15,7 @@ export function autoTable(this: jsPDFDocument) { } // 1. Parse and unify user input - const table = parseInput(arguments, doc, win) + const table = parseInput(args, doc, win) // 2. Calculate preliminary table, column, row and cell dimensions calculateWidths(table, doc) diff --git a/src/config.ts b/src/config.ts index 304c1270..ce60efc2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,3 @@ -import { CellHookData } from './HookData' import { CellHook, PageHook } from './models' /** diff --git a/src/documentHandler.ts b/src/documentHandler.ts index acf3444a..2de7c56c 100644 --- a/src/documentHandler.ts +++ b/src/documentHandler.ts @@ -3,8 +3,11 @@ import { Color, Styles, UserOptions } from './config' let globalDefaults: UserOptions = {} +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type jsPDFConstructor = any +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type jsPDFDocument = any + type Opts = { [key: string]: string | number } export class DocHandler { diff --git a/src/htmlParser.ts b/src/htmlParser.ts index cc7c897c..0ae63f78 100644 --- a/src/htmlParser.ts +++ b/src/htmlParser.ts @@ -11,7 +11,7 @@ export function parseHtml( ): { head: RowInput[]; body: RowInput[]; foot: RowInput[] } { let tableElement: HTMLTableElement if (typeof input === 'string') { - tableElement = window.document.querySelector(input) + tableElement = window.document.querySelector(input) as HTMLTableElement } else { tableElement = input } diff --git a/src/inputValidator.ts b/src/inputValidator.ts index b6166223..c22f02fb 100644 --- a/src/inputValidator.ts +++ b/src/inputValidator.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { DocHandler } from './documentHandler' import { HookData } from './HookData' import { UserOptions } from './config' diff --git a/src/main.ts b/src/main.ts index 45462519..93cb1d33 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ export function applyPlugin(jsPDF: jsPDFConstructor) { export type autoTable = (options: UserOptions) => void try { + // eslint-disable-next-line @typescript-eslint/no-var-requires const jsPDF = require('jspdf') applyPlugin(jsPDF) } catch (error) { diff --git a/src/models.ts b/src/models.ts index e45f875f..dead2180 100644 --- a/src/models.ts +++ b/src/models.ts @@ -14,12 +14,6 @@ import { marginOrPadding, MarginPadding } from './common' export type PageHook = (data: HookData) => void | boolean export type CellHook = (data: CellHookData) => void | boolean -export type HookProp = - | 'didParseCell' - | 'willDrawCell' - | 'didDrawCell' - | 'didDrawPage' - export interface HookProps { didParseCell: CellHook[] willDrawCell: CellHook[] diff --git a/src/polyfills.ts b/src/polyfills.ts index 0c174c68..5312fe8c 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -1,6 +1,4 @@ -/* - * Include common small polyfills instead of requiring the user to to do it - */ +/* eslint-disable @typescript-eslint/no-unused-vars */ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign export function assign( @@ -15,6 +13,7 @@ export function assign( } const to = Object(target) for (let index = 1; index < arguments.length; index++) { + // eslint-disable-next-line prefer-rest-params const nextSource = arguments[index] if (nextSource != null) { diff --git a/src/tableDrawer.ts b/src/tableDrawer.ts index 1b4c5b47..87756237 100644 --- a/src/tableDrawer.ts +++ b/src/tableDrawer.ts @@ -5,7 +5,7 @@ import { DocHandler } from './documentHandler' import { assign } from './polyfills' import autoTableText from './autoTableText' -export function drawTable(table: Table, doc: DocHandler) { +export function drawTable(table: Table, doc: DocHandler): void { const settings = table.settings const startY = settings.startY const margin = settings.margin diff --git a/src/widthCalculator.ts b/src/widthCalculator.ts index 5a05f621..5ebcf79d 100644 --- a/src/widthCalculator.ts +++ b/src/widthCalculator.ts @@ -247,7 +247,7 @@ function fitContent(table: Table, doc: DocHandler) { } } -function ellipsize( +export function ellipsize( text: string[], width: number, styles: Styles, diff --git a/test/testCommon.ts b/test/testCommon.ts index f19756eb..ca3c164d 100644 --- a/test/testCommon.ts +++ b/test/testCommon.ts @@ -1,8 +1,8 @@ const assert = require('assert') -import { ellipsize } from '../src/common' +import { ellipsize } from '../src/widthCalculator' import { DocHandler } from '../src/documentHandler' -describe('common', () => { +describe('ellipsize', () => { let doc: any, jsPDF before(() => { jsPDF = require('./common').loadJspdf() diff --git a/test/testInitializer.ts b/test/testInitializer.ts index 3a4af503..cf577327 100644 --- a/test/testInitializer.ts +++ b/test/testInitializer.ts @@ -1,3 +1,5 @@ +import { autoTable } from '../src/main' + const assert = require('assert') import { loadJspdf } from './common' @@ -8,8 +10,17 @@ describe('execution', () => { require('../src/main') }) + it('types', () => { + const doc = new jsPDF() + ;((doc as any).autoTable as autoTable)({ + body: [['test']], + }) + assert(true) + }) + it('init', () => { const autoTable = new jsPDF().autoTable + new jsPDF().autoTable({}) assert.equal(typeof autoTable, 'function') })