1.0.0-rc-2 • Published 10 months ago

data-deref v1.0.0-rc-2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Data-Deref

Simple utility to dereference $ref references in a data document.

Usage

Examples of usage can be found in the examples directory on the repository.

Basic Usage

The module exports a deref function by default which takes a single argument, a path to the file which is to be parsed and dereferenced.

import deref from "data-deref";

deref('path/to/data.json#/path/to/reference').then(console.log);

Using with a custom parser

You can use a custom parsing function which parses data based on the extension of file being referred to as resolved by 'path.extname(...)' of the standard library.

This example uses yaml to parse the data from a .yaml file.

import deref, { config } from "data-deref";
import YAML from "yaml";

config.addFileParser(".yaml", YAML.parse);

deref('path/to/data.yaml#/path/to/reference').then(console.log);

By default, the module only uses JSON.parse(...) to parse .json files.

Mixing references from different files

You can mix references from different files by using the $ref keyword in the data document.

// target.json
{
  "foo": {
    "$ref": "ref.yaml#/value/of/foo"
  }
}
# ref.yaml
value:
  of:
    foo: "bar"
import deref from "data-deref";
import YAML from "yaml";

deref('path/to/target.json#/foo').then(console.log);
// Logs "bar" to the console

Issues

If you find any issues with the module, please report them on the issues page of the repository.

Contributing

If you would like to contribute to the project, go to the GitHub Repository to clone the project, and make a pull-request after making changes. All pull requests are welcomed, and subjected to a review before being merged.

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.0-rc-2

10 months ago

1.0.0-rc-1

11 months ago

1.0.0-alpha.1

11 months ago

1.0.0-alpha

11 months ago

1.0.0-a

11 months ago