forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ts
More file actions
72 lines (63 loc) · 1.52 KB
/
helpers.ts
File metadata and controls
72 lines (63 loc) · 1.52 KB
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
import { escapeString } from '../../helpers/escape';
export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string) => {
lastIndent = lastIndent || '';
indent = indent || '';
switch (Object.prototype.toString.call(obj)) {
case '[object Null]':
return 'null';
case '[object Undefined]':
return 'null';
case '[object String]':
return `'${escapeString(obj, { delimiter: "'", escapeNewlines: false })}'`;
case '[object Number]':
return obj.toString();
case '[object Array]': {
const contents = obj
.map((item: any) => convertType(item, `${indent}${indent}`, indent))
.join(`,\n${indent}`);
return `[\n${indent}${contents}\n${lastIndent}]`;
}
case '[object Object]': {
const result: string[] = [];
for (const i in obj) {
if (Object.prototype.hasOwnProperty.call(obj, i)) {
result.push(
`${convertType(i, indent)} => ${convertType(obj[i], `${indent}${indent}`, indent)}`,
);
}
}
return `[\n${indent}${result.join(`,\n${indent}`)}\n${lastIndent}]`;
}
default:
return 'null';
}
};
export const supportedMethods = [
'ACL',
'BASELINE_CONTROL',
'CHECKIN',
'CHECKOUT',
'CONNECT',
'COPY',
'DELETE',
'GET',
'HEAD',
'LABEL',
'LOCK',
'MERGE',
'MKACTIVITY',
'MKCOL',
'MKWORKSPACE',
'MOVE',
'OPTIONS',
'POST',
'PROPFIND',
'PROPPATCH',
'PUT',
'REPORT',
'TRACE',
'UNCHECKOUT',
'UNLOCK',
'UPDATE',
'VERSION_CONTROL',
];