Coder Social home page Coder Social logo

data-deref's Introduction

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.

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.

data-deref's People

Contributors

l0rd-zer0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.