1.0.0 • Published 5 years ago
unwrap-refs v1.0.0
unwrap-refs
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