Skip to content

Commit 5fba2f5

Browse files
committed
Added ArrayUtils. Now sorting lists ignoring casing in commands ListAllInports and PackageJsonToMarkdown.
1 parent 08c7e60 commit 5fba2f5

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/arrayUtils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import path = require("path");
2+
3+
export class ArrayUtils {
4+
5+
public static arrayToMarkdown(array: string[] | undefined): string {
6+
if (array === undefined || array.length === 0) {
7+
return '';
8+
} else {
9+
if (typeof (array) === 'string') {
10+
return array;
11+
} else {
12+
try {
13+
return array.sort(this.sortStrings).join(',<br>');
14+
} catch (ex) {
15+
return `ex: ${ex} - Len:${array.length} - type:${typeof (array)} - ${array}\n`;
16+
}
17+
}
18+
}
19+
}
20+
21+
public static sortStrings(stringA: string, stringB: string): number {
22+
stringA = path.basename(stringA).toUpperCase();
23+
stringB = path.basename(stringB).toUpperCase();
24+
if (stringA < stringB) {
25+
return -1;
26+
}
27+
if (stringA > stringB) {
28+
return 1;
29+
}
30+
return 0;
31+
}
32+
}

src/commands/listAllImports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22
import * as vscode from 'vscode';
33

4-
import { Config, FileSystemUtils } from '@src';
4+
import { ArrayUtils, Config, FileSystemUtils } from '@src';
55

66
export class ListAllImports {
77
private config = new Config();
@@ -51,7 +51,7 @@ export class ListAllImports {
5151
angularToolsOutput.clear();
5252
angularToolsOutput.appendLine(`Imports for files in workspace: ${workspaceDirectory}`);
5353
angularToolsOutput.appendLine('The number following each import in the list is the number of occurrences of the package import.\n');
54-
for (const key of Object.keys(imports).sort()) {
54+
for (const key of Object.keys(imports).sort(ArrayUtils.sortStrings)) {
5555
angularToolsOutput.appendLine(`${key}: ${imports[key]}`);
5656
}
5757
angularToolsOutput.show();

src/commands/packageJsonToMarkdown.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33

4-
import { Config, FileSystemUtils } from '@src';
4+
import { ArrayUtils, Config, FileSystemUtils } from '@src';
55

66
const fetch = require('node-fetch');
77

@@ -39,7 +39,7 @@ export class PackageJsonToMarkdown {
3939
let devDependenciesMarkdown = '';
4040
let peerDependenciesMarkdown = '';
4141
const dependenciesRequests: Promise<{ name: string, description: string }>[] = [];
42-
dependencies.sort().forEach(pckName => {
42+
dependencies.sort(ArrayUtils.sortStrings).forEach(pckName => {
4343
dependenciesRequests.push(this.makeRequest(pckName));
4444
});
4545
Promise.all(dependenciesRequests).then(responses => {
@@ -50,7 +50,7 @@ export class PackageJsonToMarkdown {
5050
});
5151
}).then(() => {
5252
const devDependenciesRequests: Promise<{ name: string, description: string }>[] = [];
53-
devDependencies.sort().forEach(pckName => {
53+
devDependencies.sort(ArrayUtils.sortStrings).forEach(pckName => {
5454
devDependenciesRequests.push(this.makeRequest(pckName));
5555
});
5656
Promise.all(devDependenciesRequests).then(responses => {
@@ -61,7 +61,7 @@ export class PackageJsonToMarkdown {
6161
});
6262
}).then(() => {
6363
const peerDependenciesRequests: Promise<{ name: string, description: string }>[] = [];
64-
peerDependencies.sort().forEach(pckName => {
64+
peerDependencies.sort(ArrayUtils.sortStrings).forEach(pckName => {
6565
peerDependenciesRequests.push(this.makeRequest(pckName));
6666
});
6767
Promise.all(peerDependenciesRequests).then(responses => {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './arrayUtils';
12
export * from './componentManager';
23
export * from './config';
34
export * from './filesystemUtils';

0 commit comments

Comments
 (0)