1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.get = exports.pathToSegments = exports.fieldPathToSchema = exports.schemaPointerToFieldPath = exports.fieldPathToSchemaPath = void 0;
|
4 | const fieldPathToSchemaPath = (fieldPath) => {
|
5 | return pathToSegments(fieldPath)
|
6 | .map((segment) => `properties.${segment}`)
|
7 | .join('.');
|
8 | };
|
9 | exports.fieldPathToSchemaPath = fieldPathToSchemaPath;
|
10 |
|
11 | const schemaPointerToFieldPath = (jsonPointer) => {
|
12 | return jsonPointer
|
13 | .split('/')
|
14 | .slice(2)
|
15 | .filter((error) => error !== 'properties')
|
16 | .join('.');
|
17 | };
|
18 | exports.schemaPointerToFieldPath = schemaPointerToFieldPath;
|
19 | const fieldPathToSchema = (schema, fieldPath) => {
|
20 | return get(schema, (0, exports.fieldPathToSchemaPath)(fieldPath));
|
21 | };
|
22 | exports.fieldPathToSchema = fieldPathToSchema;
|
23 | function pathToSegments(path) {
|
24 | return Array.isArray(path) ? path : path.split('.');
|
25 | }
|
26 | exports.pathToSegments = pathToSegments;
|
27 | function 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 | }
|
36 | exports.get = get;
|
37 | //# sourceMappingURL=Util.js.map |
\ | No newline at end of file |