MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / valToResource

Function valToResource

lib/src/value.ts:64–84  ·  view source on GitHub ↗
(val: JSONValue)

Source from the content-addressed store, hash-verified

62
63/** Returns either the URL of the resource, or the NestedResource itself. */
64export 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}

Callers 1

ValueCompFunction · 0.90

Calls 1

parseJsonADResourceFunction · 0.85

Tested by

no test coverage detected