(obj: any[] | any, indent?: string, lastIndent?: string)
| 1 | import { escapeString } from '../../helpers/escape'; |
| 2 | |
| 3 | export 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 | |
| 44 | export const supportedMethods = [ |
| 45 | 'ACL', |
no test coverage detected
searching dependent graphs…