@pipedream/gong
Version:
Pipedream Gong Components
58 lines (47 loc) • 1.19 kB
JavaScript
import { ConfigurationError } from "@pipedream/platform";
function emptyStrToUndefined(value) {
const trimmed = typeof(value) === "string" && value.trim();
return trimmed === ""
? undefined
: value;
}
function parse(value) {
const valueToParse = emptyStrToUndefined(value);
if (typeof(valueToParse) === "object" || valueToParse === undefined) {
return valueToParse;
}
try {
return JSON.parse(valueToParse);
} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid object");
}
}
function parseArray(value) {
try {
if (!value) {
return [];
}
if (Array.isArray(value)) {
return value;
}
const parsedValue = JSON.parse(value);
if (!Array.isArray(parsedValue)) {
throw new Error("Not an array");
}
return parsedValue;
} catch (e) {
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
}
}
async function streamIterator(stream) {
const resources = [];
for await (const resource of stream) {
resources.push(resource);
}
return resources;
}
export default {
parseArray,
parse,
streamIterator,
};