Skip to content

Commit ef4577c

Browse files
committed
Some general cleanup.
1 parent 3de4dc4 commit ef4577c

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

src/exceptionless-spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,15 @@ module Exceptionless {
286286
});
287287
});
288288

289-
describe('ModuleInfoPlugin', () => {
290-
it('should parse version from script source', () => {
291-
var mi = new Exceptionless.ModuleInfoPlugin();
292-
expect(mi.getVersion('https://code.jquery.com/jquery-2.1.3.js')).toBe('2.1.3');
293-
expect(mi.getVersion('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css')).toBe('3.3.4');
294-
expect(mi.getVersion('https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css')).toBe('2.0');
295-
expect(mi.getVersion('https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js')).toBe('0.3.0');
296-
expect(mi.getVersion('https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.0-X.10/angular-google-maps.min.js')).toBe('2.1.0-X.10');
297-
expect(mi.getVersion('https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/2.1.8-M1/swagger-ui.min.js')).toBe('2.1.8-M1');
298-
expect(mi.getVersion('https://cdnjs.cloudflare.com/BLAH/BLAH.min.js')).toBe(null);
289+
describe('Utils', () => {
290+
it('should parse version from url', () => {
291+
expect(Utils.parseVersion('https://code.jquery.com/jquery-2.1.3.js')).toBe('2.1.3');
292+
expect(Utils.parseVersion('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css')).toBe('3.3.4');
293+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css')).toBe('2.0');
294+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js')).toBe('0.3.0');
295+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.0-X.10/angular-google-maps.min.js')).toBe('2.1.0-X.10');
296+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/2.1.8-M1/swagger-ui.min.js')).toBe('2.1.8-M1');
297+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/BLAH/BLAH.min.js')).toBe(null);
299298
});
300299
});
301300
}

src/exceptionless.ts

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ module Exceptionless {
242242
}
243243

244244
if (!plugin.name) {
245-
plugin.name = Random.guid();
245+
plugin.name = Utils.guid();
246246
}
247247

248248
if (!plugin.priority) {
@@ -341,7 +341,7 @@ module Exceptionless {
341341
return;
342342
}
343343

344-
var key = this.queuePath() + '-' + new Date().toJSON() + '-' + Random.number();
344+
var key = this.queuePath() + '-' + new Date().toJSON() + '-' + Utils.randomNumber();
345345
this._config.log.info('Enqueuing event: ' + key);
346346
return this._config.storage.save(key, event);
347347
}
@@ -1015,7 +1015,7 @@ module Exceptionless {
10151015

10161016
run(context:Exceptionless.EventPluginContext): Promise<any> {
10171017
if ((!context.event.reference_id || context.event.reference_id.length === 0) && context.event.type === 'error') {
1018-
context.event.reference_id = Random.guid().replace('-', '').substring(0, 10);
1018+
context.event.reference_id = Utils.guid().replace('-', '').substring(0, 10);
10191019
}
10201020

10211021
return Promise.resolve();
@@ -1080,7 +1080,7 @@ module Exceptionless {
10801080
}
10811081
}
10821082

1083-
export class ModuleInfoPlugin implements IEventPlugin {
1083+
class ModuleInfoPlugin implements IEventPlugin {
10841084
public priority:number = 40;
10851085
public name:string = 'ModuleInfoPlugin';
10861086

@@ -1096,9 +1096,9 @@ module Exceptionless {
10961096
if (scripts && scripts.length > 0) {
10971097
for (var index = 0; index < scripts.length; index++) {
10981098
if (scripts[index].src) {
1099-
modules.push({ module_id: index, name: scripts[index].src, version: this.getVersion(scripts[index].src) });
1099+
modules.push({ module_id: index, name: scripts[index].src, version: Utils.parseVersion(scripts[index].src) });
11001100
} else if (!!scripts[index].innerHTML) {
1101-
modules.push({ module_id: index, name: 'Script Tag', version: this.getHashCode(scripts[index].innerHTML) });
1101+
modules.push({ module_id: index, name: 'Script Tag', version: Utils.getHashCode(scripts[index].innerHTML) });
11021102
}
11031103
}
11041104

@@ -1110,37 +1110,6 @@ module Exceptionless {
11101110

11111111
return Promise.resolve();
11121112
}
1113-
1114-
public getVersion(source:string): string {
1115-
if (!source) {
1116-
return null;
1117-
}
1118-
1119-
var versionRegex = /(v?((\d+)\.(\d+)(\.(\d+))?)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?)/;
1120-
var matches = versionRegex.exec(source);
1121-
if (matches && matches.length > 0) {
1122-
return matches[0];
1123-
}
1124-
1125-
return null;
1126-
}
1127-
1128-
public getHashCode(source:string): string {
1129-
if (!source || source.length === 0) {
1130-
return null;
1131-
}
1132-
1133-
var hash:number = 0;
1134-
for (var index = 0; index < source.length; index++) {
1135-
var character = source.charCodeAt(index);
1136-
hash = ((hash << 5) - hash) + character;
1137-
hash |= 0;
1138-
}
1139-
1140-
return hash.toString();
1141-
}
1142-
1143-
private get
11441113
}
11451114

11461115
class DuplicateCheckerPlugin implements IEventPlugin {
@@ -1174,7 +1143,7 @@ module Exceptionless {
11741143
path: location.pathname,
11751144
//client_ip_address: 'TODO',
11761145
cookies: this.getCookies(),
1177-
query_string: this.getQueryString(),
1146+
query_string: Utils.parseQueryString(location.search.substring(1)),
11781147
};
11791148

11801149
if (document.referrer && document.referrer !== '') {
@@ -1200,22 +1169,6 @@ module Exceptionless {
12001169

12011170
return result;
12021171
}
1203-
1204-
private getQueryString(): any {
1205-
var query:string = location.search.substring(1);
1206-
var pairs = query.split('&');
1207-
if (pairs.length === 0) {
1208-
return null;
1209-
}
1210-
1211-
var result = {};
1212-
for (var index = 0; index < pairs.length; index++) {
1213-
var pair = pairs[index].split('=');
1214-
result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
1215-
}
1216-
1217-
return result;
1218-
}
12191172
}
12201173

12211174
class SubmissionMethodPlugin implements IEventPlugin {
@@ -1309,7 +1262,22 @@ module Exceptionless {
13091262
data?:any;
13101263
}
13111264

1312-
class Random {
1265+
export class Utils {
1266+
public static getHashCode(source:string): string {
1267+
if (!source || source.length === 0) {
1268+
return null;
1269+
}
1270+
1271+
var hash:number = 0;
1272+
for (var index = 0; index < source.length; index++) {
1273+
var character = source.charCodeAt(index);
1274+
hash = ((hash << 5) - hash) + character;
1275+
hash |= 0;
1276+
}
1277+
1278+
return hash.toString();
1279+
}
1280+
13131281
public static guid(): string {
13141282
function s4() {
13151283
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
@@ -1318,7 +1286,40 @@ module Exceptionless {
13181286
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
13191287
}
13201288

1321-
public static number(): number {
1289+
public static parseVersion(source:string): string {
1290+
if (!source) {
1291+
return null;
1292+
}
1293+
1294+
var versionRegex = /(v?((\d+)\.(\d+)(\.(\d+))?)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?)/;
1295+
var matches = versionRegex.exec(source);
1296+
if (matches && matches.length > 0) {
1297+
return matches[0];
1298+
}
1299+
1300+
return null;
1301+
}
1302+
1303+
public static parseQueryString(query:string) {
1304+
if (!query || query.length === 0) {
1305+
return null;
1306+
}
1307+
1308+
var pairs = query.split('&');
1309+
if (pairs.length === 0) {
1310+
return null;
1311+
}
1312+
1313+
var result = {};
1314+
for (var index = 0; index < pairs.length; index++) {
1315+
var pair = pairs[index].split('=');
1316+
result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
1317+
}
1318+
1319+
return result;
1320+
}
1321+
1322+
public static randomNumber(): number {
13221323
return Math.floor(Math.random() * 9007199254740992);
13231324
}
13241325
}

0 commit comments

Comments
 (0)