The internal entries iterator. In some cases iterating over lines is simple. For example, if we create an instance from string or array we already have all the lines. However, if the input is a file, the entries iterator will be a function that reads and parses one line at a time.
The internal lines iterator. In some cases iterating over lines is simple. For example, if we create an instance from string or array we already have all the lines. However, if the input is a file, the lines iterator will be a function that reads one line at a time.
The entries iterator of the instance. Yields lines as objects.
The lines iterator of the instance. Yields lines as strings.
Sets the entries iterator of the instance. Useful while composing an instance from different sources. The "entries" might be JSON objects representing NDJSON lines or JS arrays of strings representing a line in CSV or TSV file.
The instance to allow chaining
Sets the entries iterator of the instance. Useful while composing an instance from different sources
The iterator to use
The instance to allow chaining
Returns an array of JSON objects representing of the NDJSON object.
NOTE: The array takes memory. Don't use this for big NDJSON objects.
Use the lines
or entries
iterators instead to handle one entry at a time.
Writes the NDJSON object to file. The file can be (re)created or appended to. Example:
```js const ndjson = NDJSON.fromStringArray(["{}", "{}" ]);
// Create or overwrite the file with default settings ndjson.toFile("/my/output.ndjson");
// Or use custom settings: ndjson.toFile("/my/output.ndjson", { eol: "\r\n", append: true });
Converts the contents of the collection to array of "values". The values are json objects representing each line. The result does not include the header in case of delimited formats.
NOTE: Don't use this for big objects/files because the output array is built into memory and then returned. For big files iterate over the entries instead, which will yield the same objects:
for (const entry of collection.entries()) {
// entry is an object representing a row
}
Returns a string representation of the NDJSON object.
NOTE: The string takes memory. Don't use this for big NDJSON objects.
Use the lines
or entries
iterators instead to handle one entry at a time.
Returns an array of JSON strings representing of the NDJSON object.
NOTE: The array takes memory. Don't use this for big NDJSON objects.
Use the lines
or entries
iterators instead to handle one entry at a time.
If we happen to have the entire ndjson as array, we can create an NDJSON instance like so:
const ndjson = NDJSON.fromArray([ {}, {} ]);
ndjson.lines(); // Lines iterator
ndjson.entries(); // JSON iterator
An array of objects that can be serialized as JSON
Creates and returns an NDJSON instance from directory path. This will
walk (recursively) through the directory and collect all the files having
a .ndjson
extension. The lines
and entries
iterators will yield
results from all those files combined. Example:
const ndjson = NDJSON.fromDirectory("/path/to/directory/containing/ndjson/files");
ndjson.lines(); // Lines iterator
ndjson.entries(); // JSON iterator
Absolute path to directory
Creates and returns an NDJSON instance from a file path. Example:
const ndjson = NDJSON.fromFile("/path/to/file.ndjson");
ndjson.lines(); // Lines iterator
ndjson.entries(); // JSON iterator
Absolute path to NDJSON file
If we have the entire ndjson as a string, we can create an instance
of NDJSON which will provide the lines
and entries
iterators like so:
const ndjson = NDJSON.fromString("{}\n{}");
ndjson.lines(); // Lines iterator
ndjson.entries(); // JSON iterator
The input string that can be parsed as JSON
If we have the entire ndjson as array of strings, we can create an NDJSON instance like so:
const ndjson = NDJSON.fromStringArray(["{}", "{}" ]);
ndjson.lines(); // Lines iterator
ndjson.entries(); // JSON iterator
An array of strings that can be parsed as JSON
Generated using TypeDoc
This class represents an NDJSON object. An instance can be created from different kinds of input using the static methods starting with
from
and converted to other kinds of output using the instance methods starting withto
. This class is designed to handle large files or directories by using iterators and reading files one line at a time.