-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathjs_json.js
110 lines (93 loc) · 2.06 KB
/
js_json.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
var Caml_option = require("./caml_option.js");
function classify(x) {
var ty = typeof x;
if (ty === "string") {
return {
tag: /* JSONString */0,
_0: x
};
} else if (ty === "number") {
return {
tag: /* JSONNumber */1,
_0: x
};
} else if (ty === "boolean") {
if (x === true) {
return /* JSONTrue */1;
} else {
return /* JSONFalse */0;
}
} else if (x === null) {
return /* JSONNull */2;
} else if (Array.isArray(x)) {
return {
tag: /* JSONArray */3,
_0: x
};
} else {
return {
tag: /* JSONObject */2,
_0: x
};
}
}
function test(x, v) {
switch (v) {
case /* String */0 :
return typeof x === "string";
case /* Number */1 :
return typeof x === "number";
case /* Object */2 :
if (x !== null && typeof x === "object") {
return !Array.isArray(x);
} else {
return false;
}
case /* Array */3 :
return Array.isArray(x);
case /* Boolean */4 :
return typeof x === "boolean";
case /* Null */5 :
return x === null;
}
}
function decodeString(json) {
if (typeof json === "string") {
return json;
}
}
function decodeNumber(json) {
if (typeof json === "number") {
return json;
}
}
function decodeObject(json) {
if (typeof json === "object" && !Array.isArray(json) && json !== null) {
return Caml_option.some(json);
}
}
function decodeArray(json) {
if (Array.isArray(json)) {
return json;
}
}
function decodeBoolean(json) {
if (typeof json === "boolean") {
return json;
}
}
function decodeNull(json) {
if (json === null) {
return null;
}
}
exports.classify = classify;
exports.test = test;
exports.decodeString = decodeString;
exports.decodeNumber = decodeNumber;
exports.decodeObject = decodeObject;
exports.decodeArray = decodeArray;
exports.decodeBoolean = decodeBoolean;
exports.decodeNull = decodeNull;
/* No side effect */