pg-rdf-to-json
Version:
Transforms RDF files from rdf-files.tar.bz2 provided by Project Gutenberg into JS/JSON objects.
43 lines • 1.63 kB
TypeScript
import { type Formatter, type FormattedRDFFile, type UnformattedRDFFile } from '../types.js';
type Rule = [string, Formatter | Formatter[]];
export declare const formatters: Map<Rule[0], Rule[1]>;
/**
* Accepts a parsed, but not formatted RDF file. It isn't possible _just_ using
* `fast-xml-parser` to move keys and values around. This additional formatting
* step reduces the complexity of the parsed XML object by:
*
* * reducing the depth of unnecessesarily nested objects.
* * converting certain values into more suitable data types.
* * grouping similar fields like MARC fields.
* * enforcing structural rules e.g. `files` **must** be defined.
*
* This function recursively goes through the `original` object, returning a
* deep clone of it, but with every single one of its values parsed where a
* parser for the path has been defined.
*
* If the `original` object looks like this:
*
* ```json
* {
* "title": "hello",
* "desciption": {
* "short": "a short description",
* "long": "a long description"
* }
* }
* ```
*
* And a formatter has been defined that applies to the path
* `description.short`, but no others have been defined, then only that single
* value will be parsed. Every other value will be added to the new object
* without any changes.
*
* The formatters applied to the `original` object is defined at
* {@link formatters}.
*
* @param original The parsed, but unformatted RDF file.
* @returns A formatted RDF file.
*/
export declare function formatRDFFile(original: UnformattedRDFFile): FormattedRDFFile;
export {};
//# sourceMappingURL=formatters.d.ts.map