Skip to content
Draft
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
15 changes: 14 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@ module.exports = {
overrides: [
{
// tests
files: ['test/**/*.js'],
files: ['test/**/*.js', 'test/**/*.ts'],
env: {
node: true,
jest: true,
},
},
{
files: ['test/**/*.ts', 'index.d.ts'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
},
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
},
}
],
};
152 changes: 75 additions & 77 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,91 @@
declare namespace CliTable3 {
type CharName =
"top" |
"top-mid" |
"top-left" |
"top-right" |
"bottom" |
"bottom-mid" |
"bottom-left" |
"bottom-right" |
"left" |
"left-mid" |
"mid" |
"mid-mid" |
"right" |
"right-mid" |
"middle";
type CharName =
| 'top'
| 'top-mid'
| 'top-left'
| 'top-right'
| 'bottom'
| 'bottom-mid'
| 'bottom-left'
| 'bottom-right'
| 'left'
| 'left-mid'
| 'mid'
| 'mid-mid'
| 'right'
| 'right-mid'
| 'middle';

type HorizontalAlignment = "left" | "center" | "right";
type VerticalAlignment = "top" | "center" | "bottom";
type HorizontalAlignment = 'left' | 'center' | 'right';
type VerticalAlignment = 'top' | 'center' | 'bottom';

interface TableOptions {
truncate: string;
colWidths: Array<number | null>;
rowHeights: Array<number | null>;
colAligns: HorizontalAlignment[];
rowAligns: VerticalAlignment[];
head: string[];
wordWrap: boolean;
wrapOnWordBoundary: boolean;
}
interface TableOptions {
truncate: string;
colWidths: Array<number | null>;
rowHeights: Array<number | null>;
colAligns: HorizontalAlignment[];
rowAligns: VerticalAlignment[];
head: string[];
wordWrap: boolean;
wrapOnWordBoundary: boolean;
}

interface TableInstanceOptions extends TableOptions {
chars: Record<CharName, string>;
style: {
"padding-left": number;
"padding-right": number;
head: string[];
border: string[];
compact: boolean;
};
}
interface TableInstanceOptions extends TableOptions {
chars: Record<CharName, string>;
style: {
'padding-left': number;
'padding-right': number;
head: string[];
border: string[];
compact: boolean;
};
}

interface TableConstructorOptions extends Partial<TableOptions> {
chars?: Partial<Record<CharName, string>>;
style?: Partial<TableInstanceOptions["style"]>;
}
interface TableConstructorOptions extends Partial<TableOptions> {
chars?: Partial<Record<CharName, string>>;
style?: Partial<TableInstanceOptions['style']>;
}

type CellValue = boolean | number | string | null | undefined;
type CellValue = boolean | number | string | null | undefined;

interface CellOptions {
content: CellValue;
chars?: Partial<Record<CharName, string>>;
truncate?: string;
colSpan?: number;
rowSpan?: number;
hAlign?: HorizontalAlignment;
vAlign?: VerticalAlignment;
style?: {
"padding-left"?: number;
"padding-right"?: number;
head?: string[];
border?: string[];
};
}
interface CellOptions {
content: CellValue;
chars?: Partial<Record<CharName, string>>;
truncate?: string;
colSpan?: number;
rowSpan?: number;
hAlign?: HorizontalAlignment;
vAlign?: VerticalAlignment;
style?: {
'padding-left'?: number;
'padding-right'?: number;
head?: string[];
border?: string[];
};
}

interface GenericTable<T> extends Array<T> {
options: TableInstanceOptions;
readonly width: number;
}
interface GenericTable<T> extends Array<T> {
options: TableInstanceOptions;
readonly width: number;
}

type Table = GenericTable<HorizontalTableRow|VerticalTableRow|CrossTableRow>;
type Cell = CellValue | CellOptions;
type Table = GenericTable<HorizontalTableRow | VerticalTableRow | CrossTableRow>;
type Cell = CellValue | CellOptions;

type HorizontalTableRow = Cell[];
type HorizontalTableRow = Cell[];

interface VerticalTableRow {
[name: string]: Cell;
}
interface VerticalTableRow {
[name: string]: Cell;
}

interface CrossTableRow {
[name: string]: Cell[];
}
interface CrossTableRow {
[name: string]: Cell[];
}
}

interface CliTable3 {
new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
readonly prototype: CliTable3.Table;
interface ICliTable3 {
new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
readonly prototype: CliTable3.Table;
}

declare const CliTable3: CliTable3;

export = CliTable3;
export const table: ICliTable3;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./src/table');
module.exports = require('./src/table');
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
"string-width": "^4.2.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "4.25.0",
"@typescript-eslint/parser": "4.25.0",
"cli-table": "^0.3.1",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.0.0",
"jest": "^25.2.4",
"jest-runner-eslint": "^0.7.0",
"lerna-changelog": "^1.0.1",
"prettier": "2.3.2"
"prettier": "2.3.2",
"typescript": "<5"
},
"optionalDependencies": {
"@colors/colors": "1.5.0"
},
"scripts": {
"changelog": "lerna-changelog",
"docs": "node ./scripts/update-docs.js",
"prettier": "prettier --write '{examples,lib,scripts,src,test}/**/*.js'",
"prettier": "prettier --write index.js index.d.ts '{examples,lib,scripts,src,test}/**/*.js'",
"test": "jest --color",
"test:watch": "jest --color --watchAll --notify"
},
Expand Down Expand Up @@ -82,11 +85,8 @@
"runner": "jest-runner-eslint",
"displayName": "lint",
"testMatch": [
"<rootDir>/examples/**/*.js",
"<rootDir>/lib/**/*.js",
"<rootDir>/scripts/**/*.js",
"<rootDir>/src/**/*.js",
"<rootDir>/test/**/*.js"
"<rootDir>/**/*.js",
"<rootDir>/**/*.ts"
]
}
]
Expand Down
Loading