-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
index.ts
54 lines (46 loc) · 1.58 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import path from 'path';
import * as query from './query';
import commandExists from './command-exists';
import { ConnectionInterface, DatabaseDialect } from '../interface';
export * from './get-home';
export * from './replacer';
export * from './telemetry';
export * from './timer';
export * from './get-connection-stuff';
export function sortText(a: string, b: string) { return a.toString().localeCompare(b.toString()); }
export function asArray<T>(obj: any) {
if (Array.isArray(obj)) {
return obj as T[];
}
return Object.keys(obj).map((k) => obj[k]) as T[];
}
export function getConnectionDescription(c: ConnectionInterface): string | null {
if (!c) return null;
if (c.dialect === DatabaseDialect.SQLite) {
return c.database.replace(/\$\{workspaceFolder:(.+)}/g, '$1').replace(/\$\{workspaceFolder}/g, '.');
}
if (c.connectString) {
return c.connectString.replace(/(.+):.+@/gi, '$1@'); // removes password from string
}
return [
c.username,
c.username ? '@' : '',
!c.socketPath && c.server,
!c.socketPath && c.server && c.port ? ':' : '',
c.socketPath && `socket:${path.basename(c.socketPath)}`,
c.port,
'/',
c.database,
].filter(Boolean).join('');
}
export function isEmpty(v?: string) {
return !v || v.length === 0;
}
export function numericVersion(v: string) {
const n: number[] = v.replace(/^v/, '').split('.')
.map((a) => parseInt(a.replace(/\D+/, ''), 10));
if (n.length >= 3) return n[0] * 10000 + n[1] * 100 + n[2];
if (n.length === 2) return n[0] * 10000 + n[1] * 100;
return n[0] * 10000;
}
export { query, commandExists };