Skip to content

Commit e6acefc

Browse files
authored
fix: Fixing doc about styling (#347)
1 parent 12d060c commit e6acefc

9 files changed

Lines changed: 70 additions & 28 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- name: Use Node.js 20
16+
- name: Use Node.js 22
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: '20.x'
19+
node-version: '22.x'
2020
cache: 'yarn'
2121

2222
- name: Install dependencies

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ typings/
6464
# next.js build output
6565
.next
6666

67-
# tests (not to add tests when publishing)
68-
test
67+
# Coverage output
6968
coverage
7069

7170
# jest configuration

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ You can customize the table output using the `--tableOptions` parameter. This ac
5050
Example with table options:
5151

5252
```bash
53-
# Color the entire table red
54-
ctp -i '[{"id":1,"name":"John"},{"id":2,"name":"Jane"}]' --tableOptions '{"style": {"headerColor": "red", "color": "red"}}'
55-
5653
# Use custom column styles
5754
ctp -i '[{"id":1,"status":"active"},{"id":2,"status":"inactive"}]' --tableOptions '{"columns": [{"name": "status", "color": "green"}]}'
5855

jestconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"collectCoverage": true,
3-
"preset": "ts-jest"
4-
}
3+
"preset": "ts-jest",
4+
"testMatch": ["**/test/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"]
5+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"ctp": "dist/index.js"
99
},
1010
"files": [
11-
"dist"
11+
"dist",
12+
"!dist/**/*.test.*",
13+
"!dist/test/**/*"
1214
],
1315
"scripts": {
1416
"setup": "npm install",

src/inputVerifier.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export const isValidJson = (str: string): Boolean => {
2+
if (!str) {
3+
console.error('Input is required');
4+
return false;
5+
}
6+
27
try {
38
const jsonObj = JSON.parse(str);
49
if (!Array.isArray(jsonObj)) {
@@ -12,9 +17,19 @@ export const isValidJson = (str: string): Boolean => {
1217
}
1318
};
1419

15-
export const verifyInput = (inp: string): Boolean => isValidJson(inp);
20+
export const verifyInput = (inp: string): Boolean => {
21+
if (inp === undefined || inp === null) {
22+
console.error('Input is required');
23+
return false;
24+
}
25+
return isValidJson(inp);
26+
};
1627

1728
export const verifyTableOptions = (options: string): boolean => {
29+
if (!options) {
30+
console.error('Table options are required');
31+
return false;
32+
}
1833
try {
1934
JSON.parse(options);
2035
return true;

src/service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@ const parseAndValidateInput = (inp: string, tableOptions?: string): ParsedInput
1818
return null;
1919
}
2020

21-
return {
22-
data: JSON.parse(inp),
23-
options: tableOptions && JSON.parse(tableOptions)
24-
};
21+
try {
22+
return {
23+
data: JSON.parse(inp),
24+
options: tableOptions && JSON.parse(tableOptions)
25+
};
26+
} catch (err) {
27+
console.log(`not a valid input ${inp}`);
28+
return null;
29+
}
2530
};
2631

2732
const printTableFromInp = (inp: string, tableOptions?: string): void | string => {
2833
const parsed = parseAndValidateInput(inp, tableOptions);
2934
if (!parsed) return;
3035

3136
const { data, options } = parsed;
37+
38+
console.log(options);
3239
if (options) {
3340
printTable(data, options);
3441
} else {

test/readmeExamples.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import service from '../src/service';
2+
3+
4+
describe('Testing Examples from README', () => {
5+
it('Original example', () => {
6+
service(
7+
'[{ "index":3, "text":"I would like some gelb bananen bitte", "value":200 }, { "index":4, "text":"I hope batch update is working", "value":300 } ]'
8+
);
9+
});
10+
11+
it('Basic Example', () => {
12+
service(
13+
'[{ "id":3, "text":"like" }, {"id":4, "text":"tea"}]'
14+
);
15+
});
16+
});
17+
18+
19+
describe('Using Table Options Examples', () => {
20+
it('Example 1: Table with column-specific color and alignment', () => {
21+
service(
22+
'[{"id":1,"status":"active"},{"id":2,"status":"inactive"}]',
23+
'{"columns":[{"name":"status","alignment":"right","color":"green"}]}'
24+
);
25+
});
26+
27+
it('Example 2: Table with custom title', () => {
28+
service(
29+
'[{"id":1,"name":"John"}]',
30+
'{"title":"Users List"}'
31+
);
32+
});
33+
});
34+

test/service.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)