-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
84 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,49 @@ | ||
import {StringHelper} from "./ExtensionMethods"; | ||
import * as uuid from 'node-uuid'; | ||
import { StringHelper } from "./ExtensionMethods"; | ||
import * as uuid from 'uuid'; | ||
/** Guid proxy class */ | ||
export class Guid { | ||
static Empty: Guid = new Guid('00000000-0000-0000-0000-000000000000'); | ||
private guid: string = null; | ||
constructor(str: string) { | ||
if (StringHelper.IsNullOrEmpty(str) || str === null) { | ||
throw new TypeError("Guid.ctor - invalid input"); | ||
} | ||
str = str.replace("-", "").replace("{", "").replace("}", "").toLowerCase(); | ||
var parsed = uuid.parse(str); | ||
if (parsed) { | ||
this.guid = uuid.unparse(parsed); | ||
// if (this.guid.replace("-", "") !== str.toString()) { | ||
// throw new TypeError("Guid.ctor - malformed string") | ||
// } | ||
static Empty: Guid = new Guid(); | ||
private guid: string = '00000000-0000-0000-0000-000000000000'; | ||
//private regx = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
//private regx_withoutdash = /^[0-9a-f]{8}[0-9a-f]{4}[1-5][0-9a-f]{3}[89ab][0-9a-f]{3}[0-9a-f]{12}$/i; | ||
|
||
constructor(); | ||
constructor(str: string); | ||
constructor(str?: string) { | ||
let regx = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
if (arguments.length > 0) { | ||
if (StringHelper.IsNullOrEmpty(str) || str === null) { | ||
throw new TypeError("Guid.ctor - invalid input"); | ||
} | ||
//str = str.replace("-", "").replace("{", "").replace("}", "").toLowerCase(); | ||
str = str.replace("{", "").replace("}", "").toLowerCase(); | ||
if (regx.test(str)) { | ||
this.guid = str; | ||
} else { | ||
throw new TypeError("Guid.ctor - invalid input"); | ||
} | ||
} | ||
} | ||
ToString() { | ||
return this.guid; | ||
} | ||
toString(){ | ||
return this.guid; | ||
} | ||
|
||
static NewGuid(): Guid { | ||
return new Guid(uuid.v4()); | ||
} | ||
static Parse(str: string): Guid { | ||
var parsed = uuid.parse(str); | ||
if (parsed) { | ||
return new Guid(str); | ||
return new Guid(str); | ||
} | ||
|
||
static TryParse(str, _parsed_output: { guid: Guid } = { guid: null }) { | ||
try { | ||
_parsed_output.guid = new Guid(str); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters