Functions:parseData - bettyblocks/cli GitHub Wiki

The parseData helper makes it easier to parse different datatypes in an Action. The function takes in an object with keys; data and format, and returns a Promise with a list objects. The data keys can be one of these: a string with the data or a url pointing to the data.

type JSONValue = string | number | boolean | null | JSONObject | JSONArray;

interface JSONObject {
  [x: string]: JSONValue;
}

type JSONArray = Array<JSONValue>;

type Format = 'CSV' | 'JSON';

interface ParseDataArguments {
  data: string;
  format?: Format;
}

async function parseData({
  data,
  format,
}: ParseDataArguments): Promise<JSONValue[]>;

Examples

const data = `[
  {"data": 1, "description": ""},
  {"data": 2, "description": ""}
]`;

await parseData({
  data,
  format: 'JSON',
});
const data = `order_id;customer;paid;created_at
14987576452870392979;John Doe;true;2213-05-22T16:08:55.067342584Z
638002794201564283;Jane Doe;true;2149-05-03T23:22:31.389391892Z`;

await parseData({
  data,
  format: 'CSV',
});
const url = 'https://httpbin.org/json';
await parseData({
  url,
  format: 'JSON',
});
⚠️ **GitHub.com Fallback** ⚠️