Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 29cdfba

Browse files
ghillertoodamien
authored andcommitted
gh-852 Use a dedicated UUID/GUID library
* Add `node-uuid` dependency * Update code * Ensure that lint errors pertaining to `Forbidden bitwise operation` no longer occur
1 parent d244ab9 commit 29cdfba

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

ui/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"jshint": "2.9.5",
5252
"spring-flo": "0.8.0",
5353
"ng-busy": "1.4.4",
54-
"rxjs-compat": "^6.2.1"
54+
"rxjs-compat": "^6.2.1",
55+
"uuid": "3.3.2"
5556
},
5657
"devDependencies": {
5758
"@angular/compiler-cli": "6.0.7",
@@ -62,6 +63,7 @@
6263
"@types/jasmine": "2.8.8",
6364
"@types/jasminewd2": "2.0.3",
6465
"@types/node": "8.9.5",
66+
"@types/uuid": "3.4.3",
6567
"codelyzer": "4.2.1",
6668
"jasmine-core": "2.99.1",
6769
"jasmine-spec-reporter": "4.2.1",

ui/src/app/shared/services/group-route.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Injectable } from '@angular/core';
22
import { LocalStorageService } from 'angular-2-local-storage';
33

4+
import * as uuidv4 from 'uuid/v4';
5+
46
/**
5-
* A service for global logs.
7+
* A service for create group route.
68
*
79
* @author Damien Vitrac
810
*/
@@ -12,11 +14,16 @@ export class GroupRouteService {
1214
constructor(private localStorageService: LocalStorageService) {
1315
}
1416

17+
/**
18+
* Create an unique UUID
19+
* Format:
20+
* 6ba7b810-9dad-11d1-80b4-00c04fd430c8
21+
*
22+
* @param args
23+
* @returns {string}
24+
*/
1525
create(args): string {
16-
const key = `group-${'xxxxx-xxxxx-xxxxx-xxxxx'.replace(/[xy]/g, function (c) {
17-
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
18-
return v.toString(16);
19-
})}`;
26+
const key = 'group-' + uuidv4();
2027
this.localStorageService.set(key, args);
2128
return key;
2229
}
@@ -26,7 +33,8 @@ export class GroupRouteService {
2633
if (!str.startsWith('group-')) {
2734
return false;
2835
}
29-
if (str.length !== 29 || str[11] !== '-' || str[17] !== '-' || str[23] !== '-') {
36+
const g = `group-`.length;
37+
if (str.length !== (36 + g) || str[(8 + g)] !== '-' || str[(13 + g)] !== '-' || str[(18 + g)] !== '-' || str[(23 + g)] !== '-') {
3038
return false;
3139
}
3240
return true;

ui/src/app/tests/mocks/group-route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as uuidv4 from 'uuid/v4';
2+
13
/**
24
* A service for group route.
35
*
@@ -12,10 +14,7 @@ export class MockGroupRouteService {
1214
}
1315

1416
create(args): string {
15-
const key = `group-${'xxxxx-xxxxx-xxxxx-xxxxx'.replace(/[xy]/g, function (c) {
16-
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
17-
return v.toString(16);
18-
})}`;
17+
const key = 'group-' + uuidv4();
1918
this._group[key] = args;
2019
this.last = {
2120
key: key,
@@ -29,7 +28,8 @@ export class MockGroupRouteService {
2928
if (!str.startsWith('group-')) {
3029
return false;
3130
}
32-
if (str.length !== 29 || str[11] !== '-' || str[17] !== '-' || str[23] !== '-') {
31+
const g = `group-`.length;
32+
if (str.length !== (36 + g) || str[(8 + g)] !== '-' || str[(13 + g)] !== '-' || str[(18 + g)] !== '-' || str[(23 + g)] !== '-') {
3333
return false;
3434
}
3535
return true;

0 commit comments

Comments
 (0)