miscUtil.js
1.49 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.leftPad = leftPad;
exports.toArray = toArray;
exports.default = getDataOrAriaProps;
exports.getValue = getValue;
exports.updateValues = updateValues;
exports.tuple = void 0;
function leftPad(str, length) {
var fill = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
var current = String(str);
while (current.length < length) {
current = "".concat(fill).concat(str);
}
return current;
}
var tuple = function tuple() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return args;
};
exports.tuple = tuple;
function toArray(val) {
if (val === null || val === undefined) {
return [];
}
return Array.isArray(val) ? val : [val];
}
function getDataOrAriaProps(props) {
var retProps = {};
Object.keys(props).forEach(function (key) {
if ((key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role' || key === 'name') && key.substr(0, 7) !== 'data-__') {
retProps[key] = props[key];
}
});
return retProps;
}
function getValue(values, index) {
return values ? values[index] : null;
}
function updateValues(values, value, index) {
var newValues = [getValue(values, 0), getValue(values, 1)];
newValues[index] = typeof value === 'function' ? value(newValues[index]) : value;
if (!newValues[0] && !newValues[1]) {
return null;
}
return newValues;
}