MCPcopy Index your code
hub / github.com/angular/angular / toKeyValue

Function toKeyValue

packages/common/upgrade/src/params.ts:291–310  ·  view source on GitHub ↗

* Serializes into key-value pairs. Logic taken from * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1409

(obj: {[k: string]: unknown})

Source from the content-addressed store, hash-verified

289 * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1409
290 */
291function toKeyValue(obj: {[k: string]: unknown}) {
292 const parts: unknown[] = [];
293 for (const key in obj) {
294 let value = obj[key];
295 if (Array.isArray(value)) {
296 value.forEach((arrayValue) => {
297 parts.push(
298 encodeUriQuery(key, true) +
299 (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)),
300 );
301 });
302 } else {
303 parts.push(
304 encodeUriQuery(key, true) +
305 (value === true ? '' : '=' + encodeUriQuery(value as any, true)),
306 );
307 }
308 }
309 return parts.length ? parts.join('&') : '';
310}
311
312/**
313 * We need our custom method because encodeURIComponent is too aggressive and doesn't follow

Callers 1

encodeSearchMethod · 0.85

Calls 5

isArrayMethod · 0.80
encodeUriQueryFunction · 0.70
joinMethod · 0.65
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…