@json-schema-tools/traverse
Version:
This package exports a method that will traverse a JSON-Schema, calling a mutation function for each sub schema found. It is useful for building tools to work with JSON Schemas.
30 lines (29 loc) • 818 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.last = exports.isCycle = exports.jsonPathStringify = void 0;
var jsonPathStringify = function (s) {
return s
.map(function (i) {
if (i === "") {
return "$";
}
else {
return ".".concat(i);
}
})
.join("");
};
exports.jsonPathStringify = jsonPathStringify;
var isCycle = function (s, recursiveStack) {
var foundInRecursiveStack = recursiveStack.find(function (recSchema) { return recSchema === s; });
if (foundInRecursiveStack) {
return foundInRecursiveStack;
}
return false;
};
exports.isCycle = isCycle;
var last = function (i, skip) {
if (skip === void 0) { skip = 1; }
return i[i.length - skip];
};
exports.last = last;
;