export class Guid { private static EMPTY = "00000000-0000-0000-0000-000000000000" ; private static validator = new RegExp ( "^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$" , "i" ) ; private _value : string ; public __typeName = "System.Guid" ; classdesc class param { string } string constructor ( guid ? ) { if ( guid === undefined ) { this . _value = Guid . EMPTY ; } else { if ( Guid . isGuid ( guid ) ) { this . _value = guid ; } else { throw new Error ( "Invalid GUID value" ) ; } } } private static gen ( count ) { var out = "" ; for ( var i = 0 ; i < count ; i ++ ) { out += ( ( ( 1 + Math . random ( ) ) * 0x10000 ) | 0 ) . toString ( 16 ) . substring ( 1 ) ; } return out ; } equals ( other ) { if ( other instanceof Guid ) return this . _value == other . getValue ( ) ; return Guid . isGuid ( other ) && this . _value == other ; } ; isEmpty ( ) { return this . _value === Guid . EMPTY ; } ; toString ( ) { return this . _value ; } ; toJSON ( ) { return this . _value ; } ; getValue ( ) { return this . _value ; } get Value ( ) : string { return this . _value ; } static isGuid ( value ) { return value && ( value instanceof Guid || Guid . validator . test ( value . toString ( ) ) ) ; } ; static create ( ) { return new Guid ( [ Guid . gen ( 2 ) , Guid . gen ( 1 ) , Guid . gen ( 1 ) , Guid . gen ( 1 ) , Guid . gen ( 3 ) ] . join ( "-" ) ) ; } ; static raw ( ) { return [ Guid . gen ( 2 ) , Guid . gen ( 1 ) , Guid . gen ( 1 ) , Guid . gen ( 1 ) , Guid . gen ( 3 ) ] . join ( "-" ) ; } ; static empty ( ) { return new Guid ( Guid . EMPTY ) ; } }