MCPcopy Create free account
hub / github.com/Kong/httpsnippet / convertType

Function convertType

src/targets/php/helpers.ts:3–42  ·  view source on GitHub ↗
(obj: any[] | any, indent?: string, lastIndent?: string)

Source from the content-addressed store, hash-verified

1import { escapeString } from '../../helpers/escape';
2
3export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string) => {
4 lastIndent = lastIndent || '';
5 indent = indent || '';
6
7 switch (Object.prototype.toString.call(obj)) {
8 case '[object Null]':
9 return 'null';
10
11 case '[object Undefined]':
12 return 'null';
13
14 case '[object String]':
15 return `'${escapeString(obj, { delimiter: "'", escapeNewlines: false })}'`;
16
17 case '[object Number]':
18 return obj.toString();
19
20 case '[object Array]': {
21 const contents = obj
22 .map((item: any) => convertType(item, `${indent}${indent}`, indent))
23 .join(`,\n${indent}`);
24 return `[\n${indent}${contents}\n${lastIndent}]`;
25 }
26
27 case '[object Object]': {
28 const result: string[] = [];
29 for (const i in obj) {
30 if (Object.prototype.hasOwnProperty.call(obj, i)) {
31 result.push(
32 `${convertType(i, indent)} => ${convertType(obj[i], `${indent}${indent}`, indent)}`,
33 );
34 }
35 }
36 return `[\n${indent}${result.join(`,\n${indent}`)}\n${lastIndent}]`;
37 }
38
39 default:
40 return 'null';
41 }
42};
43
44export const supportedMethods = [
45 'ACL',

Callers 4

client.tsFile · 0.90
client.tsFile · 0.90
client.tsFile · 0.90
client.tsFile · 0.90

Calls 1

escapeStringFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…