UNPKG

@js-data-tools/js-helpers

Version:

A set of JavaScript / TypeScript helper functions for parsing, converting, transforming and formatting data.

46 lines (45 loc) 1.92 kB
/** * Parses an NDJSON stream * * @since 0.1.2 * @category json * @param {Iterable<string>} textLines - The enumerable collection of text lines to parse - every entry is supposed to be a valid JSON text to parse * @param {(this: any, key: string, value: any) => any} [reviver] An optional reviver object (see {@link JSON#parse}) * @returns {Iterable<T>} An iterable collection of parsed values. */ export declare function parseJsonLines<T>(textLines: Iterable<string>, reviver?: (this: any, key: string, value: any) => any): Iterable<T>; /** * Parses an asynchronous NDJSON stream * * @since 0.1.2 * @category json * @param {AsyncIterable<string>} textLines - The enumerable async stream of text lines to parse - every entry is supposed to be a valid JSON. * @param {(this: any, key: string, value: any) => any} [reviver] An optional reviver object (see {@link JSON#parse}) * @returns {AsyncIterable<T>} An iterable asynchronous stream of parsed values. */ export declare function parseJsonLinesAsync<T>(textLines: AsyncIterable<string>, reviver?: (this: any, key: string, value: any) => any): AsyncIterable<T>; /** * Render the given value as an NDJSON entry: a JSON without whitespace, followed by a line break. * * @since 0.1.2 * @category json * @param value - The value to render as an NDJSON (JSON line). * @param replacer - An optional function that transforms the results (see JSON.stringify). * @returns {string} A string with JSON representation of the given value (no whitespace or line breaks in the middle), followed by a line break. * @example * * toJsonLine([ * { * name: "John", * age: 23, * male: true * }, * { * name: "Mary", * age: 21 * } * ]); * * // => `[{"name":"John","age":23,"male":true},{"name":"Mary","age":21}]` */ export declare function toJsonLine(value: unknown, replacer?: (key: string, value: any) => any): string;