1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _getValue = _interopRequireDefault(require("get-value"));
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function objectDeepKeys(obj) {
|
13 | return Object.keys(obj).filter(function (key) {
|
14 | return obj[key] instanceof Object;
|
15 | }).map(function (key) {
|
16 | return objectDeepKeys(obj[key]).map(function (k) {
|
17 | return "".concat(key, ".").concat(k);
|
18 | });
|
19 | }).reduce(function (x, y) {
|
20 | return x.concat(y);
|
21 | }, Object.keys(obj));
|
22 | }
|
23 |
|
24 | var getFullPaths = function getFullPaths(path) {
|
25 | var current = '';
|
26 | return path.split('.').map(function (s, index) {
|
27 | if (current === '') current = s;else current += ".".concat(s);
|
28 | return current;
|
29 | });
|
30 | };
|
31 |
|
32 | var getFullPath = function getFullPath(obj, fullPaths) {
|
33 | var fullPath = '';
|
34 | fullPaths.forEach(function (p) {
|
35 | var key = (0, _getValue.default)(obj, p).key;
|
36 |
|
37 | if (key) {
|
38 | fullPath += ".".concat(key);
|
39 | }
|
40 | });
|
41 | return fullPath.replace('.', '');
|
42 | };
|
43 |
|
44 | var matchPatterns = function matchPatterns(patterns, fullPath) {
|
45 | var count = 0;
|
46 | patterns.forEach(function (pattern) {
|
47 | if (typeof pattern === 'string' && fullPath.includes(pattern)) count++;else if (fullPath.match(pattern) !== null) count++;
|
48 | });
|
49 | return count === patterns.length;
|
50 | };
|
51 |
|
52 | var find = function find(obj, patterns) {
|
53 | return objectDeepKeys(obj).map(function (path) {
|
54 | return {
|
55 | path: path,
|
56 | key: (0, _getValue.default)(obj, path).key
|
57 | };
|
58 | }).filter(function (x) {
|
59 | return typeof x.key !== 'undefined';
|
60 | }).map(function (_ref) {
|
61 | var path = _ref.path,
|
62 | key = _ref.key;
|
63 | var fullPaths = getFullPaths(path);
|
64 | var fullPath = getFullPath(obj, fullPaths);
|
65 | return {
|
66 | path: path,
|
67 | key: key,
|
68 | fullPath: fullPath
|
69 | };
|
70 | }).filter(function (_ref2) {
|
71 | var fullPath = _ref2.fullPath;
|
72 | return matchPatterns(patterns, fullPath);
|
73 | });
|
74 | };
|
75 |
|
76 | var _default = find;
|
77 | exports.default = _default; |
\ | No newline at end of file |