@webalternatif/js-core 1.2.1 → 1.3.1
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/cjs/dom.js +229 -43
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/is.js +3 -1
- package/dist/cjs/random.js +14 -9
- package/dist/cjs/string.js +35 -7
- package/dist/cjs/traversal.js +4 -4
- package/dist/esm/dom.js +229 -43
- package/dist/esm/index.js +6 -3
- package/dist/esm/is.js +3 -1
- package/dist/esm/random.js +14 -9
- package/dist/esm/string.js +35 -7
- package/dist/esm/traversal.js +4 -4
- package/package.json +5 -3
- package/types/dom.d.ts +65 -29
- package/types/index.d.ts +49 -14
- package/types/random.d.ts +1 -1
- package/types/string.d.ts +1 -1
- package/types/traversal.d.ts +1 -1
package/dist/cjs/dom.js
CHANGED
|
@@ -4,26 +4,51 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
4
4
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
5
5
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
6
6
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
-
import { isArray, isArrayLike, isObject, isString } from "./is.js";
|
|
7
|
+
import { isArray, isArrayLike, isFunction, isObject, isPlainObject, isString } from "./is.js";
|
|
8
8
|
import { camelCase } from "./string.js";
|
|
9
9
|
import { each, foreach, map } from "./traversal.js";
|
|
10
10
|
import { inArray } from "./array.js";
|
|
11
11
|
var cssNumber = ['animationIterationCount', 'aspectRatio', 'borderImageSlice', 'columnCount', 'flexGrow', 'flexShrink', 'fontWeight', 'gridArea', 'gridColumn', 'gridColumnEnd', 'gridColumnStart', 'gridRow', 'gridRowEnd', 'gridRowStart', 'lineHeight', 'opacity', 'order', 'orphans', 'scale', 'widows', 'zIndex', 'zoom', 'fillOpacity', 'floodOpacity', 'stopOpacity', 'strokeMiterlimit', 'strokeOpacity'];
|
|
12
|
+
var LISTENERS = new WeakMap();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {any} o
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
12
18
|
export var isWindow = function isWindow(o) {
|
|
13
19
|
return !!o && o === o.window;
|
|
14
20
|
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {any} o
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export var isDocument = function isDocument(o) {
|
|
27
|
+
return !!o && o.nodeType === 9;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {any} o
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
15
34
|
export var isDomElement = function isDomElement(o) {
|
|
16
35
|
return isObject(o) && o instanceof HTMLElement;
|
|
17
36
|
};
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {Element} el
|
|
40
|
+
* @param {string} cssRule
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export var getStyle = function getStyle(el, cssRule) {
|
|
44
|
+
if (!isDomElement(el)) {
|
|
20
45
|
return '';
|
|
21
46
|
}
|
|
22
47
|
if (window.getComputedStyle) {
|
|
23
|
-
var computedStyle = window.getComputedStyle(
|
|
48
|
+
var computedStyle = window.getComputedStyle(el, null);
|
|
24
49
|
return computedStyle.getPropertyValue(cssRule) || computedStyle[camelCase(cssRule)] || '';
|
|
25
50
|
}
|
|
26
|
-
return
|
|
51
|
+
return el.style[camelCase(cssRule)] || '';
|
|
27
52
|
};
|
|
28
53
|
export default {
|
|
29
54
|
/**
|
|
@@ -43,16 +68,16 @@ export default {
|
|
|
43
68
|
return this.first(this.children(el, selector));
|
|
44
69
|
},
|
|
45
70
|
/**
|
|
46
|
-
* @param {Element|Document} refEl
|
|
47
|
-
* @param {string|Element|NodeList|Array<Element>}
|
|
48
|
-
* @returns {Element
|
|
71
|
+
* @param {Element|Document|string} refEl
|
|
72
|
+
* @param {string|Element|NodeList|Array<Element>} selector
|
|
73
|
+
* @returns {Element}
|
|
49
74
|
*/
|
|
50
75
|
findOne: function findOne(refEl, selector) {
|
|
51
76
|
var _this$find$;
|
|
52
77
|
return (_this$find$ = this.find(refEl, selector)[0]) !== null && _this$find$ !== void 0 ? _this$find$ : null;
|
|
53
78
|
},
|
|
54
79
|
/**
|
|
55
|
-
* @param {Element|Document} refEl
|
|
80
|
+
* @param {Element|Document|string} refEl
|
|
56
81
|
* @param {string|Element|NodeList|Array<Element>} selector
|
|
57
82
|
* @returns {Array<Element>}
|
|
58
83
|
*/
|
|
@@ -72,7 +97,31 @@ export default {
|
|
|
72
97
|
return null;
|
|
73
98
|
});
|
|
74
99
|
}
|
|
75
|
-
|
|
100
|
+
try {
|
|
101
|
+
return refEl.querySelectorAll(selector);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* @param {Element|string} el
|
|
108
|
+
* @param {string} data
|
|
109
|
+
* @param {string} [value]
|
|
110
|
+
* @returns {Element|null}
|
|
111
|
+
*/
|
|
112
|
+
findOneByData: function findOneByData(el, data, value) {
|
|
113
|
+
var _this$findByData$;
|
|
114
|
+
return (_this$findByData$ = this.findByData(el, data, value)[0]) !== null && _this$findByData$ !== void 0 ? _this$findByData$ : null;
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* @param {Element|string} el
|
|
118
|
+
* @param {string} data
|
|
119
|
+
* @param {string} [value]
|
|
120
|
+
* @returns {Element[]}
|
|
121
|
+
*/
|
|
122
|
+
findByData: function findByData(el, data, value) {
|
|
123
|
+
var escapeValue = CSS.escape(value);
|
|
124
|
+
return this.find(el, "[data-".concat(data, "=\"").concat(escapeValue, "\"]"));
|
|
76
125
|
},
|
|
77
126
|
/**
|
|
78
127
|
* @param {Element|NodeList|Array<Element>} el
|
|
@@ -147,26 +196,38 @@ export default {
|
|
|
147
196
|
},
|
|
148
197
|
/**
|
|
149
198
|
* @param {Node} node
|
|
150
|
-
* @param {...Node} children
|
|
199
|
+
* @param {...(Node|string)} children
|
|
151
200
|
* @returns {Node}
|
|
152
201
|
*/
|
|
153
202
|
append: function append(node) {
|
|
203
|
+
var _this = this;
|
|
154
204
|
for (var _len = arguments.length, children = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
155
205
|
children[_key - 1] = arguments[_key];
|
|
156
206
|
}
|
|
157
|
-
|
|
207
|
+
foreach(children, function (child) {
|
|
208
|
+
if (isString(child)) {
|
|
209
|
+
child = _this.create(child);
|
|
210
|
+
}
|
|
211
|
+
child && node.append(child);
|
|
212
|
+
});
|
|
158
213
|
return node;
|
|
159
214
|
},
|
|
160
215
|
/**
|
|
161
216
|
* @param {Node} node
|
|
162
|
-
* @param {...Node} children
|
|
217
|
+
* @param {...(Node|string)} children
|
|
163
218
|
* @returns {Node}
|
|
164
219
|
*/
|
|
165
220
|
prepend: function prepend(node) {
|
|
221
|
+
var _this2 = this;
|
|
166
222
|
for (var _len2 = arguments.length, children = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
167
223
|
children[_key2 - 1] = arguments[_key2];
|
|
168
224
|
}
|
|
169
|
-
|
|
225
|
+
foreach([].concat(children).reverse(), function (child) {
|
|
226
|
+
if (isString(child)) {
|
|
227
|
+
child = _this2.create(child);
|
|
228
|
+
}
|
|
229
|
+
child && node.prepend(child);
|
|
230
|
+
});
|
|
170
231
|
return node;
|
|
171
232
|
},
|
|
172
233
|
/**
|
|
@@ -174,7 +235,7 @@ export default {
|
|
|
174
235
|
* @returns {void}
|
|
175
236
|
*/
|
|
176
237
|
remove: function remove() {
|
|
177
|
-
var
|
|
238
|
+
var _this3 = this;
|
|
178
239
|
for (var _len3 = arguments.length, els = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
179
240
|
els[_key3] = arguments[_key3];
|
|
180
241
|
}
|
|
@@ -186,13 +247,13 @@ export default {
|
|
|
186
247
|
return e.remove();
|
|
187
248
|
});
|
|
188
249
|
} else {
|
|
189
|
-
|
|
250
|
+
_this3.remove(_this3.find(el));
|
|
190
251
|
}
|
|
191
252
|
});
|
|
192
253
|
},
|
|
193
254
|
/**
|
|
194
255
|
* @param {Element} el
|
|
195
|
-
* @param {string|Element} selector
|
|
256
|
+
* @param {string|Element} [selector]
|
|
196
257
|
* @returns {Element|null}
|
|
197
258
|
*/
|
|
198
259
|
closest: function closest(el, selector) {
|
|
@@ -209,6 +270,9 @@ export default {
|
|
|
209
270
|
}
|
|
210
271
|
return null;
|
|
211
272
|
}
|
|
273
|
+
if (undefined === selector) {
|
|
274
|
+
return el;
|
|
275
|
+
}
|
|
212
276
|
return el.closest(selector);
|
|
213
277
|
},
|
|
214
278
|
/**
|
|
@@ -411,13 +475,13 @@ export default {
|
|
|
411
475
|
* @returns {Element|DOMStringMap}
|
|
412
476
|
*/
|
|
413
477
|
data: function data(el, name, value) {
|
|
414
|
-
var
|
|
478
|
+
var _this4 = this;
|
|
415
479
|
if (undefined === name && undefined === value) {
|
|
416
480
|
return el.dataset;
|
|
417
481
|
}
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
return
|
|
482
|
+
if (isPlainObject(name)) {
|
|
483
|
+
each(name, function (k, v) {
|
|
484
|
+
return _this4.data(el, k, v);
|
|
421
485
|
});
|
|
422
486
|
return el;
|
|
423
487
|
}
|
|
@@ -443,25 +507,95 @@ export default {
|
|
|
443
507
|
},
|
|
444
508
|
/**
|
|
445
509
|
* @param {Element|Document|Window} el
|
|
446
|
-
* @param {string}
|
|
447
|
-
* @param {function}
|
|
448
|
-
* @param {AddEventListenerOptions|
|
|
510
|
+
* @param {string} events
|
|
511
|
+
* @param {string|Element|function} selector
|
|
512
|
+
* @param {function|AddEventListenerOptions|boolean} [handler]
|
|
513
|
+
* @param {AddEventListenerOptions|boolean} [options]
|
|
449
514
|
* @returns {Element}
|
|
450
515
|
*/
|
|
451
|
-
on: function on(el,
|
|
452
|
-
var
|
|
453
|
-
|
|
516
|
+
on: function on(el, events, selector, handler, options) {
|
|
517
|
+
var _this5 = this;
|
|
518
|
+
if (isFunction(selector)) {
|
|
519
|
+
options = handler;
|
|
520
|
+
handler = selector;
|
|
521
|
+
selector = null;
|
|
522
|
+
}
|
|
523
|
+
foreach(events.split(' '), function (event) {
|
|
524
|
+
var listener = function listener(ev) {
|
|
525
|
+
if (!selector) {
|
|
526
|
+
handler.call(el, ev);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
var currentTarget = ev.target;
|
|
530
|
+
while (currentTarget && currentTarget !== el) {
|
|
531
|
+
if (_this5.matches(currentTarget, selector)) {
|
|
532
|
+
var wrappedEv = Object.assign({}, ev, {
|
|
533
|
+
originalEvent: ev,
|
|
534
|
+
type: ev.type,
|
|
535
|
+
currentTarget: currentTarget,
|
|
536
|
+
target: ev.target,
|
|
537
|
+
relatedTarget: ev.relatedTarget,
|
|
538
|
+
button: ev.button,
|
|
539
|
+
pageX: ev.pageX,
|
|
540
|
+
pageY: ev.pageY,
|
|
541
|
+
preventDefault: function preventDefault() {
|
|
542
|
+
return ev.preventDefault.apply(ev, arguments);
|
|
543
|
+
},
|
|
544
|
+
stopPropagation: function stopPropagation() {
|
|
545
|
+
return ev.stopPropagation.apply(ev, arguments);
|
|
546
|
+
},
|
|
547
|
+
stopImmediatePropagation: function stopImmediatePropagation() {
|
|
548
|
+
return ev.stopImmediatePropagation.apply(ev, arguments);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
handler.call(currentTarget, wrappedEv);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
currentTarget = currentTarget.parentElement;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
var store = LISTENERS.get(el);
|
|
558
|
+
if (!store) {
|
|
559
|
+
store = [];
|
|
560
|
+
LISTENERS.set(el, store);
|
|
561
|
+
}
|
|
562
|
+
store.push({
|
|
563
|
+
event: event,
|
|
564
|
+
handler: handler,
|
|
565
|
+
selector: selector,
|
|
566
|
+
listener: listener,
|
|
567
|
+
options: options
|
|
568
|
+
});
|
|
569
|
+
el.addEventListener(event, listener, options);
|
|
570
|
+
});
|
|
454
571
|
return el;
|
|
455
572
|
},
|
|
456
573
|
/**
|
|
457
574
|
* @param {Element|Document|Window} el
|
|
458
|
-
* @param {string}
|
|
459
|
-
* @param {function}
|
|
460
|
-
* @param {
|
|
575
|
+
* @param {string} [events]
|
|
576
|
+
* @param {string|Element|function} selector
|
|
577
|
+
* @param {function|AddEventListenerOptions|boolean} [handler]
|
|
578
|
+
* @param {AddEventListenerOptions|boolean} [options]
|
|
461
579
|
* @returns {Element}
|
|
462
580
|
*/
|
|
463
|
-
off: function off(el,
|
|
464
|
-
|
|
581
|
+
off: function off(el, events, selector, handler, options) {
|
|
582
|
+
if (isFunction(selector)) {
|
|
583
|
+
options = handler;
|
|
584
|
+
handler = selector;
|
|
585
|
+
selector = null;
|
|
586
|
+
}
|
|
587
|
+
var store = LISTENERS.get(el);
|
|
588
|
+
if (!store) return el;
|
|
589
|
+
var evts = events ? events.split(' ') : [undefined];
|
|
590
|
+
foreach(evts.split(' '), function (event) {
|
|
591
|
+
each(_toConsumableArray(store).reverse(), function (i, l) {
|
|
592
|
+
if ((undefined === event || l.event === event) && (undefined === handler || l.handler === handler) && (undefined === selector || l.selector === selector) && (undefined === options || l.options === options)) {
|
|
593
|
+
el.removeEventListener(event, l.listener, l.options);
|
|
594
|
+
var index = store.indexOf(l);
|
|
595
|
+
index !== -1 && store.splice(index, 1);
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
});
|
|
465
599
|
return el;
|
|
466
600
|
},
|
|
467
601
|
/**
|
|
@@ -471,7 +605,7 @@ export default {
|
|
|
471
605
|
* @returns {Element}
|
|
472
606
|
*/
|
|
473
607
|
css: function css(el, style, value) {
|
|
474
|
-
var
|
|
608
|
+
var _this6 = this;
|
|
475
609
|
if (isString(style)) {
|
|
476
610
|
var prop = style.startsWith('--') ? style : camelCase(style);
|
|
477
611
|
if (undefined === value) {
|
|
@@ -485,7 +619,7 @@ export default {
|
|
|
485
619
|
}
|
|
486
620
|
} else {
|
|
487
621
|
each(style, function (name, v) {
|
|
488
|
-
|
|
622
|
+
_this6.css(el, name, v);
|
|
489
623
|
});
|
|
490
624
|
}
|
|
491
625
|
return el;
|
|
@@ -521,16 +655,18 @@ export default {
|
|
|
521
655
|
* @returns {Element|null}
|
|
522
656
|
*/
|
|
523
657
|
first: function first(nodeList) {
|
|
658
|
+
var _Array$from$;
|
|
524
659
|
if (nodeList instanceof Element) return nodeList;
|
|
525
|
-
return
|
|
660
|
+
return (_Array$from$ = Array.from(nodeList)[0]) !== null && _Array$from$ !== void 0 ? _Array$from$ : null;
|
|
526
661
|
},
|
|
527
662
|
/**
|
|
528
663
|
* @param {NodeList|Array<Element>} nodeList
|
|
529
664
|
* @returns {Element|null}
|
|
530
665
|
*/
|
|
531
666
|
last: function last(nodeList) {
|
|
532
|
-
var
|
|
533
|
-
|
|
667
|
+
var _arr;
|
|
668
|
+
var arr = Array.from(nodeList);
|
|
669
|
+
return (_arr = arr[arr.length - 1]) !== null && _arr !== void 0 ? _arr : null;
|
|
534
670
|
},
|
|
535
671
|
/**
|
|
536
672
|
* @param {string} html
|
|
@@ -543,32 +679,42 @@ export default {
|
|
|
543
679
|
return (_tpl$content$firstEle = tpl.content.firstElementChild) !== null && _tpl$content$firstEle !== void 0 ? _tpl$content$firstEle : null;
|
|
544
680
|
},
|
|
545
681
|
/**
|
|
546
|
-
* @param {NodeList} nodeList
|
|
682
|
+
* @param {NodeList|Array<Element>} nodeList
|
|
547
683
|
* @param {number} [index=0]
|
|
548
684
|
* @returns {Element|null}
|
|
549
685
|
*/
|
|
550
686
|
eq: function eq(nodeList) {
|
|
687
|
+
var _nodeList$index;
|
|
551
688
|
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
689
|
+
nodeList = Array.from(nodeList);
|
|
552
690
|
if (Math.abs(index) >= nodeList.length) return null;
|
|
553
691
|
if (index < 0) {
|
|
554
692
|
index = nodeList.length + index;
|
|
555
693
|
}
|
|
556
|
-
return
|
|
694
|
+
return (_nodeList$index = nodeList[index]) !== null && _nodeList$index !== void 0 ? _nodeList$index : null;
|
|
557
695
|
},
|
|
558
696
|
/**
|
|
559
697
|
* @param {Element} el
|
|
560
|
-
* @param {Element} newEl
|
|
561
|
-
* @returns {Element}
|
|
698
|
+
* @param {Element|string} newEl
|
|
699
|
+
* @returns {Element|null}
|
|
562
700
|
*/
|
|
563
701
|
after: function after(el, newEl) {
|
|
702
|
+
if (!el.parentElement) return null;
|
|
703
|
+
if (isString(newEl)) {
|
|
704
|
+
newEl = this.create(newEl);
|
|
705
|
+
}
|
|
564
706
|
return el.parentElement.insertBefore(newEl, el.nextElementSibling);
|
|
565
707
|
},
|
|
566
708
|
/**
|
|
567
709
|
* @param {Element} el
|
|
568
|
-
* @param {Element} newEl
|
|
569
|
-
* @returns {Element}
|
|
710
|
+
* @param {Element|string} newEl
|
|
711
|
+
* @returns {Element|null}
|
|
570
712
|
*/
|
|
571
713
|
before: function before(el, newEl) {
|
|
714
|
+
if (!el.parentElement) return null;
|
|
715
|
+
if (isString(newEl)) {
|
|
716
|
+
newEl = this.create(newEl);
|
|
717
|
+
}
|
|
572
718
|
return el.parentElement.insertBefore(newEl, el);
|
|
573
719
|
},
|
|
574
720
|
/**
|
|
@@ -594,6 +740,23 @@ export default {
|
|
|
594
740
|
return selectorIsString ? !e.matches(selector) : e !== selector;
|
|
595
741
|
});
|
|
596
742
|
},
|
|
743
|
+
/**
|
|
744
|
+
* @param {Element} elem1
|
|
745
|
+
* @param {Element} elem2
|
|
746
|
+
* @returns {boolean}
|
|
747
|
+
*/
|
|
748
|
+
collide: function collide(elem1, elem2) {
|
|
749
|
+
var rect1 = elem1.getBoundingClientRect();
|
|
750
|
+
var rect2 = elem2.getBoundingClientRect();
|
|
751
|
+
return rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.y + rect1.height > rect2.y;
|
|
752
|
+
},
|
|
753
|
+
/**
|
|
754
|
+
* @param {Element} el
|
|
755
|
+
* @param {string|Element} selector
|
|
756
|
+
*/
|
|
757
|
+
matches: function matches(el, selector) {
|
|
758
|
+
return selector instanceof Element ? selector === el : el.matches(selector);
|
|
759
|
+
},
|
|
597
760
|
/**
|
|
598
761
|
* @param {Element} el
|
|
599
762
|
* @param {Element} child
|
|
@@ -613,5 +776,28 @@ export default {
|
|
|
613
776
|
}
|
|
614
777
|
el.replaceChildren.apply(el, children);
|
|
615
778
|
return el;
|
|
779
|
+
},
|
|
780
|
+
/**
|
|
781
|
+
* @param {Element|Document|Window} el
|
|
782
|
+
* @returns {{top: number, left: number}}
|
|
783
|
+
*/
|
|
784
|
+
offset: function offset(el) {
|
|
785
|
+
if (isWindow(el)) {
|
|
786
|
+
return {
|
|
787
|
+
top: el.scrollY,
|
|
788
|
+
left: el.scrollX
|
|
789
|
+
};
|
|
790
|
+
} else if (isDocument(el)) {
|
|
791
|
+
return {
|
|
792
|
+
top: el.documentElement.scrollTop,
|
|
793
|
+
left: el.documentElement.scrollLeft
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
var rect = el.getBoundingClientRect();
|
|
797
|
+
var wOffset = this.offset(window);
|
|
798
|
+
return {
|
|
799
|
+
top: rect.top + wOffset.top,
|
|
800
|
+
left: rect.left + wOffset.left
|
|
801
|
+
};
|
|
616
802
|
}
|
|
617
803
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -7,19 +7,22 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
7
7
|
import * as stringFunctions from './string.js';
|
|
8
8
|
import './stringPrototype.js';
|
|
9
9
|
import * as arrayFunctions from './array.js';
|
|
10
|
+
import * as is from './is.js';
|
|
11
|
+
import * as random from './random.js';
|
|
10
12
|
import * as traversal from './traversal.js';
|
|
11
|
-
import dom, { getStyle, isDomElement, isWindow } from './dom.js';
|
|
13
|
+
import dom, { getStyle, isDomElement, isWindow, isDocument } from './dom.js';
|
|
12
14
|
import * as math from './math.js';
|
|
13
15
|
import * as utils from './utils.js';
|
|
14
16
|
import * as i18n from './i18n.js';
|
|
15
17
|
import eventDispatcher from './eventDispatcher.js';
|
|
16
|
-
var webf = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, stringFunctions), arrayFunctions), traversal), {}, {
|
|
18
|
+
var webf = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, stringFunctions), arrayFunctions), traversal), is), random), {}, {
|
|
17
19
|
dom: dom,
|
|
18
20
|
isWindow: isWindow,
|
|
21
|
+
isDocument: isDocument,
|
|
19
22
|
isDomElement: isDomElement,
|
|
20
23
|
getStyle: getStyle
|
|
21
24
|
}, math), utils), i18n), {}, {
|
|
22
25
|
eventDispatcher: eventDispatcher
|
|
23
26
|
});
|
|
24
27
|
export default webf;
|
|
25
|
-
export { stringFunctions, arrayFunctions, traversal, getStyle, dom, math, utils, eventDispatcher };
|
|
28
|
+
export { stringFunctions, arrayFunctions, traversal, is, random, getStyle, dom, math, utils, eventDispatcher };
|
package/dist/cjs/is.js
CHANGED
|
@@ -24,7 +24,9 @@ export var isUndefined = function isUndefined(v) {
|
|
|
24
24
|
return typeof v === 'undefined';
|
|
25
25
|
};
|
|
26
26
|
export var isArrayLike = function isArrayLike(o) {
|
|
27
|
-
return
|
|
27
|
+
return !!o && !isString(o) && !isFunction(o) && isInt(o.length)
|
|
28
|
+
// && o.length >= 0
|
|
29
|
+
&& Number.isFinite(o.length);
|
|
28
30
|
};
|
|
29
31
|
export var isArray = function isArray(a) {
|
|
30
32
|
return Array.isArray(a);
|
package/dist/cjs/random.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
export var uniqid = function uniqid() {
|
|
2
|
-
return randAlpha(10);
|
|
3
|
-
};
|
|
4
1
|
export var randAlpha = function randAlpha(n) {
|
|
5
|
-
return rand("
|
|
2
|
+
return rand("abcdefghijklmnopqrstuvwxyz".split(''), n);
|
|
6
3
|
};
|
|
7
4
|
export var randAlphaCs = function randAlphaCs(n) {
|
|
8
|
-
return rand("
|
|
5
|
+
return rand("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''), n);
|
|
9
6
|
};
|
|
10
7
|
export var randAlphaNum = function randAlphaNum(n) {
|
|
11
|
-
return rand("
|
|
8
|
+
return rand("0123456789abcdefghijklmnopqrstuvwxyz".split(''), n);
|
|
12
9
|
};
|
|
13
10
|
export var randAlphaNumCs = function randAlphaNumCs(n) {
|
|
14
|
-
return rand("
|
|
11
|
+
return rand("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''), n);
|
|
15
12
|
};
|
|
16
13
|
export var randNum = function randNum(n) {
|
|
17
|
-
return rand("
|
|
14
|
+
return rand("0123456789".split(''), n);
|
|
18
15
|
};
|
|
19
16
|
export var rand = function rand(range, n) {
|
|
20
17
|
var rand = "";
|
|
@@ -22,4 +19,12 @@ export var rand = function rand(range, n) {
|
|
|
22
19
|
rand += range[Math.floor(Math.random() * 1000) % range.length];
|
|
23
20
|
}
|
|
24
21
|
return rand;
|
|
25
|
-
};
|
|
22
|
+
};
|
|
23
|
+
export var uniqid = function () {
|
|
24
|
+
var uid = 0;
|
|
25
|
+
return function () {
|
|
26
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
27
|
+
uid++;
|
|
28
|
+
return "".concat(prefix).concat(Date.now().toString(36), "_").concat(uid.toString(36), "_").concat(randAlphaNum(5));
|
|
29
|
+
};
|
|
30
|
+
}();
|
package/dist/cjs/string.js
CHANGED
|
@@ -318,13 +318,41 @@ export var escapeRegex = function escapeRegex(str) {
|
|
|
318
318
|
return str.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&").replace(/[\n\t]/g, " ");
|
|
319
319
|
};
|
|
320
320
|
export var camelCase = function camelCase(str) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
321
|
+
if (!str) return '';
|
|
322
|
+
var prev = '';
|
|
323
|
+
var prevReplaced = false;
|
|
324
|
+
var prevIsSeparator = false;
|
|
325
|
+
var prevIsUpperCase = false;
|
|
326
|
+
str = trim(str);
|
|
327
|
+
str = trim(str, '_');
|
|
328
|
+
str = trim(str, '-');
|
|
329
|
+
var isUpperCase = function isUpperCase(c) {
|
|
330
|
+
return c === c.toUpperCase() && c !== c.toLowerCase();
|
|
331
|
+
};
|
|
332
|
+
var isSeparator = function isSeparator(c) {
|
|
333
|
+
return c === '-' || c === '_' || c === ' ';
|
|
334
|
+
};
|
|
335
|
+
return map(str, function (i, c) {
|
|
336
|
+
prevIsSeparator = isSeparator(prev);
|
|
337
|
+
prevIsUpperCase = isUpperCase(prev);
|
|
338
|
+
prev = c;
|
|
339
|
+
if (isSeparator(c)) {
|
|
340
|
+
return null;
|
|
341
|
+
} else if (prevIsSeparator) {
|
|
342
|
+
c = c.toUpperCase();
|
|
343
|
+
prevReplaced = true;
|
|
344
|
+
} else if (isUpperCase(c)) {
|
|
345
|
+
if (i === 0) {
|
|
346
|
+
c = c.toLowerCase();
|
|
347
|
+
} else if (prevIsUpperCase && !prevReplaced) {
|
|
348
|
+
c = c.toLowerCase();
|
|
349
|
+
}
|
|
350
|
+
prevReplaced = false;
|
|
351
|
+
} else {
|
|
352
|
+
prevReplaced = false;
|
|
353
|
+
}
|
|
354
|
+
return c;
|
|
355
|
+
}).join('');
|
|
328
356
|
};
|
|
329
357
|
export var format = function format(str) {
|
|
330
358
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
package/dist/cjs/traversal.js
CHANGED
|
@@ -36,7 +36,7 @@ export var each = function each(o, callback, context) {
|
|
|
36
36
|
var arr = o.split('');
|
|
37
37
|
for (var _i = 0; _i < arr.length; _i++) if (false === callback.call(context !== null && context !== void 0 ? context : arr[_i], _i, arr[_i], o, _i)) return;
|
|
38
38
|
return o;
|
|
39
|
-
} else if (o instanceof Map) {
|
|
39
|
+
} else if (o instanceof Map || o instanceof WeakMap) {
|
|
40
40
|
var _index = 0;
|
|
41
41
|
var _iterator = _createForOfIteratorHelper(o.entries()),
|
|
42
42
|
_step;
|
|
@@ -68,8 +68,8 @@ export var each = function each(o, callback, context) {
|
|
|
68
68
|
_iterator2.f();
|
|
69
69
|
}
|
|
70
70
|
} else if (isArrayLike(o)) {
|
|
71
|
-
|
|
72
|
-
for (var _i2 = 0; _i2 <
|
|
71
|
+
var _arr = Array.from(o);
|
|
72
|
+
for (var _i2 = 0; _i2 < _arr.length; _i2++) if (false === callback.call(context || _arr[_i2], _i2, _arr[_i2], _arr, _i2)) return;
|
|
73
73
|
}
|
|
74
74
|
return o;
|
|
75
75
|
};
|
|
@@ -105,7 +105,7 @@ export var foreach = function foreach(o, callback, context) {
|
|
|
105
105
|
* @param {Collection<T>} o
|
|
106
106
|
* @param {(key: number|string, value: T, o: Collection<T>, index: number) => (R|null|false)} callback
|
|
107
107
|
* @param {any} [context] Optional "this" binding for the callback
|
|
108
|
-
* @returns {Array} Returns the resulted array
|
|
108
|
+
* @returns {Array<R>} Returns the resulted array
|
|
109
109
|
*/
|
|
110
110
|
export var map = function map(o, callback, context) {
|
|
111
111
|
var results = [];
|