(val: JSONValue)
| 62 | |
| 63 | /** Returns either the URL of the resource, or the NestedResource itself. */ |
| 64 | export function valToResource(val: JSONValue): string | Resource { |
| 65 | if (typeof val == 'string') { |
| 66 | return val; |
| 67 | } |
| 68 | if (val instanceof Date) { |
| 69 | throw new Error(`Not a resource: ${val}, is a Date`); |
| 70 | } |
| 71 | if (val.constructor == Array) { |
| 72 | throw new Error(`Not a resource: ${val}, is an Array`); |
| 73 | } |
| 74 | if (typeof val == 'object') { |
| 75 | //@ts-ignore |
| 76 | const resource = new Resource('nested-resource'); |
| 77 | parseJsonADResource(val as JSONObject, resource); |
| 78 | return resource; |
| 79 | } |
| 80 | if (typeof val !== 'object') { |
| 81 | throw new Error(`Not a resource: ${val}, is a ${typeof val}`); |
| 82 | } |
| 83 | throw new Error(`Not a resource: ${val}, is a ${typeof val}`); |
| 84 | } |
no test coverage detected