MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / object

Method object

shared/rison.ts:111–145  ·  view source on GitHub ↗
(x: Record<string, JSONValue> | null)

Source from the content-addressed store, hash-verified

109 return String(x).replace(/\+/, '');
110 }
111 static object(x: Record<string, JSONValue> | null) {
112 if (x) {
113 // because typeof null === 'object'
114 if (Array.isArray(x)) {
115 return Encoders.array(x);
116 }
117
118 const a = ['('];
119 let b = false;
120 let i: string;
121 let v: string | undefined;
122 let k: string;
123 let ki: number;
124 const ks: string[] = [];
125 for (const i in x) ks[ks.length] = i;
126 ks.sort();
127 for (ki = 0; ki < ks.length; ki++) {
128 i = ks[ki];
129 v = enc(x[i]);
130 if (typeof v == 'string') {
131 if (b) {
132 a[a.length] = ',';
133 }
134 k = Number.isNaN(Number.parseInt(i, 10))
135 ? Encoders.string(i)
136 : Encoders.number(Number.parseInt(i, 10));
137 a.push(k, ':', v);
138 b = true;
139 }
140 }
141 a[a.length] = ')';
142 return a.join('');
143 }
144 return '!n';
145 }
146 static string(x: string) {
147 if (x === '') return "''";
148

Callers 8

test_with_output_fileMethod · 0.80
test_exceptionMethod · 0.80
getPopularArgumentsMethod · 0.80
getMethod · 0.80
parseRequestReusableMethod · 0.80
registerShortlinkToolsFunction · 0.80
registerCompileToolFunction · 0.80

Calls 6

encFunction · 0.85
arrayMethod · 0.80
sortMethod · 0.80
stringMethod · 0.80
numberMethod · 0.80
pushMethod · 0.80

Tested by 3

test_with_output_fileMethod · 0.64
test_exceptionMethod · 0.64