@bbn/bbn 1.0.350 → 1.0.352
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/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/fn/html/getIndex.d.ts +5 -0
- package/dist/fn/html/getIndex.js +17 -0
- package/dist/fn/object/getField.d.ts +30 -28
- package/dist/fn/object/getField.js +42 -30
- package/dist/fn/object/getRow.d.ts +5 -3
- package/dist/fn/object/getRow.js +12 -5
- package/dist/fn/object/search.d.ts +2 -2
- package/dist/fn/object/search.js +12 -11
- package/dist/fn.d.ts +2 -0
- package/dist/fn.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets all the tag names present in the DOM
|
|
3
|
+
* @returns array
|
|
4
|
+
*/
|
|
5
|
+
export default function getIndex(element, selector) {
|
|
6
|
+
if (selector === void 0) { selector = ''; }
|
|
7
|
+
if (!element.parentElement) {
|
|
8
|
+
return -1; // Element has no parent, return -1
|
|
9
|
+
}
|
|
10
|
+
if (!selector) {
|
|
11
|
+
Array.from(element.parentElement.children).indexOf(element);
|
|
12
|
+
}
|
|
13
|
+
var siblings = Array.from(element.parentElement.children);
|
|
14
|
+
var filteredSiblings = siblings.filter(function (el) { return el.matches(selector); });
|
|
15
|
+
return filteredSiblings.indexOf(element);
|
|
16
|
+
}
|
|
17
|
+
;
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
* Returns the value of the given field (property) from the first object matching the given filter in an array of objects.
|
|
3
|
+
*
|
|
4
|
+
* The filtering arguments follow the same scheme as bbn.fn.search.
|
|
5
|
+
*
|
|
6
|
+
* @method getField
|
|
7
|
+
* @global
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* let ar = [
|
|
11
|
+
* {name: "Raiders of the lost ark", director: "Steven Spielberg", year: 1981, id: 589},
|
|
12
|
+
* {name: "Goonies", director: "Richard Donner", year: 1985, id: 689},
|
|
13
|
+
* {name: "Star wars", director: "George Lucas", year: 1977, id: 256},
|
|
14
|
+
* {name: "Jaws", director: "Steven Spielberg", year: 1975, id: 423}
|
|
15
|
+
* ];
|
|
16
|
+
* bbn.fn.getField(ar, "name", {id: 256});
|
|
17
|
+
* // Star wars
|
|
18
|
+
* bbn.fn.getField(ar, "name", "id", 689);
|
|
19
|
+
* // Goonies
|
|
20
|
+
* ```
|
|
21
|
+
* @memberof bbn.fn
|
|
22
|
+
* @param {Array} arr The subject array
|
|
23
|
+
* @param {String} field The property from which the value is returned
|
|
24
|
+
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
25
|
+
* @param {*} val The value with which comparing the given property
|
|
26
|
+
* @param {String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
27
|
+
* @param {Number|false} from The index to start from, if false the search starts from the end
|
|
28
|
+
* @param {Boolean} backward Searches backward
|
|
29
|
+
* @returns {*}
|
|
30
|
+
*/
|
|
31
|
+
export default function getField(arr: any[], field: string, prop?: object | string, val?: any, operator?: string, from?: boolean | number, backward?: any, notFound?: any): any;
|
|
@@ -1,40 +1,52 @@
|
|
|
1
1
|
import getRow from './getRow.js';
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
* Returns the value of the given field (property) from the first object matching the given filter in an array of objects.
|
|
4
|
+
*
|
|
5
|
+
* The filtering arguments follow the same scheme as bbn.fn.search.
|
|
6
|
+
*
|
|
7
|
+
* @method getField
|
|
8
|
+
* @global
|
|
9
|
+
* @example
|
|
10
|
+
* ```javascript
|
|
11
|
+
* let ar = [
|
|
12
|
+
* {name: "Raiders of the lost ark", director: "Steven Spielberg", year: 1981, id: 589},
|
|
13
|
+
* {name: "Goonies", director: "Richard Donner", year: 1985, id: 689},
|
|
14
|
+
* {name: "Star wars", director: "George Lucas", year: 1977, id: 256},
|
|
15
|
+
* {name: "Jaws", director: "Steven Spielberg", year: 1975, id: 423}
|
|
16
|
+
* ];
|
|
17
|
+
* bbn.fn.getField(ar, "name", {id: 256});
|
|
18
|
+
* // Star wars
|
|
19
|
+
* bbn.fn.getField(ar, "name", "id", 689);
|
|
20
|
+
* // Goonies
|
|
21
|
+
* ```
|
|
22
|
+
* @memberof bbn.fn
|
|
23
|
+
* @param {Array} arr The subject array
|
|
24
|
+
* @param {String} field The property from which the value is returned
|
|
25
|
+
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
26
|
+
* @param {*} val The value with which comparing the given property
|
|
27
|
+
* @param {String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
28
|
+
* @param {Number|false} from The index to start from, if false the search starts from the end
|
|
29
|
+
* @param {Boolean} backward Searches backward
|
|
30
|
+
* @returns {*}
|
|
31
|
+
*/
|
|
32
|
+
export default function getField(arr, field, prop, val, operator, from, backward, notFound) {
|
|
31
33
|
if (prop === void 0) { prop = ''; }
|
|
32
34
|
if (val === void 0) { val = null; }
|
|
33
35
|
if (operator === void 0) { operator = '='; }
|
|
36
|
+
if (from === void 0) { from = 0; }
|
|
37
|
+
if (backward === void 0) { backward = false; }
|
|
38
|
+
if (notFound === void 0) { notFound = undefined; }
|
|
34
39
|
var r;
|
|
35
|
-
if (
|
|
40
|
+
if (prop && ['object', 'function'].includes(typeof prop) && (6 in arguments)) {
|
|
41
|
+
notFound = backward;
|
|
42
|
+
}
|
|
43
|
+
if (field) {
|
|
44
|
+
r = getRow(arr, prop, val, operator, from, backward, undefined);
|
|
45
|
+
if (r === undefined) {
|
|
46
|
+
return notFound;
|
|
47
|
+
}
|
|
36
48
|
return r[field];
|
|
37
49
|
}
|
|
38
|
-
return
|
|
50
|
+
return notFound;
|
|
39
51
|
}
|
|
40
52
|
;
|
|
@@ -36,7 +36,9 @@
|
|
|
36
36
|
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
37
37
|
* @param {*} val The value with which comparing the given property
|
|
38
38
|
* @param {Number|false|String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
39
|
-
* @param {Number|
|
|
40
|
-
* @
|
|
39
|
+
* @param {Number|Boolean} from The index to start from, if false the search starts from the end
|
|
40
|
+
* @param {*} backward Searches backward
|
|
41
|
+
* @param {*} notFound Value to return when not found
|
|
42
|
+
* @returns {*} The item if found, false otherwise
|
|
41
43
|
*/
|
|
42
|
-
export default function getRow(arr: any[], prop: object | string, val?: any, operator?: number |
|
|
44
|
+
export default function getRow(arr: any[], prop: object | string, val?: any, operator?: number | string, from?: boolean | number, backward?: any, notFound?: any): any | false;
|
package/dist/fn/object/getRow.js
CHANGED
|
@@ -37,17 +37,24 @@ import search from './search.js';
|
|
|
37
37
|
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
38
38
|
* @param {*} val The value with which comparing the given property
|
|
39
39
|
* @param {Number|false|String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
40
|
-
* @param {Number|
|
|
41
|
-
* @
|
|
40
|
+
* @param {Number|Boolean} from The index to start from, if false the search starts from the end
|
|
41
|
+
* @param {*} backward Searches backward
|
|
42
|
+
* @param {*} notFound Value to return when not found
|
|
43
|
+
* @returns {*} The item if found, false otherwise
|
|
42
44
|
*/
|
|
43
|
-
export default function getRow(arr, prop, val, operator, from) {
|
|
45
|
+
export default function getRow(arr, prop, val, operator, from, backward, notFound) {
|
|
44
46
|
if (val === void 0) { val = null; }
|
|
45
47
|
if (operator === void 0) { operator = '='; }
|
|
46
48
|
if (from === void 0) { from = 0; }
|
|
47
|
-
|
|
49
|
+
if (backward === void 0) { backward = false; }
|
|
50
|
+
if (notFound === void 0) { notFound = false; }
|
|
51
|
+
var idx = search(arr, prop, val, operator, from, backward);
|
|
48
52
|
if (idx > -1) {
|
|
49
53
|
return arr[idx];
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
if (prop && ['object', 'function'].includes(typeof prop) && (5 in arguments)) {
|
|
56
|
+
return backward;
|
|
57
|
+
}
|
|
58
|
+
return notFound;
|
|
52
59
|
}
|
|
53
60
|
;
|
|
@@ -94,7 +94,7 @@ import { Filter } from './filterToConditions.js';
|
|
|
94
94
|
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
95
95
|
* @param {*} val The value with which comparing the given property
|
|
96
96
|
* @param {String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
97
|
-
* @param {Number
|
|
97
|
+
* @param {Number} startFrom The index from which the search should start
|
|
98
98
|
* @returns {Number} The index if found, otherwise -1
|
|
99
99
|
*/
|
|
100
|
-
export default function search(arr: any[], prop: Filter | object | string | ((a: any, i: string | number | symbol) => boolean), val?: any, operator?: number |
|
|
100
|
+
export default function search(arr: any[], prop: Filter | object | string | ((a: any, i: string | number | symbol) => boolean), val?: any, operator?: number | string, startFrom?: boolean | number, backward?: boolean): number;
|
package/dist/fn/object/search.js
CHANGED
|
@@ -3,6 +3,7 @@ import compareConditions from './compareConditions.js';
|
|
|
3
3
|
import { filterToConditions } from './filterToConditions.js';
|
|
4
4
|
import isObject from '../type/isObject.js';
|
|
5
5
|
import numProperties from './numProperties.js';
|
|
6
|
+
import isNumber from '../type/isNumber.js';
|
|
6
7
|
/**
|
|
7
8
|
* Retrieves the index of the array's first element corresponding to the given filter.
|
|
8
9
|
*
|
|
@@ -98,13 +99,14 @@ import numProperties from './numProperties.js';
|
|
|
98
99
|
* @param {(String|Object|Function)} prop A property's name or a filter object or function
|
|
99
100
|
* @param {*} val The value with which comparing the given property
|
|
100
101
|
* @param {String} operator The operator to use for comparison with the value as used in bbn.fn.compare
|
|
101
|
-
* @param {Number
|
|
102
|
+
* @param {Number} startFrom The index from which the search should start
|
|
102
103
|
* @returns {Number} The index if found, otherwise -1
|
|
103
104
|
*/
|
|
104
|
-
export default function search(arr, prop, val, operator, startFrom) {
|
|
105
|
+
export default function search(arr, prop, val, operator, startFrom, backward) {
|
|
105
106
|
if (val === void 0) { val = null; }
|
|
106
107
|
if (operator === void 0) { operator = '='; }
|
|
107
108
|
if (startFrom === void 0) { startFrom = 0; }
|
|
109
|
+
if (backward === void 0) { backward = false; }
|
|
108
110
|
if (!isIterable(arr)) {
|
|
109
111
|
throw new Error(bbn._('The first argument for a search should be iterable') + ' ' + typeof arr + ' ' + bbn._('given'));
|
|
110
112
|
}
|
|
@@ -140,7 +142,8 @@ export default function search(arr, prop, val, operator, startFrom) {
|
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
144
|
else {
|
|
143
|
-
|
|
145
|
+
backward = startFrom === true ? true : false;
|
|
146
|
+
startFrom = typeof (operator) === 'number' ? operator : (backward ? arr.length - 1 : 0);
|
|
144
147
|
operator = val;
|
|
145
148
|
if (isObject(prop)) {
|
|
146
149
|
filter = prop;
|
|
@@ -151,17 +154,15 @@ export default function search(arr, prop, val, operator, startFrom) {
|
|
|
151
154
|
}
|
|
152
155
|
}
|
|
153
156
|
if (isFn || (isObject(filter) && numProperties(filter))) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
startFrom = operator;
|
|
157
|
+
if (isNumber(operator)) {
|
|
158
|
+
startFrom = typeof (operator) === 'number' ? operator : 0;
|
|
157
159
|
operator = undefined;
|
|
158
160
|
}
|
|
159
|
-
if (startFrom
|
|
160
|
-
startFrom = arr.length - 1;
|
|
161
|
-
dir = 'desc';
|
|
161
|
+
if (typeof startFrom !== 'number') {
|
|
162
|
+
startFrom = backward ? arr.length - 1 : 0;
|
|
162
163
|
}
|
|
163
164
|
if (typeof filter === 'function') {
|
|
164
|
-
if (
|
|
165
|
+
if (backward) {
|
|
165
166
|
for (var i = startFrom; i >= 0; i--) {
|
|
166
167
|
if (filter(arr[i])) {
|
|
167
168
|
return i;
|
|
@@ -178,7 +179,7 @@ export default function search(arr, prop, val, operator, startFrom) {
|
|
|
178
179
|
}
|
|
179
180
|
else {
|
|
180
181
|
filter = filterToConditions(filter);
|
|
181
|
-
if (
|
|
182
|
+
if (backward) {
|
|
182
183
|
for (var i = startFrom; i >= 0; i--) {
|
|
183
184
|
if (compareConditions(arr[i], filter)) {
|
|
184
185
|
return i;
|
package/dist/fn.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ import getDeviceType from './fn/browser/getDeviceType.js';
|
|
|
100
100
|
import getEventData from './fn/browser/getEventData.js';
|
|
101
101
|
import getField from './fn/object/getField.js';
|
|
102
102
|
import getFieldValues from './fn/object/getFieldValues.js';
|
|
103
|
+
import getIndex from './fn/html/getIndex.js';
|
|
103
104
|
import getHtml from './fn/html/getHtml.js';
|
|
104
105
|
import getHTMLOfSelection from './fn/html/getHTMLOfSelection.js';
|
|
105
106
|
import getLoader from './fn/ajax/getLoader.js';
|
|
@@ -340,6 +341,7 @@ declare const _default: {
|
|
|
340
341
|
getEventData: typeof getEventData;
|
|
341
342
|
getField: typeof getField;
|
|
342
343
|
getFieldValues: typeof getFieldValues;
|
|
344
|
+
getIndex: typeof getIndex;
|
|
343
345
|
getHtml: typeof getHtml;
|
|
344
346
|
getHTMLOfSelection: typeof getHTMLOfSelection;
|
|
345
347
|
getLoader: typeof getLoader;
|
package/dist/fn.js
CHANGED
|
@@ -100,6 +100,7 @@ import getDeviceType from './fn/browser/getDeviceType.js';
|
|
|
100
100
|
import getEventData from './fn/browser/getEventData.js';
|
|
101
101
|
import getField from './fn/object/getField.js';
|
|
102
102
|
import getFieldValues from './fn/object/getFieldValues.js';
|
|
103
|
+
import getIndex from './fn/html/getIndex.js';
|
|
103
104
|
import getHtml from './fn/html/getHtml.js';
|
|
104
105
|
import getHTMLOfSelection from './fn/html/getHTMLOfSelection.js';
|
|
105
106
|
import getLoader from './fn/ajax/getLoader.js';
|
|
@@ -340,6 +341,7 @@ export default {
|
|
|
340
341
|
getEventData: getEventData,
|
|
341
342
|
getField: getField,
|
|
342
343
|
getFieldValues: getFieldValues,
|
|
344
|
+
getIndex: getIndex,
|
|
343
345
|
getHtml: getHtml,
|
|
344
346
|
getHTMLOfSelection: getHTMLOfSelection,
|
|
345
347
|
getLoader: getLoader,
|