UNPKG

1.38 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.get = exports.pathToSegments = exports.fieldPathToSchema = exports.schemaPointerToFieldPath = exports.fieldPathToSchemaPath = void 0;
4const fieldPathToSchemaPath = (fieldPath) => {
5 return pathToSegments(fieldPath)
6 .map((segment) => `properties.${segment}`)
7 .join('.');
8};
9exports.fieldPathToSchemaPath = fieldPathToSchemaPath;
10// Assumption: used only for jsonPointer returned from traverse
11const schemaPointerToFieldPath = (jsonPointer) => {
12 return jsonPointer
13 .split('/')
14 .slice(2)
15 .filter((error) => error !== 'properties')
16 .join('.');
17};
18exports.schemaPointerToFieldPath = schemaPointerToFieldPath;
19const fieldPathToSchema = (schema, fieldPath) => {
20 return get(schema, (0, exports.fieldPathToSchemaPath)(fieldPath));
21};
22exports.fieldPathToSchema = fieldPathToSchema;
23function pathToSegments(path) {
24 return Array.isArray(path) ? path : path.split('.');
25}
26exports.pathToSegments = pathToSegments;
27function get(object, path) {
28 const segments = pathToSegments(path);
29 const length = segments.length;
30 let index = 0;
31 while (object != null && index < length) {
32 object = object[segments[index++]];
33 }
34 return index && index === length ? object : undefined;
35}
36exports.get = get;
37//# sourceMappingURL=Util.js.map
\No newline at end of file