UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.fieldPathToSchema = exports.schemaPointerToFieldPath = exports.fieldPathToSchemaPath = void 0;
7const fill_1 = __importDefault(require("lodash/fill"));
8const flatten_1 = __importDefault(require("lodash/flatten"));
9const get_1 = __importDefault(require("lodash/get"));
10const zip_1 = __importDefault(require("lodash/zip"));
11const fieldPathToSchemaPath = (fieldPath) => {
12 const newPath = zip_1.default(fill_1.default(fieldPath.split('.'), 'properties'), fieldPath.split('.'));
13 return flatten_1.default(newPath).join('.');
14};
15exports.fieldPathToSchemaPath = fieldPathToSchemaPath;
16// Assumption: used only for jsonPointer returned from traverse
17const schemaPointerToFieldPath = (jsonPointer) => {
18 return jsonPointer
19 .split('/')
20 .slice(2)
21 .filter(e => e !== 'properties')
22 .join('.');
23};
24exports.schemaPointerToFieldPath = schemaPointerToFieldPath;
25const fieldPathToSchema = (schema, fieldPath) => {
26 return get_1.default(schema, exports.fieldPathToSchemaPath(fieldPath));
27};
28exports.fieldPathToSchema = fieldPathToSchema;
29//# sourceMappingURL=Util.js.map
\No newline at end of file