UNPKG

arquero

Version:

Query processing and transformation of array-backed data tables.

110 lines (109 loc) 5.23 kB
/** * Options for JSON parsing. * @typedef {object} JSONParseOptions * @property {'columns' | 'rows' | 'ndjson' | null} [type] The format type. * One of `'columns'` (for an object with named column arrays)`, 'rows'` (for * an array for row objects), or `'ndjson'` for [newline-delimited JSON][1] * rows. For `'ndjson'`, each line of text must contain a JSON row object * (with no trailing comma) and string properties must not contain any * newline characters. If no format type is specified, one of `'rows'` or * `'columns'` is inferred from the structure of the parsed JSON. * * [1]: https://github.com/ndjson/ndjson-spec * @property {boolean} [autoType=true] Flag controlling automatic type * inference for column values. If false, date parsing for input JSON * strings is disabled. * @property {Record<string, (value: any) => any>} [parse] Object of column * parsing options. The object keys should be column names. The object values * should be parsing functions that transform values upon input. * @property {string[]} [columns] An array of column names to include. JSON * properties missing from this list are not included in the table. * @property {number} [skip=0] The number of lines to skip before reading data. * Applicable to newline-delimited (NDJSON) data only. * @property {string} [comment] A string used to identify comment lines. Any * lines that start with the comment pattern are skipped. Applicable to * newline-delimited (NDJSON) data only. */ /** * Parse JavaScript Object Notation (JSON) data into a table. * By default, automatic type inference is performed * for input values; string values that match the ISO standard * date format are parsed into JavaScript Date objects. To disable this * behavior, set the autoType option to false. To perform custom parsing * of input column values, use the parse option. * @param {string} input The input text or stream. * @param {JSONParseOptions} options The JSON parse options. * @return {ColumnTable} A new table containing the parsed values. */ export function fromJSON(input: string, options?: JSONParseOptions): ColumnTable; /** * Parse a JavaScript Object Notation (JSON) stream into a table. * By default, automatic type inference is performed * for input values; string values that match the ISO standard * date format are parsed into JavaScript Date objects. To disable this * behavior, set the autoType option to false. To perform custom parsing * of input column values, use the parse option. * @param {ReadableStream<string>} input The input text or stream. * @param {JSONParseOptions} options The JSON parse options. * @return {Promise<ColumnTable>} A Promise to a new table containing the * parsed values. */ export function fromJSONStream(input: ReadableStream<string>, options?: JSONParseOptions): Promise<ColumnTable>; /** * Load a JSON file from a URL and return a Promise for an Arquero table. * If the loaded JSON is array-valued, an array-of-objects format is assumed * and the aq.from method is used to construct the table. Otherwise, a * column object format is assumed and aq.fromJSON is applied. * @param {string} path The URL or file path to load. * @param {import('./types.js').LoadOptions & JSONParseOptions} [options] * JSON parse options. * @return {Promise<ColumnTable>} A Promise to an Arquero table. * @example aq.loadJSON('data/table.json') */ export function loadJSON(path: string, options?: import("./types.js").LoadOptions & JSONParseOptions): Promise<ColumnTable>; /** * Options for JSON parsing. */ export type JSONParseOptions = { /** * The format type. * One of `'columns'` (for an object with named column arrays)`, 'rows'` (for * an array for row objects), or `'ndjson'` for [newline-delimited JSON][1] * rows. For `'ndjson'`, each line of text must contain a JSON row object * (with no trailing comma) and string properties must not contain any * newline characters. If no format type is specified, one of `'rows'` or * `'columns'` is inferred from the structure of the parsed JSON. * * [1]: https://github.com/ndjson/ndjson-spec */ type?: "columns" | "rows" | "ndjson" | null; /** * Flag controlling automatic type * inference for column values. If false, date parsing for input JSON * strings is disabled. */ autoType?: boolean; /** * Object of column * parsing options. The object keys should be column names. The object values * should be parsing functions that transform values upon input. */ parse?: Record<string, (value: any) => any>; /** * An array of column names to include. JSON * properties missing from this list are not included in the table. */ columns?: string[]; /** * The number of lines to skip before reading data. * Applicable to newline-delimited (NDJSON) data only. */ skip?: number; /** * A string used to identify comment lines. Any * lines that start with the comment pattern are skipped. Applicable to * newline-delimited (NDJSON) data only. */ comment?: string; }; import { ColumnTable } from '../table/ColumnTable.js';