1.0.0 • Published 5 years ago

unwrap-refs v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

unwrap-refs Build Status codecov

Unwrap { \$ref } in object

Install

$ npm install unwrap-refs

Usage

const { unwrapRefs, getByPath } = require("unwrap-refs")

const object = {
	first: {
		second: { $ref: "#/defs/value" },
	},
	defs: {
		value: {
			hello: "world",
		},
	},
}

const result = unwrapRefs(object)
/*
const object = {
  first: {
    second: { hello: "world" },
  },
  defs: {
    value: {
      hello: "world"
    },
  },
}
*/

API

unwrapRefs(object)

Returns unwrapped copy of object.

getByPath(root, path)

Get part of object from root by path.

root: Object

Target object to get path from.

path: String

Path from root, in format #/foo/bar.

Example

const target = {
  foo: {
    bar: { value: 1 },
  },
},

const result = getByPath(target, "#/foo/bar")
// { value: 1 }

License

MIT © Sergey Sova

1.0.0

5 years ago