UNPKG

@loaders.gl/json

Version:

Framework-independent loader for JSON and streaming JSON formats

43 lines (42 loc) 1.39 kB
// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import { parseJSONSync } from "./lib/parsers/parse-json.js"; import { parseJSONInBatches } from "./lib/parsers/parse-json-in-batches.js"; // __VERSION__ is injected by babel-plugin-version-inline // @ts-ignore TS2304: Cannot find name '__VERSION__'. const VERSION = typeof "4.3.2" !== 'undefined' ? "4.3.2" : 'latest'; export const JSONLoader = { dataType: null, batchType: null, name: 'JSON', id: 'json', module: 'json', version: VERSION, extensions: ['json', 'geojson'], mimeTypes: ['application/json'], category: 'table', text: true, options: { json: { shape: undefined, table: false, jsonpaths: [] // batchSize: 'auto' } }, parse, parseTextSync, parseInBatches }; async function parse(arrayBuffer, options) { return parseTextSync(new TextDecoder().decode(arrayBuffer), options); } function parseTextSync(text, options) { const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } }; return parseJSONSync(text, jsonOptions); } function parseInBatches(asyncIterator, options) { const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } }; return parseJSONInBatches(asyncIterator, jsonOptions); }