@common.js/object-scan 20.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2022 Lukas Siemon
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/object-scan
2
+
3
+ The [object-scan](https://www.npmjs.com/package/object-scan) package exported as CommonJS modules.
4
+
5
+ Exported from [object-scan@20.0.4](https://www.npmjs.com/package/object-scan/v/20.0.4) using https://github.com/etienne-martin/common.js.
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _iteratorJs = /*#__PURE__*/ _interopRequireDefault(require("../generic/iterator.js"));
12
+ function _arrayLikeToArray(arr, len) {
13
+ if (len == null || len > arr.length) len = arr.length;
14
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
15
+ return arr2;
16
+ }
17
+ function _arrayWithHoles(arr) {
18
+ if (Array.isArray(arr)) return arr;
19
+ }
20
+ function _interopRequireDefault(obj) {
21
+ return obj && obj.__esModule ? obj : {
22
+ default: obj
23
+ };
24
+ }
25
+ function _iterableToArrayLimit(arr, i) {
26
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
27
+ if (_i == null) return;
28
+ var _arr = [];
29
+ var _n = true;
30
+ var _d = false;
31
+ var _s, _e;
32
+ try {
33
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
34
+ _arr.push(_s.value);
35
+ if (i && _arr.length === i) break;
36
+ }
37
+ } catch (err) {
38
+ _d = true;
39
+ _e = err;
40
+ } finally{
41
+ try {
42
+ if (!_n && _i["return"] != null) _i["return"]();
43
+ } finally{
44
+ if (_d) throw _e;
45
+ }
46
+ }
47
+ return _arr;
48
+ }
49
+ function _nonIterableRest() {
50
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
+ }
52
+ function _slicedToArray(arr, i) {
53
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
54
+ }
55
+ function _unsupportedIterableToArray(o, minLen) {
56
+ if (!o) return;
57
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
58
+ var n = Object.prototype.toString.call(o).slice(8, -1);
59
+ if (n === "Object" && o.constructor) n = o.constructor.name;
60
+ if (n === "Map" || n === "Set") return Array.from(n);
61
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
62
+ }
63
+ var _default = function(tower, needle, tree, param) {
64
+ var onAdd = param.onAdd, onFin = param.onFin;
65
+ var stack = [
66
+ [
67
+ [
68
+ tower,
69
+ null
70
+ ]
71
+ ]
72
+ ];
73
+ var excluded = false;
74
+ (0, _iteratorJs.default)(tree, function(type, v) {
75
+ if (type === "RM") {
76
+ if (v.excluded === true) {
77
+ excluded = false;
78
+ }
79
+ stack.length -= 2;
80
+ } else if (type === "ADD") {
81
+ if (v.excluded === true) {
82
+ if (excluded) {
83
+ throw new Error('Redundant Exclusion: "'.concat(needle, '"'));
84
+ }
85
+ excluded = true;
86
+ }
87
+ var toAdd = [];
88
+ var vParent = stack[stack.length - 2];
89
+ stack[stack.length - 1].forEach(function(param) {
90
+ var _param = _slicedToArray(param, 2), cur = _param[0], parent = _param[1];
91
+ return onAdd(cur, parent, v, vParent, function(e) {
92
+ return toAdd.push([
93
+ e,
94
+ cur
95
+ ]);
96
+ });
97
+ });
98
+ stack.push(v, toAdd);
99
+ } else {
100
+ stack[stack.length - 1].filter(function(param) {
101
+ var _param = _slicedToArray(param, 1), cur = _param[0];
102
+ return cur !== tower;
103
+ }).forEach(function(param) {
104
+ var _param = _slicedToArray(param, 2), cur = _param[0], parent = _param[1];
105
+ return onFin(cur, parent, v, excluded);
106
+ });
107
+ }
108
+ });
109
+ };
@@ -0,0 +1,164 @@
1
+ /* compile needles to hierarchical map object */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "compile", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return compile;
9
+ }
10
+ });
11
+ var _parserJs = /*#__PURE__*/ _interopRequireDefault(require("./parser.js"));
12
+ var _compilerIteratorJs = /*#__PURE__*/ _interopRequireDefault(require("./compiler-iterator.js"));
13
+ var _parserRefJs = require("./parser-ref.js");
14
+ var _nodeJs = require("./node.js");
15
+ var _helperJs = require("../generic/helper.js");
16
+ function _arrayLikeToArray(arr, len) {
17
+ if (len == null || len > arr.length) len = arr.length;
18
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
19
+ return arr2;
20
+ }
21
+ function _arrayWithoutHoles(arr) {
22
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
23
+ }
24
+ function _instanceof(left, right) {
25
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
26
+ return !!right[Symbol.hasInstance](left);
27
+ } else {
28
+ return left instanceof right;
29
+ }
30
+ }
31
+ function _interopRequireDefault(obj) {
32
+ return obj && obj.__esModule ? obj : {
33
+ default: obj
34
+ };
35
+ }
36
+ function _iterableToArray(iter) {
37
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
38
+ }
39
+ function _nonIterableSpread() {
40
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
41
+ }
42
+ function _toConsumableArray(arr) {
43
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
44
+ }
45
+ function _unsupportedIterableToArray(o, minLen) {
46
+ if (!o) return;
47
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
48
+ var n = Object.prototype.toString.call(o).slice(8, -1);
49
+ if (n === "Object" && o.constructor) n = o.constructor.name;
50
+ if (n === "Map" || n === "Set") return Array.from(n);
51
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
52
+ }
53
+ var applyNeedle = function(tower, needle, tree, ctx) {
54
+ (0, _compilerIteratorJs.default)(tower, needle, tree, {
55
+ onAdd: function(cur, parent, v, vParent, next) {
56
+ cur.addNeedle(needle);
57
+ if (_instanceof(v, _parserRefJs.Ref)) {
58
+ if (v.left === true) {
59
+ if (v.isStarRec) {
60
+ v.setPointer(cur);
61
+ }
62
+ v.setNode(new _nodeJs.Node("*", ctx));
63
+ ctx.links.push(cur, v.node);
64
+ next(v.node);
65
+ } else {
66
+ // eslint-disable-next-line no-param-reassign
67
+ v.target = "target" in vParent ? vParent.target : parent.get(vParent.value);
68
+ ctx.links.push(v.target, v.node);
69
+ if (v.pointer !== null) {
70
+ next(v.pointer);
71
+ v.setPointer(null);
72
+ }
73
+ next(cur);
74
+ }
75
+ return;
76
+ }
77
+ var redundantRecursion = v.isStarRec && v.value === (vParent === null || vParent === void 0 ? void 0 : vParent.value);
78
+ if (redundantRecursion && ctx.strict) {
79
+ throw new Error('Redundant Recursion: "'.concat(needle, '"'));
80
+ }
81
+ if (!redundantRecursion) {
82
+ var node = cur.get(v.value);
83
+ if (node === undefined) {
84
+ node = new _nodeJs.Node(v.value, ctx);
85
+ cur.add(node);
86
+ }
87
+ next(node);
88
+ } else {
89
+ // eslint-disable-next-line no-param-reassign
90
+ v.target = cur;
91
+ }
92
+ if (v.isStarRec) {
93
+ next(cur);
94
+ }
95
+ },
96
+ onFin: function(cur, parent, v, excluded) {
97
+ if (ctx.strict && v.isSimpleStarRec) {
98
+ var unnecessary = parent.children.filter(function(param) {
99
+ var value = param.value;
100
+ return ![
101
+ "",
102
+ "**"
103
+ ].includes(value);
104
+ });
105
+ if (unnecessary.length !== 0) {
106
+ throw new Error('Needle Target Invalidated: "'.concat(unnecessary[0].needles[0], '" by "').concat(needle, '"'));
107
+ }
108
+ }
109
+ if (ctx.strict && cur.leafNeedles.length !== 0) {
110
+ var nLeft = (0, _helperJs.formatNeedle)(cur.leafNeedles[0]);
111
+ var nRight = (0, _helperJs.formatNeedle)(needle);
112
+ throw new Error('Redundant Needle Target: "'.concat(nLeft, '" vs "').concat(nRight, '"'));
113
+ }
114
+ cur.finish(needle, excluded, ctx.counter);
115
+ ctx.counter += 1;
116
+ }
117
+ });
118
+ };
119
+ var finalizeTower = function(tower, ctx) {
120
+ var _loop = function() {
121
+ var child = links.pop();
122
+ var parent = links.pop();
123
+ var children = parent.children;
124
+ parent.children = _toConsumableArray(child.children.filter(function(c) {
125
+ return !children.includes(c);
126
+ })).concat(_toConsumableArray(children));
127
+ };
128
+ var links = ctx.links;
129
+ while(links.length !== 0)_loop();
130
+ if (ctx.useArraySelector === false) {
131
+ tower.setRoots(tower.children.filter(function(param) {
132
+ var isStarRec = param.isStarRec, value = param.value;
133
+ return isStarRec || value === "";
134
+ }));
135
+ }
136
+ var nodes = ctx.nodes;
137
+ while(nodes.length !== 0){
138
+ var node = nodes.pop();
139
+ var children = node.children;
140
+ children.reverse();
141
+ if (children.some(function(param) {
142
+ var matches = param.matches;
143
+ return matches;
144
+ })) {
145
+ node.markMatches();
146
+ }
147
+ }
148
+ };
149
+ var compile = function(needles, ctx) {
150
+ ctx.counter = 0;
151
+ ctx.links = [];
152
+ ctx.nodes = [];
153
+ ctx.regex = Object.create(null);
154
+ var tower = new _nodeJs.Node("*", ctx);
155
+ for(var idx = 0; idx < needles.length; idx += 1){
156
+ var needle = needles[idx];
157
+ var tree = [
158
+ _parserJs.default.parse(needle, ctx)
159
+ ];
160
+ applyNeedle(tower, needle, tree, ctx);
161
+ }
162
+ finalizeTower(tower, ctx);
163
+ return tower;
164
+ };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _assertJs = /*#__PURE__*/ _interopRequireDefault(require("../generic/assert.js"));
12
+ function _defineProperty(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ function _interopRequireDefault(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ function _objectSpread(target) {
31
+ for(var i = 1; i < arguments.length; i++){
32
+ var source = arguments[i] != null ? arguments[i] : {};
33
+ var ownKeys = Object.keys(source);
34
+ if (typeof Object.getOwnPropertySymbols === "function") {
35
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
36
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
37
+ }));
38
+ }
39
+ ownKeys.forEach(function(key) {
40
+ _defineProperty(target, key, source[key]);
41
+ });
42
+ }
43
+ return target;
44
+ }
45
+ var _typeof = function(obj) {
46
+ "@swc/helpers - typeof";
47
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
48
+ };
49
+ var expect = function(opts, option, types) {
50
+ (0, _assertJs.default)(types.includes(_typeof(opts[option])), function() {
51
+ return 'Option "'.concat(option, '" not one of [').concat(types.join(", "), "]");
52
+ });
53
+ };
54
+ var _default = function(opts) {
55
+ var ctx = _objectSpread({
56
+ filterFn: undefined,
57
+ breakFn: undefined,
58
+ beforeFn: undefined,
59
+ afterFn: undefined,
60
+ compareFn: undefined,
61
+ reverse: true,
62
+ orderByNeedles: false,
63
+ abort: false,
64
+ rtn: undefined,
65
+ joined: false,
66
+ useArraySelector: true,
67
+ strict: true
68
+ }, opts);
69
+ (0, _assertJs.default)(Object.keys(ctx).length === 12, "Unexpected Option provided");
70
+ expect(ctx, "filterFn", [
71
+ "function",
72
+ "undefined"
73
+ ]);
74
+ expect(ctx, "breakFn", [
75
+ "function",
76
+ "undefined"
77
+ ]);
78
+ expect(ctx, "beforeFn", [
79
+ "function",
80
+ "undefined"
81
+ ]);
82
+ expect(ctx, "afterFn", [
83
+ "function",
84
+ "undefined"
85
+ ]);
86
+ expect(ctx, "compareFn", [
87
+ "function",
88
+ "undefined"
89
+ ]);
90
+ expect(ctx, "reverse", [
91
+ "boolean"
92
+ ]);
93
+ expect(ctx, "orderByNeedles", [
94
+ "boolean"
95
+ ]);
96
+ expect(ctx, "abort", [
97
+ "boolean"
98
+ ]);
99
+ (0, _assertJs.default)(typeof ctx.rtn === "function" && ctx.rtn.length === 1 || [
100
+ undefined,
101
+ "context",
102
+ "key",
103
+ "value",
104
+ "entry",
105
+ "property",
106
+ "gproperty",
107
+ "parent",
108
+ "gparent",
109
+ "parents",
110
+ "isMatch",
111
+ "matchedBy",
112
+ "excludedBy",
113
+ "traversedBy",
114
+ "isCircular",
115
+ "isLeaf",
116
+ "depth",
117
+ "bool",
118
+ "count",
119
+ "sum"
120
+ ].includes(ctx.rtn) || Array.isArray(ctx.rtn) && ctx.rtn.every(function(e) {
121
+ return [
122
+ "key",
123
+ "value",
124
+ "entry",
125
+ "property",
126
+ "gproperty",
127
+ "parent",
128
+ "gparent",
129
+ "parents",
130
+ "isMatch",
131
+ "matchedBy",
132
+ "excludedBy",
133
+ "traversedBy",
134
+ "isCircular",
135
+ "isLeaf",
136
+ "depth"
137
+ ].includes(e);
138
+ }), 'Option "rtn" is malformed');
139
+ expect(ctx, "joined", [
140
+ "boolean"
141
+ ]);
142
+ expect(ctx, "useArraySelector", [
143
+ "boolean"
144
+ ]);
145
+ expect(ctx, "strict", [
146
+ "boolean"
147
+ ]);
148
+ return ctx;
149
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _default = function(kwargs, ctx) {
12
+ if (ctx.rtn === "context") {
13
+ return {
14
+ onMatch: function() {},
15
+ get: function() {
16
+ return kwargs.context;
17
+ }
18
+ };
19
+ }
20
+ if (ctx.rtn === "bool") {
21
+ var result = false;
22
+ return {
23
+ onMatch: function() {
24
+ result = true;
25
+ },
26
+ get: function() {
27
+ return result;
28
+ }
29
+ };
30
+ }
31
+ if (ctx.rtn === "count") {
32
+ var result1 = 0;
33
+ return {
34
+ onMatch: function() {
35
+ result1 += 1;
36
+ },
37
+ get: function() {
38
+ return result1;
39
+ }
40
+ };
41
+ }
42
+ if (ctx.rtn === "sum") {
43
+ var result2 = 0;
44
+ return {
45
+ onMatch: function(param) {
46
+ var value = param.value;
47
+ result2 += value;
48
+ },
49
+ get: function() {
50
+ return result2;
51
+ }
52
+ };
53
+ }
54
+ var result3 = [];
55
+ return {
56
+ onMatch: function() {
57
+ if (typeof ctx.rtn === "function") {
58
+ return function() {
59
+ return result3.push(ctx.rtn(kwargs));
60
+ };
61
+ }
62
+ if (Array.isArray(ctx.rtn)) {
63
+ return function() {
64
+ return result3.push(ctx.rtn.map(function(rtn) {
65
+ return kwargs[rtn];
66
+ }));
67
+ };
68
+ }
69
+ return function() {
70
+ return result3.push(kwargs[ctx.rtn]);
71
+ };
72
+ }(),
73
+ get: function() {
74
+ return ctx.abort ? result3[0] : result3;
75
+ }
76
+ };
77
+ };
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ matchedBy: function() {
13
+ return matchedBy;
14
+ },
15
+ excludedBy: function() {
16
+ return excludedBy;
17
+ },
18
+ traversedBy: function() {
19
+ return traversedBy;
20
+ },
21
+ isLastLeafMatch: function() {
22
+ return isLastLeafMatch;
23
+ },
24
+ formatPath: function() {
25
+ return formatPath;
26
+ }
27
+ });
28
+ var _helperJs = require("../generic/helper.js");
29
+ function _arrayLikeToArray(arr, len) {
30
+ if (len == null || len > arr.length) len = arr.length;
31
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
32
+ return arr2;
33
+ }
34
+ function _arrayWithoutHoles(arr) {
35
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
36
+ }
37
+ function _iterableToArray(iter) {
38
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
39
+ }
40
+ function _nonIterableSpread() {
41
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
42
+ }
43
+ function _toConsumableArray(arr) {
44
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
45
+ }
46
+ function _unsupportedIterableToArray(o, minLen) {
47
+ if (!o) return;
48
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
49
+ var n = Object.prototype.toString.call(o).slice(8, -1);
50
+ if (n === "Object" && o.constructor) n = o.constructor.name;
51
+ if (n === "Map" || n === "Set") return Array.from(n);
52
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
53
+ }
54
+ var getUniques = function(searches, key) {
55
+ var result = [];
56
+ for(var i = 0, lenS = searches.length; i < lenS; i += 1){
57
+ var needles = searches[i][key];
58
+ for(var j = 0, lenN = needles.length; j < lenN; j += 1){
59
+ var needle = needles[j];
60
+ if (!result.includes(needle)) {
61
+ result.push(needle);
62
+ }
63
+ }
64
+ }
65
+ return result;
66
+ };
67
+ var matchedBy = function(searches) {
68
+ return getUniques(searches, "leafNeedlesMatch");
69
+ };
70
+ var excludedBy = function(searches) {
71
+ return getUniques(searches, "leafNeedlesExclude");
72
+ };
73
+ var traversedBy = function(searches) {
74
+ return getUniques(searches, "needles");
75
+ };
76
+ var isLastLeafMatch = function(searches) {
77
+ var maxLeafIndex = -1;
78
+ var maxLeafMatch = false;
79
+ var idx = searches.length;
80
+ // eslint-disable-next-line no-plusplus
81
+ while(idx--){
82
+ var _idx = searches[idx], index = _idx.index, match = _idx.match;
83
+ if (index > maxLeafIndex) {
84
+ maxLeafIndex = index;
85
+ maxLeafMatch = match;
86
+ }
87
+ }
88
+ return maxLeafMatch;
89
+ };
90
+ var formatPath = function(input, joined) {
91
+ return joined ? (0, _helperJs.toPath)(input) : _toConsumableArray(input);
92
+ };