Log.res.mjs
1// Generated by ReScript, PLEASE EDIT WITH CARE
2
3import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
4import * as Core__JSON from "@rescript/core/lib/es6/src/Core__JSON.res.mjs";
5import * as Stdlib_Bool from "@rescript/runtime/lib/es6/Stdlib_Bool.js";
6import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
7
8function _toString(kv, key) {
9 let x = kv[key];
10 if (x === undefined) {
11 return "";
12 }
13 let y = Core__JSON.Classify.classify(Primitive_option.valFromOption(x));
14 if (typeof y !== "object") {
15 return "null";
16 }
17 switch (y.TAG) {
18 case "Bool" :
19 return Stdlib_Bool.toString(y._0);
20 case "String" :
21 return y._0;
22 case "Number" :
23 return y._0.toString();
24 case "Object" :
25 case "Array" :
26 return "<invalid>";
27 }
28}
29
30function _render(msg, kvOpt) {
31 let kv = kvOpt !== undefined ? Primitive_option.valFromOption(kvOpt) : ({});
32 let keys = Object.keys(kv);
33 return Belt_Array.reduce(keys, msg, (out, key) => out + (` ` + key + `=` + _toString(kv, key)));
34}
35
36function debug(msg, kv) {
37 if (import.meta.env.MODE === "development") {
38 if (kv !== undefined) {
39 console.debug(_render(msg, Primitive_option.some(Primitive_option.valFromOption(kv))));
40 } else {
41 console.debug(msg);
42 }
43 return;
44 }
45}
46
47function info(msg, kv) {
48 if (kv !== undefined) {
49 console.log(_render(msg, Primitive_option.some(Primitive_option.valFromOption(kv))));
50 } else {
51 console.log(msg);
52 }
53}
54
55function warn(msg, kv) {
56 if (kv !== undefined) {
57 console.warn(_render(msg, Primitive_option.some(Primitive_option.valFromOption(kv))));
58 } else {
59 console.warn(msg);
60 }
61}
62
63function error(msg, kv) {
64 if (kv !== undefined) {
65 console.error(_render(msg, Primitive_option.some(Primitive_option.valFromOption(kv))));
66 } else {
67 console.error(msg);
68 }
69}
70
71function verify(b, msg) {
72 console.assert(b, msg);
73}
74
75export {
76 _toString,
77 _render,
78 debug,
79 info,
80 warn,
81 error,
82 verify,
83}
84/* No side effect */