@webalternatif/js-core 1.1.1 → 1.1.2
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 +173 -74
- package/dist/cjs/is.js +5 -1
- package/dist/cjs/traversal.js +117 -25
- package/dist/esm/array.js +24 -35
- package/dist/esm/dom.js +185 -95
- package/dist/esm/eventDispatcher.js +15 -21
- package/dist/esm/i18n.js +11 -21
- package/dist/esm/index.js +16 -47
- package/dist/esm/is.js +22 -38
- package/dist/esm/math.js +21 -33
- package/dist/esm/random.js +8 -21
- package/dist/esm/string.js +74 -113
- package/dist/esm/stringPrototype.js +3 -6
- package/dist/esm/traversal.js +139 -59
- package/dist/esm/utils.js +14 -27
- package/package.json +1 -1
- package/types/dom.d.ts +53 -35
- package/types/index.d.ts +22 -19
- package/types/is.d.ts +1 -0
- package/types/traversal.d.ts +10 -7
package/dist/esm/utils.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.throttle = exports.strParseFloat = exports.sizeOf = exports.noop = exports.flatten = exports.equals = exports.debounce = void 0;
|
|
7
|
-
var _traversal = require("./traversal.js");
|
|
8
|
-
var _is = require("./is.js");
|
|
9
|
-
const equals = function (o1, o2, seen = new WeakMap()) {
|
|
1
|
+
import { each, map } from "./traversal.js";
|
|
2
|
+
import { isArray, isFunction, isObject, isUndefined } from "./is.js";
|
|
3
|
+
export const equals = function (o1, o2, seen = new WeakMap()) {
|
|
10
4
|
if (o1 === o2) return true;
|
|
11
5
|
if (typeof o1 !== typeof o2 || o1 == null || o2 == null) {
|
|
12
6
|
return false;
|
|
13
7
|
}
|
|
14
|
-
if (
|
|
8
|
+
if (isObject(o1)) {
|
|
15
9
|
if (seen.has(o1)) {
|
|
16
10
|
return seen.get(o1) === o2;
|
|
17
11
|
}
|
|
@@ -25,11 +19,9 @@ const equals = function (o1, o2, seen = new WeakMap()) {
|
|
|
25
19
|
}
|
|
26
20
|
return false;
|
|
27
21
|
};
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const sizeOf = function (o) {
|
|
32
|
-
return (0, _traversal.map)(o, noop).length;
|
|
22
|
+
export const noop = function () {};
|
|
23
|
+
export const sizeOf = function (o) {
|
|
24
|
+
return map(o, noop).length;
|
|
33
25
|
};
|
|
34
26
|
|
|
35
27
|
/**
|
|
@@ -48,20 +40,17 @@ const sizeOf = function (o) {
|
|
|
48
40
|
* console.log(result);
|
|
49
41
|
* // Output: [1, 2, 3, 4]
|
|
50
42
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return [].concat.apply([], (0, _traversal.map)(o, (i, val) => flatten(val)));
|
|
43
|
+
export const flatten = function (o) {
|
|
44
|
+
if (isObject(o) || isArray(o)) {
|
|
45
|
+
return [].concat.apply([], map(o, (i, val) => flatten(val)));
|
|
55
46
|
}
|
|
56
47
|
return o;
|
|
57
48
|
};
|
|
58
|
-
|
|
59
|
-
const strParseFloat = function (val) {
|
|
49
|
+
export const strParseFloat = function (val) {
|
|
60
50
|
if (!val) return 0;
|
|
61
51
|
return parseFloat((val + '').replace(/\s/g, '').replace(',', '.'));
|
|
62
52
|
};
|
|
63
|
-
|
|
64
|
-
const throttle = function (func, wait, leading = true, trailing = true, context = null) {
|
|
53
|
+
export const throttle = function (func, wait, leading = true, trailing = true, context = null) {
|
|
65
54
|
let timeout = null;
|
|
66
55
|
let lastCall = 0;
|
|
67
56
|
return function (...args) {
|
|
@@ -93,8 +82,7 @@ const throttle = function (func, wait, leading = true, trailing = true, context
|
|
|
93
82
|
* @param {Object} [context=null] - The context to bind to `func`.
|
|
94
83
|
* @returns {Function} The debounced function.
|
|
95
84
|
*/
|
|
96
|
-
|
|
97
|
-
const debounce = function (func, wait, immediate = false, context = null) {
|
|
85
|
+
export const debounce = function (func, wait, immediate = false, context = null) {
|
|
98
86
|
let timeout = null;
|
|
99
87
|
let lastCall = 0;
|
|
100
88
|
return function (...args) {
|
|
@@ -114,5 +102,4 @@ const debounce = function (func, wait, immediate = false, context = null) {
|
|
|
114
102
|
func.apply(context || this, args);
|
|
115
103
|
}, wait);
|
|
116
104
|
};
|
|
117
|
-
};
|
|
118
|
-
exports.debounce = debounce;
|
|
105
|
+
};
|
package/package.json
CHANGED
package/types/dom.d.ts
CHANGED
|
@@ -15,29 +15,29 @@ declare namespace _default {
|
|
|
15
15
|
*/
|
|
16
16
|
function child(el: Element, selector?: string): Element | null;
|
|
17
17
|
/**
|
|
18
|
-
* @param {Element|Document
|
|
19
|
-
* @param {string} [selector
|
|
20
|
-
* @returns {
|
|
18
|
+
* @param {Element|Document} refEl
|
|
19
|
+
* @param {string|Element|NodeList|Array<Element>} [selector]
|
|
20
|
+
* @returns {Element|null}
|
|
21
21
|
*/
|
|
22
|
-
function
|
|
22
|
+
function findOne(refEl: Element | Document, selector?: string | Element | NodeList | Array<Element>): Element | null;
|
|
23
23
|
/**
|
|
24
|
-
* @param {Element|Document
|
|
25
|
-
* @param {string}
|
|
26
|
-
* @returns {Element
|
|
24
|
+
* @param {Element|Document} refEl
|
|
25
|
+
* @param {string|Element|NodeList|Array<Element>} selector
|
|
26
|
+
* @returns {Array<Element>}
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function find(refEl: Element | Document, selector: string | Element | NodeList | Array<Element>): Array<Element>;
|
|
29
29
|
/**
|
|
30
|
-
* @param {Element} el
|
|
30
|
+
* @param {Element|NodeList|Array<Element>} el
|
|
31
31
|
* @param {string} className
|
|
32
|
-
* @returns {Element}
|
|
32
|
+
* @returns {Element|NodeList|Array<Element>}
|
|
33
33
|
*/
|
|
34
|
-
function addClass(el: Element
|
|
34
|
+
function addClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
|
|
35
35
|
/**
|
|
36
|
-
* @param {Element} el
|
|
37
|
-
* @param {string}
|
|
38
|
-
* @returns {Element}
|
|
36
|
+
* @param {Element|NodeList|Array<Element>} el
|
|
37
|
+
* @param {string} className
|
|
38
|
+
* @returns {Element|NodeList|Array<Element>}
|
|
39
39
|
*/
|
|
40
|
-
function removeClass(el: Element
|
|
40
|
+
function removeClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
|
|
41
41
|
/**
|
|
42
42
|
* @param {Element} el
|
|
43
43
|
* @param {string} classNames
|
|
@@ -52,28 +52,28 @@ declare namespace _default {
|
|
|
52
52
|
*/
|
|
53
53
|
function hasClass(el: Element, classNames: string): boolean;
|
|
54
54
|
/**
|
|
55
|
-
* @param {
|
|
56
|
-
* @param {
|
|
57
|
-
* @returns {
|
|
55
|
+
* @param {Node} node
|
|
56
|
+
* @param {...Node} children
|
|
57
|
+
* @returns {Node}
|
|
58
58
|
*/
|
|
59
|
-
function append(
|
|
59
|
+
function append(node: Node, ...children: Node[]): Node;
|
|
60
60
|
/**
|
|
61
|
-
* @param {
|
|
62
|
-
* @param {
|
|
63
|
-
* @returns {
|
|
61
|
+
* @param {Node} node
|
|
62
|
+
* @param {...Node} children
|
|
63
|
+
* @returns {Node}
|
|
64
64
|
*/
|
|
65
|
-
function prepend(
|
|
65
|
+
function prepend(node: Node, ...children: Node[]): Node;
|
|
66
66
|
/**
|
|
67
|
-
* @param {Element}
|
|
67
|
+
* @param {Element|NodeList|Array<Element>|string} els
|
|
68
68
|
* @returns {void}
|
|
69
69
|
*/
|
|
70
|
-
function remove(
|
|
70
|
+
function remove(...els: Element | NodeList | Array<Element> | string): void;
|
|
71
71
|
/**
|
|
72
72
|
* @param {Element} el
|
|
73
|
-
* @param {string}
|
|
73
|
+
* @param {string|Element} selector
|
|
74
74
|
* @returns {Element|null}
|
|
75
75
|
*/
|
|
76
|
-
function closest(el: Element, selector
|
|
76
|
+
function closest(el: Element, selector: string | Element): Element | null;
|
|
77
77
|
/**
|
|
78
78
|
* @param {Element} el
|
|
79
79
|
* @param {string} [selector]
|
|
@@ -98,6 +98,18 @@ declare namespace _default {
|
|
|
98
98
|
* @returns {Element[]}
|
|
99
99
|
*/
|
|
100
100
|
function prevAll(el: Element, selector?: string): Element[];
|
|
101
|
+
/**
|
|
102
|
+
* @param {Element} el
|
|
103
|
+
* @param {Element|string} selector
|
|
104
|
+
* @returns {Element[]}
|
|
105
|
+
*/
|
|
106
|
+
function nextUntil(el: Element, selector: Element | string): Element[];
|
|
107
|
+
/**
|
|
108
|
+
* @param {Element} el
|
|
109
|
+
* @param {Element|string} selector
|
|
110
|
+
* @returns {Element[]}
|
|
111
|
+
*/
|
|
112
|
+
function prevUntil(el: Element, selector: Element | string): Element[];
|
|
101
113
|
/**
|
|
102
114
|
* @param {Element} el
|
|
103
115
|
* @param {Element} wrappingElement
|
|
@@ -149,11 +161,11 @@ declare namespace _default {
|
|
|
149
161
|
* @param {Element} el
|
|
150
162
|
* @param {Object<string, string>|string} name
|
|
151
163
|
* @param {string} [value]
|
|
152
|
-
* @returns {Element}
|
|
164
|
+
* @returns {Element|DOMStringMap}
|
|
153
165
|
*/
|
|
154
166
|
function data(el: Element, name: {
|
|
155
167
|
[x: string]: string;
|
|
156
|
-
} | string, value?: string): Element;
|
|
168
|
+
} | string, value?: string): Element | DOMStringMap;
|
|
157
169
|
/**
|
|
158
170
|
* @param {Element} el
|
|
159
171
|
* @param {string} name
|
|
@@ -178,11 +190,11 @@ declare namespace _default {
|
|
|
178
190
|
function off(el: Element | Document | Window, event: string, handler: Function, options: Object): Element;
|
|
179
191
|
/**
|
|
180
192
|
* @param {HTMLElement} el
|
|
181
|
-
* @param {Object<string, string>|string}
|
|
193
|
+
* @param {Object<string, string>|string} style
|
|
182
194
|
* @param {string} [value]
|
|
183
195
|
* @returns {Element}
|
|
184
196
|
*/
|
|
185
|
-
function css(el: HTMLElement,
|
|
197
|
+
function css(el: HTMLElement, style: {
|
|
186
198
|
[x: string]: string;
|
|
187
199
|
} | string, value?: string): Element;
|
|
188
200
|
/**
|
|
@@ -205,15 +217,15 @@ declare namespace _default {
|
|
|
205
217
|
*/
|
|
206
218
|
function first(nodeList: NodeList): Element | null;
|
|
207
219
|
/**
|
|
208
|
-
* @param {NodeList} nodeList
|
|
220
|
+
* @param {NodeList|Array<Element>} nodeList
|
|
209
221
|
* @returns {Element|null}
|
|
210
222
|
*/
|
|
211
|
-
function last(nodeList: NodeList): Element | null;
|
|
223
|
+
function last(nodeList: NodeList | Array<Element>): Element | null;
|
|
212
224
|
/**
|
|
213
225
|
* @param {string} html
|
|
214
|
-
* @returns {Element}
|
|
226
|
+
* @returns {Element|null}
|
|
215
227
|
*/
|
|
216
|
-
function create(html: string): Element;
|
|
228
|
+
function create(html: string): Element | null;
|
|
217
229
|
/**
|
|
218
230
|
* @param {NodeList} nodeList
|
|
219
231
|
* @param {number} [index=0]
|
|
@@ -237,5 +249,11 @@ declare namespace _default {
|
|
|
237
249
|
* @returns {Element}
|
|
238
250
|
*/
|
|
239
251
|
function empty(el: Element): Element;
|
|
252
|
+
/**
|
|
253
|
+
* @param {Element|NodeList} el
|
|
254
|
+
* @param {string|Element} selector
|
|
255
|
+
* @return {Element[]}
|
|
256
|
+
*/
|
|
257
|
+
function not(el: Element | NodeList, selector: string | Element): Element[];
|
|
240
258
|
}
|
|
241
259
|
export default _default;
|
package/types/index.d.ts
CHANGED
|
@@ -31,20 +31,22 @@ declare const webf: {
|
|
|
31
31
|
dom: {
|
|
32
32
|
children(el: Element, selector?: string): NodeList;
|
|
33
33
|
child(el: Element, selector?: string): Element | null;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
addClass(el: Element
|
|
37
|
-
removeClass(el: Element
|
|
34
|
+
findOne(refEl: Element | Document, selector?: string | Element | NodeList | Array<Element>): Element | null;
|
|
35
|
+
find(refEl: Element | Document, selector: string | Element | NodeList | Array<Element>): Array<Element>;
|
|
36
|
+
addClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
|
|
37
|
+
removeClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
|
|
38
38
|
toggleClass(el: Element, classNames: string, force?: boolean): Element;
|
|
39
39
|
hasClass(el: Element, classNames: string): boolean;
|
|
40
|
-
append(
|
|
41
|
-
prepend(
|
|
42
|
-
remove(
|
|
43
|
-
closest(el: Element, selector
|
|
40
|
+
append(node: Node, ...children: Node[]): Node;
|
|
41
|
+
prepend(node: Node, ...children: Node[]): Node;
|
|
42
|
+
remove(...els: Element | NodeList | Array<Element> | string): void;
|
|
43
|
+
closest(el: Element, selector: string | Element): Element | null;
|
|
44
44
|
next(el: Element, selector?: string): Element | null;
|
|
45
45
|
prev(el: Element, selector?: string | null): Element | null;
|
|
46
46
|
nextAll(el: Element, selector?: string): Element[];
|
|
47
47
|
prevAll(el: Element, selector?: string): Element[];
|
|
48
|
+
nextUntil(el: Element, selector: Element | string): Element[];
|
|
49
|
+
prevUntil(el: Element, selector: Element | string): Element[];
|
|
48
50
|
wrap(el: Element, wrappingElement: Element): Element;
|
|
49
51
|
attr(el: Element, name: string, value?: any): Element | any;
|
|
50
52
|
prop(el: Element, name: string, value?: any): any | Element;
|
|
@@ -55,33 +57,34 @@ declare const webf: {
|
|
|
55
57
|
toggle(el: Element): Element;
|
|
56
58
|
data(el: Element, name: {
|
|
57
59
|
[x: string]: string;
|
|
58
|
-
} | string, value?: string): Element;
|
|
60
|
+
} | string, value?: string): Element | DOMStringMap;
|
|
59
61
|
removeData(el: Element, name: string): Element | any;
|
|
60
62
|
on(el: Element | Document | Window, event: string, handler: Function, options?: AddEventListenerOptions | false): Element;
|
|
61
63
|
off(el: Element | Document | Window, event: string, handler: Function, options: Object): Element;
|
|
62
|
-
css(el: HTMLElement,
|
|
64
|
+
css(el: HTMLElement, style: {
|
|
63
65
|
[x: string]: string;
|
|
64
66
|
} | string, value?: string): Element;
|
|
65
67
|
closestFind(el: Element, selectorClosest: string, selectorFind: string): NodeList | null;
|
|
66
68
|
closestFindOne(el: Element, selectorClosest: string, selectorFindOne: string): Element | null;
|
|
67
69
|
first(nodeList: NodeList): Element | null;
|
|
68
|
-
last(nodeList: NodeList): Element | null;
|
|
69
|
-
create(html: string): Element;
|
|
70
|
+
last(nodeList: NodeList | Array<Element>): Element | null;
|
|
71
|
+
create(html: string): Element | null;
|
|
70
72
|
eq(nodeList: NodeList, index?: number): Element | null;
|
|
71
73
|
after(el: Element, newEl: Element): Element;
|
|
72
74
|
before(el: Element, newEl: Element): Element;
|
|
73
75
|
empty(el: Element): Element;
|
|
76
|
+
not(el: Element | NodeList, selector: string | Element): Element[];
|
|
74
77
|
};
|
|
75
78
|
isWindow: (o: any) => boolean;
|
|
76
79
|
isDomElement: (o: any) => boolean;
|
|
77
80
|
getStyle: (elem: any, cssRule: any) => any;
|
|
78
|
-
each: (o:
|
|
79
|
-
foreach: (o:
|
|
80
|
-
map: (o:
|
|
81
|
-
reduce: (o:
|
|
82
|
-
extend: (...args:
|
|
83
|
-
clone: (o:
|
|
84
|
-
merge: (first:
|
|
81
|
+
each: <T>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (void | boolean), context?: any) => typeof o;
|
|
82
|
+
foreach: <T>(o: Collection<T>, callback: (value: T, key: number | string, o: Collection<T>, index: number) => (void | boolean), context?: any) => typeof o;
|
|
83
|
+
map: <T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any) => any[];
|
|
84
|
+
reduce: <T, R>(o: Collection<T>, callback: (accumulator: R | T, value: T, key: any, index: number, o: Collection<T>) => R, initialValue?: R) => R;
|
|
85
|
+
extend: <T>(...args: (boolean | T)[]) => T;
|
|
86
|
+
clone: <T>(o: T) => T;
|
|
87
|
+
merge: <T>(first: Collection<T>, second?: Collection<T>, ...args: Collection<T>[]) => Array<T>;
|
|
85
88
|
inArray: (value: any, arr: Object | any[], index?: number, strict?: boolean) => boolean;
|
|
86
89
|
indexOf: (arr: any, elt: any, from?: number) => number;
|
|
87
90
|
compareArray: (a1: any, a2: any) => any;
|
package/types/is.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export function isPlainObject(o: any): boolean;
|
|
|
5
5
|
export function isBoolean(b: any): boolean;
|
|
6
6
|
export function isBool(b: any): boolean;
|
|
7
7
|
export function isUndefined(v: any): v is undefined;
|
|
8
|
+
export function isArrayLike(o: any): boolean;
|
|
8
9
|
export function isArray(a: any): a is any[];
|
|
9
10
|
export function isDate(o: any): boolean;
|
|
10
11
|
export function isEvent(o: any): boolean;
|
package/types/traversal.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export function each(o:
|
|
2
|
-
export function foreach(o:
|
|
3
|
-
export function map(o:
|
|
4
|
-
export function reduce(o:
|
|
5
|
-
export function extend(...args:
|
|
6
|
-
export function clone(o:
|
|
7
|
-
export function merge(first:
|
|
1
|
+
export function each<T>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (void | boolean), context?: any): typeof o;
|
|
2
|
+
export function foreach<T>(o: Collection<T>, callback: (value: T, key: number | string, o: Collection<T>, index: number) => (void | boolean), context?: any): typeof o;
|
|
3
|
+
export function map<T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any): any[];
|
|
4
|
+
export function reduce<T, R>(o: Collection<T>, callback: (accumulator: R | T, value: T, key: any, index: number, o: Collection<T>) => R, initialValue?: R): R;
|
|
5
|
+
export function extend<T>(...args: (boolean | T)[]): T;
|
|
6
|
+
export function clone<T>(o: T): T;
|
|
7
|
+
export function merge<T>(first: Collection<T>, second?: Collection<T>, ...args: Collection<T>[]): Array<T>;
|
|
8
|
+
export type Collection<T> = Array<T> | Set<T> | Map<any, T> | {
|
|
9
|
+
[x: string]: T;
|
|
10
|
+
} | string;
|