forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
57 lines (46 loc) · 1.55 KB
/
types.ts
File metadata and controls
57 lines (46 loc) · 1.55 KB
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
export function isString(value: any): boolean {
return typeof value === "string";
}
export function isNumber(value: any): boolean {
return typeof value === "number";
}
export function isFunction(value: any): boolean {
if (!value) {
return false;
}
return typeof value === "function";
}
export function isUndefined(value: any): boolean {
return typeof value === "undefined";
}
export function isDefined(value: any): boolean {
return typeof value !== "undefined";
}
export function isNullOrUndefined(value: any): boolean {
return (typeof value === "undefined") || (value === null);
}
export function verifyCallback(value: any) {
if (value && !isFunction(value)) {
throw new TypeError("Callback must be a valid function.");
}
}
var funcNameRegex = /function (.{1,})\(/;
export function getClass(object): string {
var results = (funcNameRegex).exec((object).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
}
export function getBaseClasses(object): Array<string> {
var baseProto = object.__proto__;
var result = [];
result.push(getClass(object));
while (baseProto !== Object.prototype) {
var baseProtoString = baseProto.toString();
// while extending some classes for platform specific versions results in duplicate class types in hierarchy
if (result.indexOf(baseProtoString) === -1) {
result.push(baseProtoString);
}
baseProto = baseProto.__proto__;
}
result.push("Object");
return result;
}