Skip to content

Commit f4bd1c2

Browse files
author
Wassim CHEGHAM
committed
chore: format numbers using EN numerical formatting
1 parent 75bb0ff commit f4bd1c2

File tree

9 files changed

+44
-38
lines changed

9 files changed

+44
-38
lines changed

src/helpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const format = (num: number) => num.toLocaleString('en');
2-
32
export const descOrder = stats => (a, b) => stats[b] - stats[a];

src/stats/classes.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
import { SourceFile, TypeGuards, ClassDeclaration } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
export default function(sourceFiles: SourceFile[]) {
34
const classes = [];
45
const classesAnnotated = [];
56

6-
77
// see: https://github.com/compodoc/ts-stats/issues/12#issuecomment-380791091
88
function visit(decorator: string, stats: string[]) {
99
stats.push(decorator);
1010
}
11-
11+
1212
for (const sourceFile of sourceFiles) {
1313
sourceFile.forEachDescendant(descendant => {
1414
if (TypeGuards.isClassDeclaration(descendant)) {
15-
const classeDeclaration = (descendant as ClassDeclaration);
15+
const classeDeclaration = descendant as ClassDeclaration;
1616
if (classeDeclaration.getDecorators().length === 0) {
1717
visit(classeDeclaration.getName(), classes);
18-
}
19-
else {
18+
} else {
2019
visit(classeDeclaration.getName(), classesAnnotated);
2120
}
2221
}
2322
});
2423
}
2524

26-
// sourceFiles.map(sourceFile => {
27-
// sourceFile.getClasses().map(classe => {
28-
// if (classe.getDecorators().length === 0) {
29-
// // get classes without decorators
30-
// classes.push(classe.getName());
31-
// } else {
32-
// // get classes with decorators
33-
// classesAnnotated.push(classe.getName());
34-
// }
35-
// });
36-
// });
37-
3825
return {
3926
keys: [['Classes', 'Classes (w/ annotation)', 'Classes (w/o annotation)'].join('\n')],
40-
values: [[classesAnnotated.length + classes.length, classesAnnotated.length, classes.length].join('\n')]
27+
values: [[format(classesAnnotated.length + classes.length), format(classesAnnotated.length), format(classes.length)].join('\n')]
4128
};
4229
}

src/stats/decorators.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { SourceFile, Node, TypeGuards } from 'ts-simple-ast';
22
import { stat } from 'fs';
3-
3+
import { format, descOrder } from '../helpers';
44

55
export default function(sourceFiles: SourceFile[]) {
6-
const stats: {[key: string]: number} = {};
7-
8-
function visit(decorator: string, stats: {[key: string]: number}) {
6+
const stats: { [key: string]: number } = {};
7+
8+
function visit(decorator: string, stats: { [key: string]: number }) {
99
const _decorator = `@${decorator}()`;
1010
const entry = stats[_decorator];
1111
stats[_decorator] = (stats[_decorator] || 0) + 1;
1212
}
13-
13+
1414
for (const sourceFile of sourceFiles) {
1515
sourceFile.forEachDescendant(descendant => {
1616
if (TypeGuards.isDecorator(descendant)) {
@@ -20,10 +20,15 @@ export default function(sourceFiles: SourceFile[]) {
2020
}
2121

2222
return {
23-
keys: [Object.keys(stats).join('\n')],
23+
keys: [
24+
Object.keys(stats)
25+
.sort(descOrder(stats))
26+
.join('\n')
27+
],
2428
values: [
2529
Object.keys(stats)
26-
.map(k => stats[k])
30+
.sort(descOrder(stats))
31+
.map(k => format(stats[k]))
2732
.join('\n')
2833
]
2934
};

src/stats/exports.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY = 'Exports';
34
const stats = { [KEY]: [] };
45
export default function(sourcesFiles: SourceFile[]) {
@@ -13,14 +14,12 @@ export default function(sourcesFiles: SourceFile[]) {
1314
});
1415

1516
return {
16-
keys: [
17-
[KEY, 'Exports (named)', 'Exports (default)'].join('\n')
18-
],
17+
keys: [[KEY, 'Exports (named)', 'Exports (default)'].join('\n')],
1918
values: [
2019
[
21-
stats[KEY].length,
22-
stats[KEY].filter((c: string) => !c.startsWith('default_export_')).length,
23-
stats[KEY].filter((c: string) => c.startsWith('default_export_')).length
20+
format(stats[KEY].length),
21+
format(stats[KEY].filter((c: string) => !c.startsWith('default_export_')).length),
22+
format(stats[KEY].filter((c: string) => c.startsWith('default_export_')).length)
2423
].join('\n')
2524
]
2625
};

src/stats/files.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY = 'TypeScript Files';
34
const stats = { [KEY]: [] };
45
export default function(sourcesFiles: SourceFile[]) {
@@ -8,6 +9,6 @@ export default function(sourcesFiles: SourceFile[]) {
89

910
return {
1011
keys: [KEY],
11-
values: [stats[KEY].length]
12+
values: [format(stats[KEY].length)]
1213
};
1314
}

src/stats/imports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY = 'Imports';
34
const stats = { [KEY]: [] };
45
export default function(sourcesFiles: SourceFile[]) {
@@ -10,6 +11,6 @@ export default function(sourcesFiles: SourceFile[]) {
1011

1112
return {
1213
keys: [KEY],
13-
values: [stats[KEY].length]
14+
values: [format(stats[KEY].length)]
1415
};
1516
}

src/stats/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY = 'Interfaces';
34
const stats = { [KEY]: [] };
45
export default function(sourcesFiles: SourceFile[]) {
@@ -10,6 +11,6 @@ export default function(sourcesFiles: SourceFile[]) {
1011

1112
return {
1213
keys: [KEY],
13-
values: [stats[KEY].length]
14+
values: [format(stats[KEY].length)]
1415
};
1516
}

src/stats/loc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY = 'LOC (total)';
34
const KEY1 = 'LOC (mean)';
45
const KEY2 = 'LOC (median)';
@@ -53,6 +54,6 @@ export default function(sourcesFiles: SourceFile[]) {
5354

5455
return {
5556
keys: [[KEY, KEY1, KEY2, KEY3].join('\n')],
56-
values: [[total, mean, median, mode].join('\n')]
57+
values: [[format(total), format(+mean), format(+median), format(+mode)].join('\n')]
5758
};
5859
}

src/stats/specs.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SourceFile, SyntaxKind } from 'ts-simple-ast';
2+
import { format } from '../helpers';
23
const KEY1 = 'Spec (files)';
34
const KEY2 = 'Spec (describe)';
45
const KEY2x = 'Spec (xdescribe)';
@@ -9,7 +10,7 @@ const KEY3f = 'Spec (fit)';
910
const KEY4 = 'Spec (expect)';
1011

1112
function filter(funcNames, by) {
12-
return funcNames.filter(n => n === by).length
13+
return funcNames.filter(n => n === by).length;
1314
}
1415
export default function(sourcesFiles: SourceFile[]) {
1516
const files = [];
@@ -46,6 +47,17 @@ export default function(sourcesFiles: SourceFile[]) {
4647

4748
return {
4849
keys: [[KEY1, KEY2, KEY2x, KEY2f, KEY3, KEY3x, KEY3f, KEY4].join('\n')],
49-
values: [[files.length, describe, xdescribe, fdescribe, it, xit, fit, expect].join('\n')]
50+
values: [
51+
[
52+
format(files.length),
53+
format(describe),
54+
format(xdescribe),
55+
format(fdescribe),
56+
format(it),
57+
format(xit),
58+
format(fit),
59+
format(expect)
60+
].join('\n')
61+
]
5062
};
5163
}

0 commit comments

Comments
 (0)