This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
68 lines (57 loc) · 1.48 KB
/
schema.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Utility } from "./core";
/*export enum Edm {
Null,
Binary,
Boolean,
Byte,
DateTime,
Decimal,
Double,
Single,
Guid,
Int16,
Int32,
Int64,
String,
Time
}
*/
export class Guid {
constructor(public value: String) {
if (value == null) return;
if (typeof value != "string")
throw new Error('value is not guid. Please check');
}
toString() {
return this.value;
}
valueOf() {
return this.value;
}
static new(): Guid {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return new Guid(s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4());
}
static newString(): String {
return this.new().toString();
}
static parse(value: any) {
if (Utility.instanceof(value,Guid)) return value;
let any = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value);
if (any)
return new Guid(value);
throw new Error(value + " is could not parse for guid");
}
static tryParse(value) {
if (Utility.instanceof(value,Guid)) return value;
let any = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value);
if (any) return new Guid(value);
return null;
}
}
export class Float {
}